原本 Ubuntu 16.04 預設的 PHP 版本為 7.0.x,無發自動更新到 PHP 7.4.x,有點可惜,畢竟 PHP 7.4 有著更好的效能。
下面簡單紀錄一下整個升級安裝的過程:
Step 1: 新增 PHP PPA Repository
sudo apt-get update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Step 2: 安裝 PHP 7.4
sudo apt install php7.4
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl php7.4-bcmath php7.4-bz2 php7.4-fpm
Step 3: 檢查 PHP 版本
php -v
~$ php -v
PHP 7.4.11 (cli) (built: Oct 6 2020 10:35:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
Step 4: 啟用 PHP 7.4 FPM 模組
sudo a2disconf php7.0-fpm
sudo a2enconf php7.4-fpm
sudo service apache2 stop
sudo a2dismod mpm_prefork php7.4
sudo a2enmod mpm_event
sudo service php7.4-fpm restart
sudo service apache2 restart
About the author