系统相关
首页 > 系统相关> > 在CentOS7上同时安装php704和php734

在CentOS7上同时安装php704和php734

作者:互联网

首先安装php704

1、安装依赖包

yum install libxml2 libxml2-devel openssl openssl-devel zip bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel ncurses-base ncurses-libs ncurses-devel libxslt libxslt-devel libgpg-error-devel libgcrypt-devel -y

 

2、下载php-7.0.4.tar.gz

cd /usr/local/src
wget http://cn2.php.net/distributions/php-7.0.4.tar.gz

 

3、编译安装

tar xf php-7.0.4.tar.gz
cd php-7.0.4
./configure --prefix=/usr/local/php704 --with-config-file-path=/etc --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
make && make install

 

4、配置

cp /usr/local/src/php-7.0.4/php.ini-production /etc/php.ini
cp /usr/local/php704/etc/php-fpm.conf.default /usr/local/php704/etc/php-fpm.conf
cp /usr/local/php704/etc/php-fpm.d/www.conf.default /usr/local/php704/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.0.4/sapi/fpm/php-fpm.service /etc/systemd/system/
vim /etc/systemd/system/php-fpm.service
# 这里要修改php-fpm.service中的路径
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php704/var/run/php-fpm.pid
ExecStart=/usr/local/php704/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php704/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

注意,php-fpm的默认监听端口是9000,在配置文件/usr/local/php704/etc/php-fpm.d/www.conf中有写明。

 

5、启动php-fpm

systemctl start php-fpm

 

6、如果需要安装redis扩展

yum install autoconf -y
cd /usr/local/src
wget https://codeload.github.com/phpredis/phpredis/zip/develop
unzip develop
cd phpredis-develop/
/usr/local/php704/bin/phpize
./configure --with-php-config=/usr/local/php704/bin/php-config
make && make install


# 然后在/etc/php.ini中最底部加入redis.so
extension=redis.so

 

7、重启php-fpm即可

 

注意看:

编译时,指定的用户为nobody,那么你的php程序代码目录权限也要改为nobody,否则无法使用。

 

然后安装php734

1、下载php-7.3.4.tar.gz

cd /usr/local/src
wget http://cn2.php.net/distributions/php-7.3.4.tar.gz

 

2、安装libzip(如果需要zip压缩,则安装,否则可以跳过安装libzip)

cd /usr/local/src
wget https://nih.at/libzip/libzip-1.2.0.tar.gz --no-check-certificate
tar xf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure && make && make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64' >> /etc/ld.so.conf
ldconfig -v

 

3、编译安装php734

./configure --prefix=/usr/local/php734 --with-config-file-path=/etc --enable-fpm \
--with-fpm-user=nobody --with-fpm-group=nobody --enable-inline-optimization \
--disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir \
--with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex \
--with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 \
--enable-calendar --with-curl --with-cdb --enable-dom --enable-exif \
--enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd \
--with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
--with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext \
--with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex \
--enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite \
--with-readline --enable-session --enable-shmop --enable-simplexml \
--enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx \
--with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support \
--with-pear --enable-opcache
make && make install

 

4、配置

cp /usr/local/php734/etc/php-fpm.conf.default /usr/local/php734/etc/php-fpm.conf
cp /usr/local/php734/etc/php-fpm.d/www.conf.default /usr/local/php734/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.3.4/sapi/fpm/php-fpm.service /etc/systemd/system/php734-fpm.service

# 很奇怪,这次不用修改php734-fpm.service中的路径,路径已经自动填上了

注意,由于机器上的9000端口已经被占用了,所以要换个端口。

vim /usr/local/php734/etc/php-fpm.d/www.conf

 

5、启动

systemctl start php734-fpm

 

####################################

nginx配置文件

server {
    listen       8080;
    server_name  192.168.0.109;

    index index.html index.php;
    access_log /var/log/php/nginx_access.log;
    error_log  /var/log/php/nginx_error.log;
    client_max_body_size    500m;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        root /data/public;
        add_header Access-Control-Allow-Origin *;
        add_header X-debug-message "hey2";
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

 

标签:enable,--,CentOS7,fpm,php704,php734,php,local,usr
来源: https://www.cnblogs.com/t-road/p/16343164.html