ubuntu(9.10)下安装nginx+php5.2+php-fpm+memcache+apc

http://lzyy.org/blog/archives/213

这是目前我能想到的最快的组合了,这里备份一下安装过程。

前期工作

sudo  apt-get install  make bison flex gcc patch autoconf subversion locate
sudo apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev


如果没有安装mysql的话

sudo apt-get install mysql-server

安装php

cd /usr/loca/src
wget http://cn2.php.net/get/php-5.2.13.tar.gz/from/this/mirror
tar  zvxf php-5.2.13.tar.gz
wget http://php-fpm.anight.org/downloads/head/php-5.2.13-fpm-0.5.13.diff.gz
gzip  -cd php-5.2.13-fpm-0.5.13.diff.gz | sudo patch -d php-5.2.13 -p1
cd php-5.2.13
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring  --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-xslt --enable-memcache --enable-zip --with-pcre-regex
sudo make
sudo make install

如果出现错误,把缺少的库安上就行了。

安装memcache和apc插件

sudo pecl install memcache
sudo pecl install apc
#pdo默认已经安装,所以直接安装pdo_mysql就可以了
sudo pecl install pdo_mysql

修改配置文件

sudo cp  /usr/local/src/php-5.2.8/php.ini-recommended /usr/local/lib/php.ini
sudo  mkdir /etc/php/
sudo ln -s /usr/local/lib/php.ini /etc/php/php.ini
sudo ln -s /usr/local/etc/php-fpm.conf /etc/php/php-fpm.conf

修改/etc/php/php-fpm.conf,去掉下面两行的注释,将nobody修改为www-data

<value name="user">www-data</value>
<value name="group">www-data</value>

安装nginx

sudo apt-get install nginx

修改/etc/nginx/fastcgi_params,添加以下几行

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

修改/etc/nginx/sites-enabled/default,注意servername选项,最好匹配域名而不是ip

location / 
{
    root   /var/www;
    index index.php index.html index.htm;
}
 
location ~ ^/index.php
{
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
}

启动服务

sudo php-fm start
sudo /etc/init.d/nginx start

done!

如果要让php-fpm开机自动启动,把下面这个脚本保存到/etc/init.d/php-fpm

#! /bin/sh
case "$1" in
  start)
        php-fpm start
    ;;
  stop)
        php-fpm stop
    ;;
  restart|force-reload)
        php-fpm restart
    ;;
  reload)
        php-fpm reload
      ;;
  *)
    echo "Usage: php-fpm {start|stop|restart|reload|force-reload|status}" >&2
    exit 1
    ;;
esac
 
exit 0

然后

sudo chmod +x php-fpm
sudo update-rc.d -f php-fpm defaults

就行了,要删除自动启动的话

sudo update-rc.d -f php-fpm remove

参考:NGINX + PHP-FPM + APC = Awesome

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

73 + = 78