今天是: 收藏本站 设为主页
网站首页 >  技术专栏  >  linux  > 

Ubuntu 10.10上编译安装LNMP:Nginx 0.8.54+MySQL 5.1.56+PHP-FPM 5.3.6

日期:2012-06-26  点击率:1227


本文记录了LNMP在Ubuntu10.10下的编译安装过程,版本如下:
Nginx 0.8.54
MySQL 5.1.56
PHP-FPM 5.3.6

今天下了一个mysql5.5.12,安装的时候才发现里面根本没有configure文件,mysql服务器的安装,我都不知道自己装过多少次了,没有这个怎么编译,上网查了一下,原来要用cmake来安装。下说一下安装过程

一,下载mysql5.5.12和cmake

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.12-linux2.6-i686.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

二,安装cmake

  1. mkdir /usr/local/cmake  
  2. tar zxvf cmake-2.8.4.tar.gz  
  3. cd cmake-2.8.4  
  4. ./configure  --prefix=/usr/local/cmake  
  5. make && make install  

安装需要g++支持,这个一般linux里面自带的都有,如果没有自己装一下,yum,apt-get,pacman等,这一些管理包都可以装

三,安装配置mysql

1,创建用户和目录

  1. groupadd mysql              //所以在这里我们要建一个msyql的用户和组  
  2. useradd -g mysql mysql -s /usr/sbin/nologin  
  3. mkdir /usr/local/mysql           //创建目录  
  4. mkdir /usr/local/mysql/data              //数据仓库目录  

2,安装mysql

  1. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql   
  2.   
  3. make && make install  
  4. //安装mysql默认的数据库  
  5. scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql  
  6. cp support-files/my-medium.cnf /usr/local/mysql/my.cnf //copy配置文件  
  7. chown -R mysql:mysql /usr/local/mysql //更改权限  
  8. nano /usr/local/mysql/my.cnf  
  9. //加上以下内容  
  10. [mysqld]  
  11. basedir = /usr/local/mysql  
  12. datadir = /usr/local/mysql/data  
  13. log-error = /usr/local/mysql/mysql_error.log  
  14. pid-file = /usr/local/mysql/mysql.pid  
  15. user = mysql  
  16. tmpdir          = /tmp  

cmake的时候,参数可以不用那么多,只要一个-DCMAKE_INSTALL_PREFIX=/usr/local/mysql就行了,我们可以在my.cnf里面配置。[mysqld]中的内容,看看你copy后的my.cnf有没有这些设置,有就不用了在设置了。

3,启动mysql

  1. cd /usr/local/mysql/support-files/  
  2. cp ./mysql.server /etc/init.d/mysql5  
  3. /etc/init.d/mysql5 start  

2、编译安装php-fpm


#下载
wget http://us.php.net/distributions/php-5.3.6.tar.bz2
tar -xjvf php-5.3.6.tar.bz2
cd php-5.3.6

#相关库
#sudo apt-get install libxml2-dev zlib1g-dev libcurl4-openssl-dev libpng12-dev libmcrypt-dev
apt-get install libssl0.9.8 libssl-dev openssl libxml2-dev curl libcurl3 libcurl4-gnutls-dev libjpeg62-dev libpng12-dev libfreetype6-dev libjpeg62 libncurses5-dev libpng3 libpng++-dev libmcrypt-dev

#configure
./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-config-file-scan-dir=/etc/php/conf --with-zlib --with-curl --with-gd --with-mhash --enable-mbstring --with-mcrypt --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-pdo --enable-soap --enable-sockets --with-xmlrpc --enable-zip --without-pear --with-pdo-mysql

#make
make

#install
sudo make install

#user
cd /usr/local/php
useradd www
sudo chown -R www:www ./

#拷贝php配置
sudo mkdir -p /etc/php
sudo cp php.ini-production /etc/php/php.ini

#配置
sudo vim ./etc/php-fpm.conf
rlimit_files = 1048576
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 100

#运行
./sbin/php-fpm

#添加到开机启动
ln -s /usr/local/php/sbin/php-fpm /usr/bin/
vim /etc/rc.local
#start php-fpm at start
echo 134217728 > /proc/sys/kernel/shmmax
php-fpm

#安装APC
wget http://pecl.php.net/get/APC-3.1.6.tgz
tar -xzvf APC-3.1.6.tgz
cd APC-3.1.6
sudo apt-get install autoconf
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
sudo make install
#编辑
vim /etc/sysconfig/php/php.ini
#修改并添加
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626"
extension=apc.so
[apc]
apc.enabled = 1
apc.shm_segments = 2
apc.shm_size = 48M


3、编译安装nginx


#下载
wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar -xzvf nginx-0.8.54.tar.gz

#安装相关包
sudo apt-get install libpcre3-dev libmhash-dev

#configure
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
#make
make
#install
sudo make install
cd /usr/local/nginx
sudo chown -R www:www .

#配置nginx.conf
sudo vim conf/nginx.conf
#如下
user www www;
worker_processes  2;

error_log  /usr/local/nginx/logs/error.log;
pid        /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 1048576;

events {
    use epoll;
    worker_connections  65535;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  60;

    #gzip
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers        4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 6;
    gzip_types  text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    server {
        listen       80;
        server_name  node11.coder4.com;
        root /usr/local/nginx/html;
        access_log  /usr/local/nginx/logs/node11.coder4.com.access.log  main;

        location / {
            index  index.php index.html index.htm;
        }

        # redirect server error pages to the static page /50x.html
        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }

        #deny htaccess
        location ~ /\.ht {
            deny  all;
        }

        #ip
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
            expires      30d;
            access_log   off;
        }
    }
}

#配置fastcgi_params
sudo vim conf/fastcgi_params
#添加一行
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;







下一篇:nginx的一些优化参数   上一篇:Ubuntu下安装ProFTPd和MySQL