LNMP中PHP依赖于MySQL,先安装MySQL,后安装PHP;Nginx不依赖谁,什么时候安装都可。MySQL安装参考LAMP部分的MySQL安装http://rachy.blog.51cto.com/11428504/1891065。
1.切换到目录/usr/local/src/目录下,下载php-5.4.37.tar.gz安装包:
[root@centos6 ~]# cd /usr/local/src
[root@centos6 src]# ls
php-5.4.37.tar.bz2
2.解压安装包
[root@centos6 src]# tar jxvf php-5.4.37.tar.bz2
3.创建一个用户php-fpm,禁止登陆,不创建家目录
[root@centos6 src]# useradd -s /sbin/nologin -M php-fpm
4.进入安装目录
[root@centos6 src]# cd php-5.4.37
安装PHP配置依赖项
# yum install -i openssl-devel bzip2-devel libjpeg-devel freetype-devel libxml2
# rpm -ivh 'http://www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_32.noarch.rpm'
# yum install -y libmcrypt-devel
配置安装选项
[root@centos6 php-5.4.37]# ./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
php编译安装中常见配置错误处理请参考:
(1)http://www.poluoluo.com/jzxy/201505/364819.html
(2)http://blog.sina.com.cn/s/blog_75a07c3b0101kcwb.html
5.直到配置全部正确之后开始编译
[root@centos6 php-5.4.37]# echo $?
0
[root@centos6 php-5.4.37]# make
6.编译完成之后没有错误即可开始安装
[root@centos6 php-5.4.37]# echo $?
0
[root@centos6 php-5.4.37]# make install
[root@centos6 php-5.4.37]# echo $?
0
7.安装完成之后将php加入到系统环境变量PATH中:
[root@centos6 php-5.4.37]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/etc/init.d/:/usr/local/mysql/bin/:/usr/local/php/bin/
[root@centos6 php-5.4.37]# source /etc/profile.d/path.sh
8.拷贝php.ini-production到php/etc/目录下并重命名为php.ini
[root@centos6 php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini
9.拷贝sapi/fpm/init.d/php-fpm到/etc/init.d/目录下并重命名为php-fpm
[root@centos6 php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
10.授予其执行权限,加入系统服务列表,开机启动
[root@centos6 php-5.4.37]# chmod 755 /etc/init.d/php-fpm
[root@centos6 php-5.4.37]# chkconfig --add php-fpm
[root@centos6 php-5.4.37]# chkconfig php-fpm on
11.修改配置文件,去掉后缀default
[root@centos6 php-5.4.37]# cd /usr/local/php/etc/
[root@centos6 etc]# ls
pear.conf php-fpm.conf.default php.ini
[root@centos6 etc]# mv php-fpm.conf.default php-fpm.conf
[root@centos6 etc]# ls
pear.conf php-fpm.conf php.ini
[root@centos6 etc]#
12.检测配置无误后启动PHP服务
[root@centos6 php]# /usr/local/php/sbin/php-fpm -t
[12-Jan-2017 06:29:11] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@centos6 php]# service php-fpm start
Starting php-fpm done
13.查看php进程
[root@centos6 php]# ps aux | grep php
root 31045 0.1 0.1 19096 2432 ? Ss 06:30 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
php-fpm 31046 0.0 0.1 19096 2140 ? S 06:30 0:00 php-fpm: pool www
php-fpm 31047 0.0 0.1 19096 2140 ? S 06:30 0:00 php-fpm: pool www
root 31049 6.0 0.0 5984 744 pts/0 S+ 06:32 0:00 grep php
14.查看端口
[root@centos6 php]#netstat -lnp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 8703/php-fpm