如何在 Rocky/AlmaLinux 9|8 上安裝 PHP 8.4
PHP 8.4 尚未準備好用於正式生產環境,但已經有 Alpha 版本可供測試及與開發團隊分享回饋。在本文中,我們將在 Rocky Linux/AlmaLinux 上安裝 PHP 8.4,相同的流程應該也適用於 CentOS Stream 9 或 8。在上一篇文章中,我們介紹了在 Ubuntu Linux 上安裝 PHP 8.4。關於 PHP 8.4 預期的變更和新功能,請參考以下連結/資源:
- PHP.Watch 頁面
- Laravel 新聞
在剛配置好的 Rocky/AlmaLinux 實例上進行此安裝也是一個好做法,以避免因應用程式提供實時流量而破壞活動系統。
添加 EPEL 和 REMI 軟體庫
首先,我們需要將 EPEL 和 REMI 軟體庫加入系統。
- 新增 EPEL 軟體庫
sudo dnf -y install epel-release- 安裝 REMI 軟體庫
## EL 9-based systems ##
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
## EL 8-based systems ##
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm可以透過列出系統中可用的儲存庫來進行驗證。
$ sudo dnf repolist
repo id repo name
appstream Rocky Linux 8 - AppStream
baseos Rocky Linux 8 - BaseOS
epel Extra Packages for Enterprise Linux 8 - x86_64
extras Rocky Linux 8 - Extras
remi-modular Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe Safe Remi's RPM repository for Enterprise Linux 8 - x86_64
您可能需要啟用包含不穩定軟體套件的 remi-safe 軟體庫。
sudo dnf config-manager --set-enabled remi-safe在 Rocky/AlmaLinux/CentOS Stream 上安裝 PHP 8.4
在添加這兩個軟體庫後,即可在您的本地系統上安裝 PHP 8.4。若要了解系統中可用的最新 PHP 版本,請執行以下命令:
sudo dnf module list php透過執行以下指令安裝 PHP 8.4:
sudo dnf install php84系統將提示您接受安裝,輸入 y 並按 <ENTER>
Dependencies resolved.
===================================================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================================================================================================================================================================================
Installing:
php84 x86_64 8.4-1.el8.remi remi-safe 8.0 k
Installing dependencies:
capstone x86_64 4.0.2-5.el8 epel 1.1 M
environment-modules x86_64 4.5.2-4.el8 baseos 421 k
httpd-filesystem noarch 2.4.37-65.module+el8.10.0+1840+b070a976.1 appstream 44 k
libsodium x86_64 1.0.18-2.el8 epel 162 k
libxslt x86_64 1.1.32-6.el8 baseos 249 k
oniguruma5php x86_64 6.9.9-1.el8.remi remi-safe 213 k
php84-php-cli x86_64 8.4.0~alpha4-1.el8.remi remi-safe 3.9 M
php84-php-common x86_64 8.4.0~alpha4-1.el8.remi remi-safe 785 k
php84-runtime x86_64 8.4-1.el8.remi remi-safe 1.1 M
scl-utils x86_64 1:2.0.2-16.el8 appstream 46 k
tcl x86_64 1:8.6.8-2.el8 baseos 1.1 M
Installing weak dependencies:
php84-php-fpm x86_64 8.4.0~alpha4-1.el8.remi remi-safe 2.0 M
php84-php-mbstring x86_64 8.4.0~alpha4-1.el8.remi remi-safe 553 k
php84-php-opcache x86_64 8.4.0~alpha4-1.el8.remi remi-safe 529 k
php84-php-pdo x86_64 8.4.0~alpha4-1.el8.remi remi-safe 159 k
php84-php-sodium x86_64 8.4.0~alpha4-1.el8.remi remi-safe 104 k
php84-php-xml x86_64 8.4.0~alpha4-1.el8.remi remi-safe 889 k
Enabling module streams:
httpd 2.4
Transaction Summary
===================================================================================================================================================================================================================================================================================
Install 18 Packages
Total download size: 13 M
Installed size: 53 M
Is this ok [y/N]: y請注意,此安裝來自 SCL,並且與您的系統獨立,能保護基礎作業系統的安全。需注意幾點:
- 安裝位於 /opt/remi/php84 目錄下
- 配置檔案放置在 /etc/opt/remi/php84 目錄中
要取得已安裝的 PHP 8.4 版本,請使用以下指令:
$ php84 --version
PHP 8.4.0alpha4 (cli) (built: Aug 1 2024 00:50:38) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.4.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.4.0alpha4, Copyright (c), by Zend Technologies安裝 PHP 8.4 擴充功能
使用以下指令來安裝 PHP 8.4 擴充功能。
sudo dnf install php84-<extension>讓我們考慮一個範例,我們正在安裝 mysqlnd 和 zip 擴展套件。
sudo dnf install php84-php-mysqlnd php84-php-zip要列出已列出的模組,請執行以下命令:
$ php84 --modules
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
random
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache當 PHP 8.4 的正式穩定版本推出時,我們將會更新這篇文章。請持續關注最新消息。
