编译安装php-fpm
- 环境准备
yum -y install gcc automake autoconf libtool make install gcc gcc-c++ glibc bison bison-devel zlib-devel libmcrypt-devel mcrypt openssl-devel libcurl-devel readline-devel libedit-devel sqlite-devel mhash-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
- 编译安装
下载安装包,地址:
tar xzf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-mysql --with-mysqli --with-pdo-mysql --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --with-iconv-dir --with-jpeg-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-xml --enable-fastcgi --with-curl --with-zlib --enable-zip --with-bz2 --with-gd --with-readline
make all install
复制配置文件:
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
修改配置文件:vi etc/php-fpm.conf
user = www
group = www
如果www用户不存在,那么先添加www用户
groupadd www
useradd -g www www
(注:设置为www用户,是为了和nginx或apache保持一致,可以使用nginx或者apache运行使用的用户。)
检测php.ini的语法 /usr/local/php/sbin/php-fpm -t
- 添加nginx支持php
修改nginx.conf
其中server段增加如下配置:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /data/www; #项目根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
测试nginx配置文件是否正确:/usr/local/nginx/sbin/nginx -t
- 创建php测试文件
在nginx根目录下,创建index.php文件,输入如下内容:
<?php
echo phpinfo();
?>
浏览器访问该文件,可看到php安装信息。
- 启动php
usr/local/php/sbin/php-fpm
- 测试
重启nginx,浏览器访问index.php,可看到php安装信息。
/usr/local/nginx/sbin/nginx -s reload
- 添加开机启动:
echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local
- php-fpm关闭与重启
php-fpm 关闭:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
检测php.ini的语法 /usr/local/php/sbin/php-fpm -t