一、安装环境:CentOS 7 Linux version 3.10.0-229.el7.x86_64

                 php-5.6.20

二、安装步骤:

2.1 安装php相关的依赖包

命令:yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel –y

2.2 下载php-5.6.20

命令:wget

2.3 解压

命令:cd /usr/local/src

tar –zxf php-5.6.20.tar.gz

2.4 配置php

命令:cd ./php-5.6.20

./configure --prefix=/usr/local/php-5.6.20 --with-config-file-path=/usr/local/php-5.6.20/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

出现如下图所示结果表示配置成功

2.5 编译

命令:make

2.6 安装

命令:make install

2.7 配置php启动文件

命令:cp php.ini-production /usr/local/php-5.6.20/etc/php.ini  

           cp /usr/local/php-5.6.20/etc/php-fpm.conf.default /usr/local/php-5.6.20/etc/php-fpm.conf

2.8 配置测试页面info.php

命令:mkdir /data/site

           mkdir /data/site/bfjk.com

           vim /data/site/bfjk.com/info.php

内容:

<?php  

phpinfo();    
?>

2.9 配置nginx配置文件nginx.conf

命令:vim /usr/local/nginx-1.9.12/conf/nginx.conf

以下是配置内容:

server {

listen 80;  

server_name bfjk.com;    
access_log /data/logs/nginx/bfjk.com.access.log;    
 
index index.php index.html index.html;    
root /data/site/bfjk.com;    
 
location /    
{    
try_files $uri $uri/ /index.php?$args;    
}    
 
location ~ .*\.(php)?$    
{    
expires -1s;    
try_files $uri =404;    
fastcgi_split_path_info ^(.+\.php)(/.+)$;    
include fastcgi_params;    
fastcgi_param PATH_INFO $fastcgi_path_info;    
fastcgi_index index.php;    
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    
fastcgi_pass 127.0.0.1:9000;    
}

重启nginx

命令:/usr/local/nginx-1.9.12/sbin/nginx –s reload

2.10 启动与关闭php服务

命令:/usr/local/php-5.6.20/sbin/php-fpm #启动php服务

命令:sudo pkill php-fpm #关闭php服务

2.11 测试php

命令:netstat -lnt | grep 9000

也可以通过网页访问 IP/info.php来测试,出现以下结果,表示安装成功。

2.12 配置php.ini文件,为安装zabbix做装备。

命令:vim /usr/local/php-5.6.20/etc/php.ini

修改以下配置为相应的值

max_execution_time = 300  

memory_limit = 128M    
post_max_size = 16M    
upload_max_filesize = 2M    
max_input_time = 300    
date.timezone = PRC    
always_populate_raw_post_data = -1