如何在CentOS 6和CentOS 7或CentOS 8上安裝PHP 5.4、5.5、5.6或7.3、7.4、8.0版本

我們為目前線上客戶安裝的Linux都是CentOs發行版,是一套穩定、同時也是許多企業正在運行的版本。
在CentOs所採用的PHP版本較為保守,可以看到如下評論(taken from DistroWatch) CentOS is a bit outdated with it’s PHP versions which as a PHP developer can be a pain in the ass!
如何在CentOS 6和CentOS 7或CentOS 8上安裝PHP 5.4、5.5、5.6或7.3、7.4、8.0版本
PHP Current Version | CentOS 8.3.2011 | CentOS 7.9.2009 | CentOS 6.10 |
---|---|---|---|
8.0.9 | 7.2.34 | 5.4.45 | 5.3.3 |
現在我們可以利用另一個Linux發行版本Fedora的project來改善PHP版本問題。我們需要補充兩個Repos。首先我們需要EPEL 再來需要Remi 。
Repo設置
先確認您的伺服器已經打開SSH通道,然後執行下面指令(您需要有執行指令的權限,如果有必要建議使用root操作,或是sudo):
在CentOS 8下(啟用 REMI 和 EPEL)
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm或
wget https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/e/epel-release-8-8.el8.noarch.rpm wget https://rpms.remirepo.net/enterprise/remi-release-8.rpm rpm -Uvh remi-release-8*.rpm epel-release-8*.rpm
在CentOS 8下查看可用的PHP版本
dnf module list php
啟用PHP 7.3(如果要使用REMI的PHP可以將7.3改remi-8.0)
dnf module enable php:7.3
在CentOS 7下(包含安裝EPEL)
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-13.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
如果您原本就已經裝過EPEL則執行下面指令:
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7*.rpm
在CentOS 6下(包含安裝EPEL)
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
如果您原本就已經裝過EPEL則執行下面指令:
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm
啟動程式庫(Repo,repository)
進行到目前為止,我們需要確認程式庫有被啟動,同時選訂我們想要安裝的版本。 We need to head over to /etc/yum.repos.d
you should inside see a file called remi.repo
.
使用您喜好的編輯器(Nano、Pico、Vi ...etc)開啟remi.repo這隻檔案,您將看到一部份參數。我們需要確認第一階段[remi]
是啟用狀態。
[remi] name=Les RPM de remi pour Enterprise Linux 6 - $basearch #baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
這一行enabled=1
確認要設定!在技術上現在是可以繼續進行PHP安裝,但是將只會取得PHP 5.4.X版本。這如果不是你要的,那麼跳到下一步驟!
If we want PHP 5.5 or PHP 5.6 we need to do a bit more work, further down in the repo.repo
file you will see two additional sections [remi-php55]
and [remi-php56]
, decide which PHP version you want to install and then enable the correct. So for PHP 5.6 we would change to:
[remi-php56] name=Les RPM de remi de PHP 5.6 pour Enterprise Linux 6 - $basearch #baseurl=http://rpms.famillecollet.com/enterprise/6/php56/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/php56/mirror # WARNING: If you enable this repository, you must also enable "remi" enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Once you made your changes save your modified file and quit your editor.
如何將CentOS 7的PHP升級到7.0或7.1或7.2或7.3或7.4
使用文字編輯器開啟【remi-php70.repo】或【remi-php71.repo】或【remi-php72.repo】或【remi-php73.repo】或【remi-php74.repo】將想要安裝的PHP enabled即可。# This repository only provides PHP 7.1 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php71] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror mirrorlist=http://rpms.remirepo.net/enterprise/7/php71/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-debuginfo] name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php71/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test71/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test71/httpsmirror mirrorlist=http://rpms.remirepo.net/enterprise/7/test71/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php71-test-debuginfo] name=Remi's PHP 7.1 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test71/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Installing PHP
Now I’m assuming you don’t already have PHP installed, this bit is super simple.
sudo yum install php php-gd php-mysql php-mcrypt php-mbstring
sudo yum install php71 php71-php-gd php71-php-mysql php71-php-mcrypt php71-php-mbstring
So the above assumes you want MySQL, GD and Mcrypt support in your PHP, but you should see something like the below depending on which version of PHP you are trying to install:
================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Installing: php x86_64 5.5.20-2.el6.remi remi-php55 2.6 M php-gd x86_64 5.5.20-2.el6.remi remi-php55 72 k php-mysqlnd x86_64 5.5.20-2.el6.remi remi-php55 3.6 M Installing for dependencies: php-cli x86_64 5.5.20-2.el6.remi remi-php55 3.7 M php-common x86_64 5.5.20-2.el6.remi remi-php55 1.0 M php-pdo x86_64 5.5.20-2.el6.remi remi-php55 112 k php-pear noarch 1:1.9.5-3.el6.remi remi 375 k php-pecl-jsonc x86_64 1.3.6-1.el6.remi.5.5.1 remi-php55 47 k php-pecl-zip x86_64 1.12.4-1.el6.remi.5.5 remi-php55 269 k php-process x86_64 5.5.20-2.el6.remi remi-php55 57 k php-xml x86_64 5.5.20-2.el6.remi remi-php55 208 k Transaction Summary ================================================================================================================================ Install 11 Package(s)
As you can see PHP is installing version 5.5.20-2.el6.remi from the remi-php55 repo! Once you have hit Y to confirm the install restart apache and magical unicorns you have a better version of PHP!
You can also change your mind in the future by going back into the remi.repo
file and enable a different PHP version and then run yum update
and if you have moved from 5.5 to 5.6 it will upgrade PHP for you. If you want to downgrade for any reason you will need to remove PHP (sudo yum remove php*
) and then reinstall the PHP modules you want.
相關VI編輯器操作筆記
在putty下輸入
vi /etc/yum.repos.d/remi.repo
會打開/etc/yum.repos.d/remi.repo檔
此時是處於 c-mode 模式下,無法輸入文字,按「a」鍵,轉為 i-mode模式,即可開始進行修改,同時可以看到左下角提示「INSERT」,表示現在正在 i-mode 可修改模式下。
改完按「Esc」鍵,由i-mode修改模式回到c-mode指令模式,接著按冒號「:」進入命令列模式,此時左下角會出現冒號與閃爍游標,此時可以在冒號後輸入以下指令:
w: 存檔(write)。注意在編輯過程中所有內容只存在暫存器裡,必須在 c-mode 下了這個「:w」指令才會存檔。
e: 重新編輯(edit)。
q: 退出(quit),如果檔案經過修改而沒有存檔,會出現錯誤訊息:鍵入「:q!」強制退出 (此次作的修改會流失)
cat /etc/redhat-release
cat /proc/version
rpm -q centos-release檢查硬碟使用量
df
Search console分析這篇最多人,可不可以↓幫忙我按↓下面的讚。
-
網頁設計基礎要弄懂的知識,甚麼是表格甚麼是儲存格?
Published on 2025-04-11 11:10:00 -
你可能不知道的meta標籤!renderer介紹!
Published on 2025-03-27 12:00:00 -
JavaScript 中的防抖與節流:簡單明瞭的前端解析
Published on 2025-03-14 18:10:00 -
行動網頁設計的好幫手HTML capture讓用戶直接使用手機的麥克風與鏡頭!
Published on 2025-03-13 17:40:00 -
圖示設計實用指南:提供圖示設計的實用技巧與建議,包含UX和UI設計推薦,幫助設計師創建清晰、簡潔且具吸引力的圖示。
Published on 2025-03-08 19:20:00 -
CSS Grid是網頁設計中2D排版的好幫手!repeat() 與minmax()的應用介紹
Published on 2025-03-07 17:30:00 -
流動式版面設計 (Fluid Layout) 指南:網頁設計的演變趨勢
Published on 2025-03-06 14:20:00 -
HTML輸入元素input少見屬性pattern介紹,設計網頁時可以試試
Published on 2025-03-06 13:50:00 -
數位身份的隱形印記:深入解析Canvas指紋追蹤技術
Published on 2025-03-05 15:30:00 -
CSS 媒體查詢(Media Queries)介紹
Published on 2025-03-05 15:00:00 -
強大的CSS變數功能!為新式網頁設計創建可維護、可擴展的樣式!
Published on 2025-03-04 00:30:00 -
設計使用者網頁介面的最佳實踐,如何有效提升UI設計!
Published on 2025-03-02 15:30:00 -
列項符號也可以增加動畫效果!CSS ::marker 選擇器使用教學!
Published on 2025-03-01 21:30:00 -
自適應網頁設計使用夾鉗參數讓網站更美觀clamp()使用介紹!
Published on 2025-03-01 21:00:00 -
網頁設計中推薦使用CSS Anchor定位元素!可以更靈活配置版面!
Published on 2025-03-01 00:10:00 -
利用scroll-margin設計網頁可以有效提升客戶體驗
Published on 2025-02-28 19:00:00 -
interpolate-size讓我的網頁動畫原始碼更精簡!
Published on 2025-02-27 21:40:00 -
網頁設計的革命:當上帝視角UX成為未來趨勢
Published on 2025-02-26 15:40:00 -
3D網頁設計CSS必學重點:preserve-3d與flat!
Published on 2025-02-25 20:50:00 -
前端網頁設計動畫套件anime easing介紹與範例
Published on 2025-02-10 00:00:00 -
網頁設計的關鍵原則米勒定律,由心理學解釋人類注意力所衍生的設計要點。
Published on 2025-02-02 17:00:00 -
NPU是甚麼?詳細解說CPU、GPU、NPU、TPU!
Published on 2024-10-31 14:00:00 -
環保公司網頁設計案例:樺欣環保工程有限公司官網建置
Published on 2024-09-19 18:00:00 -
選擇網頁設計公司依據地圖評價準確嗎?
Published on 2024-09-15 12:00:00 -
網頁設計中推薦使用Anchor定位元素的新方法!
Published on 2024-08-28 23:40:00 -
甚麼是ARM伺服器?
Published on 2024-06-22 00:00:00 -
自行架設網站的優缺點分析
Published on 2024-03-10 18:00:00 -
房地產網頁設計案例:詠騰工業不動產官網架設
Published on 2023-12-31 10:50:00 -
無障礙網站設計與無障礙標章檢測等級
Published on 2023-10-29 14:10:00 -
如何挑選出穩健的網頁設計公司
Published on 2023-09-16 14:30:00