centos 编译安装多个php版本

黎东
L、先森
2018-02-12 0 1080

环境准备


yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel

cd /usr/local/src

wget 

tar zvxf php-5.6.30.tar.gz

cd php-5.6.30

groupadd www

useradd -g www -s /sbin/nologin www

编译安装

./configure --prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/etc \
--enable-inline-optimization --disable-debug \
--disable-rpath --enable-shared --enable-opcache \
--enable-fpm --with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--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 \
--with-curl --with-zlib \
--enable-zip \
--with-bz2 \
--with-readline
make && make install 
#重新安装
# make clean
# make clean all
# ./configure 
# make && make install

cp -R ./sapi/fpm/php-fpm.conf /usr/local/php56/etc/php-fpm.conf

cp php.ini-development /usr/local/php56/etc/php.ini

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56

chmod +x /etc/init.d/php-fpm56

修改php-fpm.conf的侦听端口为9001,因为主版本5.5是侦听9000

listen = 127.0.0.1:9001

启动

chkconfig --add php-fpm56

chkconfig on php-fpm56

service php-fpm56 start

php安装成功查看进程

ps aux|grep php

配置Nginx

server {
        listen       80;
        server_name  www.es.com;
        index index.html index.htm index.php;
        root /alidata/www/es-php/;

        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9001;#修改端口
                fastcgi_index index.php;
                include fastcgi.conf;
        }

        location / {
        if (!-e $request_filename){
         rewrite ^/(.*) /index.php last;
         }
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }

        location ~ .*\.(js|css)?$
        {

                expires 1h;

        }
}


php