下载插件包
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel epel-release libmcrypt-devel
下载
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.32.tar.gz
解压
tar zxvf php-5.6.32.tar.gz
预编译
cd php-5.6.32
创建php-fpm用户,并禁止登录;
useradd -s /sbin/nologin php-fpm
./configure --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc/ --with-fpm-user=php-fpm --with-fpm-group=php-fpm --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --enable-ftp --enable-redis
提示错误mcrypt.h没有找到,安装libmcrypt-devel包,默认的yum源,没有这个包,需要安装epel扩展源后,才可以安装。
[root@localhost php-5.6.32]# yum install -y epel-release
[root@localhost php-5.6.32]# yum install -y libmcrypt
[root@localhost php-5.6.32]# yum install -y libmcrypt-devel
再次执行./configure,没有错误提示,出现Thank you for using PHP,配置OK。
检查是否安装正确
make && make install
echo $?
如果出现0 就说明正确了.
配置文件
需要将当前目录下的php.ini文件拷贝到 php的安装目录etc下
cp php.ini-production /usr/local/php/etc/php.ini
php.ini 文件是在包目录下的 php.ini-development(开发), php.ini-production(生产)
拷贝php启动脚本,php-fpm配置文件,更改php-fpm权限为755;添加php-fpm开机启动;
[root@ php-5.6.32]# cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
(启动脚本)
[root@ php-5.6.32]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf (就是去掉了末尾的.default )
[root@ php-5.6.32]# chmod 755 /etc/init.d/php-fpm
[root@lphp-5.6.32]# chkconfig --add php-fpm
[root@lphp-5.6.32]# service php-fpm start
Starting php-fpm done
[root@php-5.6.32]# chkconfig php-fpm on
将php的安装目录也加入到系统的环境变量 在最后一行加入
vim /etc/profile
export PATH=/usr/local/php/bin:$PATH
source /etc/profile //重新加载
[root@localhost ~]# php -v
PHP 5.6.32 (cli) (built: Mar 12 2018 17:43:15)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies完成 接下来就是测试
vim /usr/local/nginx/conf/nginx.conf
location / {
root /www/test;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
将请求转给php的9000端口 确保nginx 和PHP都是运行的哈。
location ~ \.php$ {
root /www/test;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
我的是根目录下的www/ 写个index.php 里面加入phpinfo(); 看能否成功。