最近由于一些之前的项目没法在php7.0 下运行,但是又不能一起之前的某个项目把PHP7.0回滚
所以这里重新安装下PHP5.4 用PHP5.4的php-fmp跟nginx配合

安装php5.4

wget http://cn2.php.net/distributions/php-5.4.24.tar.gz
由于之前安装过依赖包了,这里依赖包的安装就不写了,看php6.5 安装
tar xzvf  php-5.4.24.tar.gz
cd php5.4.24
./configure --prefix=/usr/local/php5.4.24 --with-config-file-path=/usr/local/php5.4.24/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-calendar --with-gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --enable-fastcgi --enable-fpm --with-curl --enable-json --enable-ctype --enable-cgi --enable-xml--with-gd --with-mcrypt --enable-zip

这里可能会提示--enable-fastcgi 没有这个参数,无所谓了,因为从php5.3开始已经把fastcgi内置了.

安装后配置.

cp php.ini-production /usr/local/php5.4.24/etc/

配置php.ini 设置安全 还有一些见php.ini 安全设置

disable_functions = phpinfo,system,passthru,exec,shell_exec,popen,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,show_source,get_cfg_var

配置启动php-fmp项目.

cp /usr/local/php5.4.24/etc/php-fpm.conf.default /usr/local/php5.4.24/etc/php-fpm.conf
vim /usr/local/php5.4.24/etc/php-fpm.conf

#指定PID启动文件

pid = run/php-fpm.pid

#启动错误日志

error_log = log/php-fpm.log

#如果没有创建项目访问组请创建

listen.owner = www
listen.group = www

#端口自行修改,同时防火墙开启

listen = 127.0.0.1:9000 

以上搞定后重启,这里并非调优,只是简单启动而已

php-fpm 关闭:
kill -INT `cat /usr/local/php5.4.24/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/php5.4.24/var/run/php-fpm.pid`

原理就是PHP启动的时候会开启一个进程ID并写入文件,kill掉进程文件里面的编号则为杀死进程,所以我们可以写一个重启服务的脚本

vim /etc/init.d/php-fpm5.4.24

#!/bin/bash
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: php-fpm5.4.24
# config:      /usr/local/php5.4.24/etc/php-fpm.conf 
# pidfile:     /usr/local/php5.4.24/var/run/php-fpm.pid

# pid file
pid="/usr/local/php5.4.24/var/run/php-fpm.pid"
# php-fpm path&file
phpfpm="/usr/local/php5.4.24/sbin/php-fpm"

param=$1

phpnum=`ps -ef | grep php-fpm | wc -l`

if [ "$param" = "stop" ]; then
    if [ ! -f $pid ]; then
        echo "Php process does not exist."
        exit 1
    fi
    kill `cat $pid`
    echo "Close php processes. OK"
    exit 1
fi

if [ "$param" = "start" ]; then
    if [ -f $pid ]; then
        echo "Php process exist."
        exit 1
    fi
    $phpfpm
    echo "Open php processes. OK"
    exit 1
fi

以上脚本有个缺陷,如果你有多个版本php-fmp则会全部杀掉,只启动你当前的指定fpm,是不是很坑,哈哈,访问者先自行解决.

#设置开启自定启动

/sbin/chkconfig php5.4.24 on

到这里你访问你的站点发现 Access denied.
为啥呢默认php-fpm人家制作动态解析来使用,拒绝静态这些资源.

但是我只是把nginx作为代理来用,我要所有的资源都转发到php-fpm上.
所以做下面配置: 完事别忘了重启fpm

vim /usr/local/php5.4.24/etc/php-fpm.conf
security.limit_extensions = .php .php3 .php4 .php5 .html .js .css .jpg .jpeg .gif .png .htm .swf .flv .zip

NINGX 配置样例:

server {
        listen 118.118.118.0:80;
        server_name www.abc.com;
        error_log  logs/www.abc.com.error.log;
        access_log logs/www.abc.com.access.log;
        index index.html index.php index.htm default.html default.htm default.php;
        root /www/www_abc_com;
        #不带www的域名301到www的域名上
        if ($host != "www.abc.com"){
            rewrite ^/(.*)$ http://www.abc.com/$1 permanent;
        }
        if (-d $request_filename){
            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
                root /www/www_abc_com;
                if (-f $request_filename) {
                  expires 1s;
                  break;
                }

        }
        location ~ .*\.(html|htm)?$ {
                fastcgi_pass  127.0.0.1:9001;
                fastcgi_index index.html;
                include /usr/local/nginx1.8/conf/fastcgi.conf;
        }

        location ~ .*\.(php|php5)?$ {
                fastcgi_pass  127.0.0.1:9001;
                fastcgi_index index.php;
                fastcgi_param  PHP_VALUE  "open_basedir=/www/www_abc_com/:/tmp/";
                include /usr/local/nginx1.8/conf/fastcgi.conf;
        }
}