centos如何安裝多個php

centos安裝多個php的方法:首先為yum引入EPEL庫和REMI庫;然后通過命令“yum-config-manager –enable remi-php71”啟用PHP源“remi-php71”;接著安裝并配置好“php56”即可。

centos如何安裝多個php

centos中安裝多版本php并同時用于nginx

在新建的虛擬機中安裝了php7, 安好了才發現一些老一點的項目跑不了了, 由于php7版本較php5版本有了較大修改, 很多函數已經不是廢棄, 而是移除了, 導致很多問題. 只好再安裝一個php版本了, 我要安裝的是php5.6, 在網上搜了linux中的php多版本管理, 推薦了phpenv, 搞了一通, 沒有結果, 只好換個方法了, 直到我發現了這篇文章, 直接解決. 下面給大家介紹安裝及配置過程.

推薦:《centos教程

這種情況下其實可以通過直接在一個linux系統中通過yum等工具安裝好不同的PHP版本, 分別注冊PHP-FPM服務, 配置到服務器中即可.

立即學習PHP免費學習筆記(深入)”;

實驗環境

CENTOS7

Nginx v1.12.2

PHP7(設置為系統默認PHP版本)和PHP5.6

服務器IP 192.168.56.100

安裝PHP7與PHP5.6

首先為yum引入兩個庫: EPEL與REMI, 因為這個兩個庫為我們提供最新的PHP版本源, CENTOS 自帶的yum庫中PHP版本都太老舊了.

#?yum?install?https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm #?yum?install?http://rpms.remirepo.net/enterprise/remi-release-7.rpm

安裝php71

#?yum-config-manager?--enable?remi-php71??[Default] #?yum?install?php?php-common?php-fpm #?yum?install?php-mysql?php-pecl-memcache?php-pecl-memcached?php-gd?php-mbstring?php-mcrypt?php-xml?php-pecl-apc?php-cli?php-pear?php-pdo

第一句用于啟用PHP源remi-php71

安裝php56

#?yum?install?php56?php56-php-common?php56-php-fpm #?yum?install?php56-php-mysql?php56-php-pecl-memcache?php56-php-pecl-memcached?php56-php-gd?php56-php-mbstring?php56-php-mcrypt?php56-php-xml?php56-php-pecl-apc?php56-php-cli?php56-php-pear?php56-php-pdo

在linux中執行php -v, 驗證一下, 當前的php版本應該是7.1

安裝好之后, 下面就要配置php-fpm與php56-php-fpm, 他們是php的Fastcgi進程管理器, linux中web服務器調用php處理就是通過他們.

好了,開始配置吧.

兩個php版本分別對應的配置文件為

php-fpm?(default?7.1)?–?/etc/php-fpm.d/www.conf php56-php-fpm?–?/opt/remi/php56/root/etc/php-fpm.d/www.conf

(很神奇, 安裝php56版本的目錄是在opt目錄下)

打開兩個配置文件, 更改如下代碼

listen?=?127.0.0.1:9000[php-fpm] listen?=?127.0.0.1:9001[php56-php-fpm]

如果是通過socket通信方式調用php-fpm的情況, 則更改代碼如下

listen?=?/var/run/php-fpm/php-fpm.sock[php-fpm] listen?=?/opt/remi/php56/root/var/run/php-fpm/php-fpm.sock[php56-php-fpm]

分別注冊并啟用兩個版本的php-fpm服務

#?systemctl?enable?nginx? #?systemctl?start?nginx? #?systemctl?enable?mariadb? #?systemctl?start?mariadb? ----------------?PHP?7.1?----------------? #?systemctl?enable?php-fpm? #?systemctl?start?php-fpm? ----------------?PHP?5.6?---------------- #?systemctl?enable?php56-fpm? #?systemctl?start?php56-php-fpm

使用php7的nginx服務器配置

server?{ ????listen?80; ????server_name?example1.com?www.example1.com; ????root???/var/www/html/example1.com/; ????index?index.php?index.html?index.htm; ????#charset?koi8-r; ????access_log?/var/log/nginx/example1.com/example1_access_log; ????error_log???/var/log/nginx/example1.com/example1_error_log???error; ????location?/?{ ????try_files?$uri?$uri/?/index.php?$query_string; ????} ????#?pass?the?PHP?scripts?to?FastCGI?server?listening?on?127.0.0.1:9000 ????location?~?.php$?{ ????root????/var/www/html/example1.com/; ????fastcgi_pass???127.0.0.1:9000;#set?port?for?php-fpm?to?listen?on ????fastcgi_index??index.php; ????fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; ????include?????????fastcgi_params; ????include?/etc/nginx/fastcgi_params; ????} } `

使用php56的nginx服務器中配置

server?{ ????listen?80; ????server_name?example2.com?www.example2.com; ????root????/var/www/html/example2.com/; ????index?index.php?index.html?index.htm; ????#charset?koi8-r; ????access_log?/var/log/nginx/example2.com/example2_access_log; ????error_log??/var/log/nginx/example2.com/example2_error_log???error; ????location?/?{ ????try_files?$uri?$uri/?/index.php?$query_string; ????} ????#?pass?the?PHP?scripts?to?FastCGI?server?listening?on?127.0.0.1:9000 ????location?~?.php$?{ ????root????/var/www/html/example2.com/; ????fastcgi_pass???127.0.0.1:9001;#set?port?for?php56-php-fpm?to?listen?on ????fastcgi_index??index.php; ????fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; ????include?????????fastcgi_params; ????include?/etc/nginx/fastcgi_params; ????} }

添加測試網頁文件

#?echo?"<?php  phpinfo(); ?>"?&gt;?/var/www/html/example1.com/info.php #?echo?"<?php  phpinfo(); ?>"?&gt;?/var/www/html/example2.com/info.php

測試

之后訪問example1.com/info.php 與 example2.com/info.php測試即可.

如果你是在本地虛擬機中配置的, 別忘了在本地host文件中添加

192.168.56.100???example1.com???example1 192.168.56.100???example2.com???example2

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊11 分享