centos如何安裝多個php
centos安裝多個php的方法:先為yum引入EPEL函式庫和REMI函式庫;然後透過指令「yum-config-manager --enable remi-php71」啟用PHP來源「remi-php71」;接著安裝並配置好“php56”即可。
centos中安裝多版本php並且同時用於nginx
在新建的虛擬機器中安裝了php7 , 安好了才發現一些老一點的項目跑不了了, 由於php7版本較php5版本有了較大修改, 很多函數已經不是廢棄, 而是移除了, 導致很多問題. 只好再安裝一個php版本了, 我要安裝的是php5.6, 在網上搜了linux中的php多版本管理, 推薦了phpenv, 搞了一通, 沒有結果, 只好換個方法了, 直到我發現了這篇文章, 直接解決. 下面給大家介紹安裝及設定流程.
推薦:《centos教學》
這種情況下其實可以透過直接在一個linux系統中透過yum等工具安裝好不同的PHP版本, 分別註冊PHP-FPM服務, 配置到伺服器中即可.
實驗環境
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(); ?>" > /var/www/html/example1.com/info.php # echo "<?php phpinfo(); ?>" > /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
以上是centos如何安裝多個php的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

CentOS系統下GitLab的備份與恢復策略為了保障數據安全和可恢復性,CentOS上的GitLab提供了多種備份方法。本文將詳細介紹幾種常見的備份方法、配置參數以及恢復流程,幫助您建立完善的GitLab備份與恢復策略。一、手動備份利用gitlab-rakegitlab:backup:create命令即可執行手動備份。此命令會備份GitLab倉庫、數據庫、用戶、用戶組、密鑰和權限等關鍵信息。默認備份文件存儲於/var/opt/gitlab/backups目錄,您可通過修改/etc/gitlab

CentOS 關機命令為 shutdown,語法為 shutdown [選項] 時間 [信息]。選項包括:-h 立即停止系統;-P 關機後關電源;-r 重新啟動;-t 等待時間。時間可指定為立即 (now)、分鐘數 ( minutes) 或特定時間 (hh:mm)。可添加信息在系統消息中顯示。

CentOS 和 Ubuntu 的關鍵差異在於:起源(CentOS 源自 Red Hat,面向企業;Ubuntu 源自 Debian,面向個人)、包管理(CentOS 使用 yum,注重穩定;Ubuntu 使用 apt,更新頻率高)、支持週期(CentOS 提供 10 年支持,Ubuntu 提供 5 年 LTS 支持)、社區支持(CentOS 側重穩定,Ubuntu 提供廣泛教程和文檔)、用途(CentOS 偏向服務器,Ubuntu 適用於服務器和桌面),其他差異包括安裝精簡度(CentOS 精

提升CentOS上HDFS性能:全方位優化指南優化CentOS上的HDFS(Hadoop分佈式文件系統)需要綜合考慮硬件、系統配置和網絡設置等多個方面。本文提供一系列優化策略,助您提升HDFS性能。一、硬件升級與選型資源擴容:盡可能增加服務器的CPU、內存和存儲容量。高性能硬件:採用高性能網卡和交換機,提升網絡吞吐量。二、系統配置精調內核參數調整:修改/etc/sysctl.conf文件,優化TCP連接數、文件句柄數和內存管理等內核參數。例如,調整TCP連接狀態和緩衝區大小

CentOS 中配置 IP 地址的步驟:查看當前網絡配置:ip addr編輯網絡配置文件:sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0更改 IP 地址:編輯 IPADDR= 行更改子網掩碼和網關(可選):編輯 NETMASK= 和 GATEWAY= 行重啟網絡服務:sudo systemctl restart network驗證 IP 地址:ip addr

CentOS下Hadoop分佈式文件系統(HDFS)配置常見問題及解決方案在CentOS系統上搭建HadoopHDFS集群時,一些常見的錯誤配置可能導致性能下降、數據丟失甚至集群無法啟動。本文總結了這些常見問題及其解決方法,幫助您避免這些陷阱,確保HDFS集群的穩定性和高效運行。機架感知配置錯誤:問題:未正確配置機架感知信息,導致數據塊副本分佈不均,增加網絡負載。解決方案:仔細檢查hdfs-site.xml文件中的機架感知配置,並使用hdfsdfsadmin-printTopo

CentOS防火牆的狀態可以通過sudo firewall-cmd --state命令查看,返回running或not running。更詳細的信息可以使用sudo firewall-cmd --list-all查看,包括已配置的區域、服務、端口等。如果 firewall-cmd 無法解決問題,可以使用sudo iptables -L -n查看iptables規則。修改防火牆配置前請務必做好備份,以確保服務器安全性。

在CentOS系統上搭建Hadoop分佈式文件系統(HDFS)需要多個步驟,本文提供一個簡要的配置指南。一、前期準備安裝JDK:在所有節點上安裝JavaDevelopmentKit(JDK),版本需與Hadoop兼容。可從Oracle官網下載安裝包。環境變量配置:編輯/etc/profile文件,設置Java和Hadoop的環境變量,使系統能夠找到JDK和Hadoop的安裝路徑。二、安全配置:SSH免密登錄生成SSH密鑰:在每個節點上使用ssh-keygen命令
