The official release of PHP 8 on 11/26/2020 brought many new features and performance improvements. Some great new features that come with PHP 8 are the JIT compiler, named arguments, union types, and attributes. This guide will show you how to install PHP 8.0 on Ubuntu 22.04/24.04, including PHP 8.0-fpm with full extensions, and configure multiple PHP versions on Ubuntu Linux.
Pre-Installation Notes:
- Ensure you have Ubuntu 22.04 installed and have root or sudo privileges.
- Back up your data before making any changes to the system.
- Be cautious with other PHP versions. Uninstall or disable other PHP versions before installing PHP 8.0.
Step 1: Add PPA repository
Add repository only needs to be applied on Ubuntu 18 and 20, on 22.04 is available so you can skip this step. You can refer to the Ondřej Surý PPA for more information. Now start running the command below to install the required packages for PHP 8.0.
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
Next, Add the repository with the following command, and press Enter
to confirm.
sudo add-apt-repository ppa:ondrej/php
Then update the system and install php8.0 ubuntu, type Y
-> Enter
to confirm.
Step 2: Install PHP 8.0
sudo apt update sudo apt install php8.0
Installing php8.0 on ubuntu is as simple as that, type php -v
to check the version, and move on to the next step, install the extensions.
Step 2: Install php8.0-fpm on Ubuntu and PHP modules
To install PHP 8 extensions on Ubuntu 22.04/22.04, use the command:
sudo apt install php8.0-<extension>
And here is the list of extensions for php8.0:
sudo apt install php8.0- php8.0-amqp php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-readline php8.0-sqlite3 php8.0-xsl php8.0-apcu php8.0-curl php8.0-gmp php8.0-mailparse php8.0-opcache php8.0-redis php8.0-sybase php8.0-yac php8.0-ast php8.0-dba php8.0-igbinary php8.0-mbstring php8.0-pgsql php8.0-rrd php8.0-tidy php8.0-yaml php8.0-bcmath php8.0-dev php8.0-imagick php8.0-memcached php8.0-phpdbg php8.0-smbclient php8.0-uuid php8.0-zip php8.0-bz2 php8.0-ds php8.0-imap php8.0-msgpack php8.0-pspell php8.0-snmp php8.0-xdebug php8.0-zmq php8.0-cgi php8.0-enchant php8.0-interbase php8.0-mysql php8.0-psr php8.0-soap php8.0-xhprof php8.0-cli php8.0-fpm php8.0-intl php8.0-oauth php8.0-raphf php8.0-solr php8.0-xml
Here I only install php8.0-fpm and some necessary extensions for the project, so the command is as follows:
sudo apt install php8.0-fpm php8.0-cli php8.0-common php8.0-imap php8.0-redis php8.0-snmp php8.0-xml php8.0-zip php8.0-mbstring
Enable php8.0-fpm and allow php-fpm
to start with the system.
sudo systemctl enable php8.0-fpm sudo service php8.0-fpm restart
You can install and use multiple PHP versions for each website (project). The command changes the default php version, just enter the version number.
sudo update-alternatives --config php
Above are the steps to successfully install PHP 8.0 on Ubuntu 22.04 or 24.04 LTS. To enhance your PHP environment, consider optimizing PHP-FPM performance. For detailed guidance, refer to the article: Optimize performance pm.max_children and fix PHP-FPM.