官方文档
安装:http://php.net/manual/zh/install.unix.nginx.php
配置选项:http://php.net/manual/en/configure.about.php
准备工作
1.yum安装所需软件包
# yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2.yum源没有libmcrypt包,采用源码安装。
# cd /usr/local/src/
# wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
# ./configure prefix=/usr/local/libmcrypt
# make && make install
# echo$?
3.下载php源码包,解压
# wget http://am1.php.net/distributions/php-5.6.29.tar.bz2
# tar jxvf php-5.6.29.tar.bz2
# cd php-5.6.29
安装过程
1.创建用户php-fpm
# useradd -s /sbin/nologin php-fpm
2.配置编译参数
# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
3.编译和安装
# make && make install
# echo $?
4.修改配置文件
# cp php.ini-production /usr/local/php/etc/php.ini
# vim /usr/local/php/etc/php-fpm.conf
# /usr/local/php/sbin/php-fpm -t
php-fpm.conf修改项如下:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
运行/usr/local/php/sbin/php-fpm -t,若结果为“test is successful”,则配置正确。
5.拷贝php-fpm启动脚本到/etc/init.d/,更改权限
# cp /usr/local/src/php-5.6.29/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
# service php-fpm start
若使php-fpm开机启动,运行chkconfig --add php-fpm;chkconfig php-fpm on。
查看服务是否启动,运行ps aux | grep php。