首先安装nginx,nginx首页http://nginx.org
下载nginx软件源
http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
然后yum -y install nginx
这样就完成了nginx的安装
然后是php
编译php需要下面软件包的支持
yum -y install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel openssl openssl-devel
还需要额外编译安装两个软件包libmcrypt和mhash,先装前者再装后者,附共享地址
libmcrypt——http://s.yunio.com/z0DCuu
mhash——http://s.yunio.com/e85BeA
下载php去
http://www.php.net/downloads.php
其他版本在
下好之后解压
tar xvf php-5.3.19.tar.bz2
cd php-5.3.19
开始编译,现在一般使用fpm模式,所以带上--enable-fpm参数
./configure --prefix=/usr/local/php --with-pdo-mysql --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-iconv-dir=/usr/local/lib --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --enable-fpm
安装
make
make install
安装完成后,你的php目录下并没有生成php.ini,需要自己从源码包根目录中手动拷贝一个样例文件并且重命名样例文件有可能是php.ini-dist,也有可能是php.ini-production
上面编译参数中指定的--with-config-file-path=/usr/local/php/etc就是你要拷贝到的路径
cp php.ini-production /usr/local/php/etc/php.ini
配置与优化
php 5.3.3之后的的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,需要使用信号控制:
查看php-fpm进程:
lsof -i:你的fastcgi监控端口
或者
ps aux | grep php-fpm
其中的php-fpm: master字样进程就是主进程
master进程可以理解以下信号
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
示例:
php-fpm 关闭:
kill -INT pid
php-fpm 重启:
kill -USR2 pid
root /home/www;//你的工程根目录
index index.html index.htm;
}
root /home/www;//同样是你的工程根目录,如果不设置,会出现
FastCGI sent in stderr: "Primary script unknown"
错误
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;//nginx安装后默认是/script$fastcgi_script_name,必须把/script替换成$document_root$
include fastcgi_params;
}
listen 80;
server_name www.250er.com 250er.com;
location / {
root /home/www/www.250er.com;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /home/www/www.250er.com;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}