如何在CentOS 8 / RHEL 8上安裝PHP 8.0
廣告
PHP是嵌入在HTML中的一種開源編程語言。 它主要用於創建動態網站,例如博客,電子商務網站等。RasmusLerdorf於1994年創建了它。
CentOS 8 / RHEL 8默認帶有PHP v7.2。
在這篇文章中,我們將看到如何在CentOS 8 / RHEL 8上安裝PHP 8.0。
添加Remi存儲庫
Remi,一個第三方存儲庫,為Red Hat Enterprise Linux提供了多個PHP版本(8.0 / 7.4 / 7.3 / 7.2)。
Remi系統信息庫要求在系統上啟用EPEL系統信息庫。 因此,在系統上安裝最新的EPEL存儲庫自動配置rpm,以啟用EPEL存儲庫。
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
然後,使用以下命令安裝Remi存儲庫自動配置軟件包。
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
輸出:
CentOS-8 - AppStream 1.4 MB/s | 5.8 MB 00:04 CentOS-8 - Base 128 kB/s | 2.2 MB 00:17 CentOS-8 - Extras 3.8 kB/s | 8.6 kB 00:02 CentOS-8 - PowerTools 764 kB/s | 1.9 MB 00:02 Extra Packages for Enterprise Linux Modular 8 - x86_64 30 kB/s | 98 kB 00:03 Extra Packages for Enterprise Linux 8 - x86_64 4.6 MB/s | 8.4 MB 00:01 Google Cloud SDK 5.4 MB/s | 22 MB 00:04 Google Compute Engine 2.1 kB/s | 6.9 kB 00:03 remi-release-8.rpm 15 kB/s | 23 kB 00:01 Dependencies resolved. =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Installing: remi-release noarch 8.1-2.el8.remi @commandline 23 k Upgrading: centos-release x86_64 8.2-2.2004.0.2.el8 BaseOS 21 k Installing dependencies: centos-gpg-keys noarch 8.2-2.2004.0.2.el8 BaseOS 12 k centos-repos x86_64 8.2-2.2004.0.2.el8 BaseOS 13 k Transaction Summary =================================================================================================================== Install 3 Packages Upgrade 1 Package Total size: 69 k Total download size: 46 k Downloading Packages: (1/3): centos-gpg-keys-8.2-2.2004.0.2.el8.noarch.rpm 12 kB/s | 12 kB 00:01 (2/3): centos-repos-8.2-2.2004.0.2.el8.x86_64.rpm 12 kB/s | 13 kB 00:01 (3/3): centos-release-8.2-2.2004.0.2.el8.x86_64.rpm 20 kB/s | 21 kB 00:01 ------------------------------------------------------------------------------------------------------------------- Total 12 kB/s | 46 kB 00:03 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: centos-gpg-keys-8.2-2.2004.0.2.el8.noarch 1/1 Installing : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch 1/5 Upgrading : centos-release-8.2-2.2004.0.2.el8.x86_64 2/5 Installing : centos-repos-8.2-2.2004.0.2.el8.x86_64 3/5 Installing : remi-release-8.1-2.el8.remi.noarch 4/5 Cleanup : centos-release-8.0-0.1905.0.9.el8.x86_64 5/5 Running scriptlet: centos-release-8.0-0.1905.0.9.el8.x86_64 5/5 Verifying : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch 1/5 Verifying : centos-repos-8.2-2.2004.0.2.el8.x86_64 2/5 Verifying : remi-release-8.1-2.el8.remi.noarch 3/5 Verifying : centos-release-8.2-2.2004.0.2.el8.x86_64 4/5 Verifying : centos-release-8.0-0.1905.0.9.el8.x86_64 5/5 Upgraded: centos-release-8.2-2.2004.0.2.el8.x86_64 Installed: remi-release-8.1-2.el8.remi.noarch centos-gpg-keys-8.2-2.2004.0.2.el8.noarch centos-repos-8.2-2.2004.0.2.el8.x86_64 Complete!
安裝Remi存儲庫rpm後,列出可用的PHP模塊流。
dnf module list php
您應該看到以下輸出。
CentOS-8 - AppStream Name Stream Profiles Summary php 7.2 [d] common [d], devel, minimal PHP scripting language php 7.3 common [d], devel, minimal PHP scripting language Remi's Modular repository for Enterprise Linux 8 - x86_64 Name Stream Profiles Summary php remi-7.2 common [d], devel, minimal PHP scripting language php remi-7.3 common [d], devel, minimal PHP scripting language php remi-7.4 common [d], devel, minimal PHP scripting language php remi-8.0 common [d], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
在CentOS 8 / RHEL 8上安裝PHP 8.0
啟用php:remi-8.0模塊以安裝PHP 8.0。
dnf module enable php:remi-8.0 -y
輸出:
Dependencies resolved. =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Enabling module streams: php remi-8.0 Transaction Summary =================================================================================================================== Complete! Switching module streams does not alter installed packages (see 'module enable' in dnf(8) for details)
使用dnf命令在CentOS 8 / RHEL 8上安裝PHP 8.0。
dnf install -y php php-cli php-common
在CentOS 8 / RHEL 8上安裝PHP 7.x
如本文所示,啟用php:remi-7.x模塊以在系統上安裝PHP7.x。
安裝PHP-FPM
如果要在RHEL 8上設置LEMP堆棧,則可能要安裝php-fpm。
dnf install -y php-fpm
安裝PHP擴展
PHP擴展是已編譯的庫,可為您的代碼提供特定的支持。
廣告
要在代碼上提供MySQL支持,可以安裝php-mysqlnd軟件包。
dnf install -y php-mysqlnd
現在,以下命令將列出已安裝的MySQL擴展。
php -m | grep -i mysql
輸出:
mysqli mysqlnd pdo_mysql
結論
就這樣。 我希望您已經學會了如何在CentOS 8 / RHEL 8上安裝PHP 8.0。請在評論部分中分享您的反饋。