PHP is by a long stretch, one of the most popular server-side programming languages in the market. It’s is ised by over 50% of all websites. Popular websites like WIkipedia, WordPress, Facebook, Magento, and Laravel are all written in PHP.
PHP 8.0 is the latest major release of the PHP language. It introduces several breaking changes, performance improvements, and lots of new features such as named arguments, JIT compiler, union types, match expression, and more.
This article will show you how to install PHP 8 on Ubuntu 20.04 and integrate it with Nginx and Apache. At the time of writing, the default Ubuntu 20.04 repositories include PHP 7.4 version. We’ll install PHP from the ondrej/php PPA repository.
Before upgrading to or installing PHP 8, make sure that your applications support it. The same steps apply for Ubuntu 18.04 and all Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.
Enabling PHP Repository
Ondřej Surý, a Debian developer, maintains a repository that includes multiple PHP versions. To enable the repository , run:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
Once the PPA is enabled, you can install PHP 8.
Installing PHP 8.0 with Apache
If you’re using Apache as a web server, you can run PHP as an Apache module or PHP-FPM. Installing PHP as an Apache module is a straightforward task:
sudo apt update
sudo apt install php8.0 libapache2-mod-php8.0
Once the packages are installed, restart Apache for the PHP module to get loaded:
sudo systemctl restart apache2
Configure Apache with PHP-FPM
PHP-FPM is a FastCGI process manager for PHP. Run the following command to install the necessary packages:
sudo apt update
sudo apt install php8.0-fpm libapache2-mod-fcgid
By default PHP-FPM is not enabled in Apache. To enable it, run:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm
To activate the changes, restart Apache:
systemctl restart apache2
Installing PHP extensions
PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt :
sudo apt install php8.0-[extname]
For example, to install MySQL and GD extensions, you would run the following command
sudo apt install php8.0-mysql php8.0-gd
After installing a new PHP extension, do not forget to restart Apache or PHP FPM service, depending on your setup.
In conclusion, tnstalling PHP 8 on Ubuntu 20.04 server is a pretty straightforward task. The main thing is to enable the “ondrej/php” repository and install PHP 8 with apt.
If you have any questions or feedback, feel free leave a comment.
Discussion about this post