1,解压缩软件
所需依赖包:
复制代码 代码示例:
yum install -y libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
vi INSTALL
./configure
make && make instal
php编译安装:
复制代码 代码示例:
tar xvjf php-5.4.25.tar.bz2
cd php-5.4.25
mkdir -p /usr/local/php
2,编译 安装 nginx
复制代码 代码示例:
./configure --prefix=/usr/local/php --with-
mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/
apache2/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --enable-fpm
错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
libmcrypt-2.5.8.tar.gz
编译安装
复制代码 代码示例:
[root@wang soft]# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@wang soft]# cd libmcrypt-2.5.8
[root@wang libmcrypt-2.5.8]# ./configure
[root@wang libmcrypt-2.5.8]# make && make install
同理安装bzip2-1.0.6.tar.gz
3,为php-fpm提供Sysv init脚本,并将其添加至服务列表:
复制代码 代码示例:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig –add php-fpm
# chkconfig php-fpm on
4,为php-fpm提供配置文件:
复制代码 代码示例:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
5,编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置pm.的相关选项为你所需要的值,并启用pid文件(如下最后一行):
复制代码 代码示例:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid
6,启动php-fpm:
复制代码 代码示例:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
[root@www conf]# ps aux | grep php-fpm
root 25424 0.0 0.4 182452 4152 ? Ss 20:30 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 25425 0.0 0.5 182452 5648 ? S 20:30 0:00 php-fpm: pool www
nobody 25426 0.0 0.5 182816 5756 ? S 20:30 0:00 php-fpm: pool www
root 25618 0.0 0.0 103236 892 pts/0 S+ 20:53 0:00 grep php-fpm
7,编辑/usr/ocal/nginx/conf/fastcgi_params,将其内容更改为:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
8,nginx配置文件
在主文件/usr/local/nginx/conf/nginx.conf配置文件中,插入include vhost/www.conf。
其中vhost为/usr/local/nginx/conf/中的新建目录
vi www.conf
复制代码 代码示例:
server {
listen 80;
server_name www.jb200.com;
root /var/www/html;
charset utf-8;
access_log logs/www.access.log;
location / {
index index.php index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
9,重启nginx
复制代码 代码示例:
service nginx restart
10,在/usr/html新建index.php的测试页面,测试php是否能正常工作:
复制代码 代码示例: