How to Install PHP 8 on Ubuntu 20.04

Practically everything is working on the web, something that seems not to change soon. And on the web, one of the languages that we find most is PHP which has recently released version 8. If you are a web developer then you have to learn how to install PHP 8 on Ubuntu 20.04 to have the latest version available of this programming language.

PHP 8

PHP is a programming language used to create web applications. These applications can be very varied and some of them are even professional like WordPress. That is why many developers prefer it for the development of their applications.

PHP being an interpreted language is usually quite fast when processing the code. But this depends on the computer or server that is processing it and the HTTP server that serves the project.

Recently, the PHP development team has released PHP 8 loaded with many new features that will take some time to be adopted but it is also true that developers are already using it in some projects. Some improvements include a better performance by caching and the JIT compiler.

So by improving performance considerably, we are talking about a major version that deserves all the credit.

Installing PHP 8 on Ubuntu 20.04

Ubuntu 20.04 includes in its PHP 7.4 repositories This version is quite good and useful because it will have support for a long time, but sometimes it is convenient to have a bigger version.

So PHP 8 is not included in the official Ubuntu 20.04 repositories but the procedure is not complex at all. It’s just a matter of adding an external repository.

Note: for this tutorial whose aim is to install PHP 8, I will install Apache as a web server.

So, open a terminal and update the system. This process is recommended to have a system with security patches installed.

sudo apt update
sudo apt upgrade

After that, it is necessary to install some additional packages to add the repository where it is hosted.

sudo apt-get install software-properties-common

Then add the Ondrej repository which is where we will install PHP 8

sudo add-apt-repository ppa:ondrej/php

Then update APT to load the new repository:

sudo apt update

Now install Apache along with PHP 8:

sudo apt install apache2 php8.0 php8.0-intl libapache2-mod-php8.0

Typing the password will start the whole installation process.

Creating a test file for PHP 8

Now it is necessary to check that the whole installation has been a success, to do this it is best to create a file with some PHP code and see if it is being processed.

So, in the terminal change the permissions on the Apache folder.

sudo chmod 755 -R /var/www/html/

Also, make Apache the owner of that whole folder so that it will not run into problems:

sudo chown -R www-data:www-data /var/www/html/

Then, if your computer or server has a firewall running, you have to enable port 80 for the webserver to work,

sudo ufw allow 80/tcp

Then create a PHP file in the Apache directory using the nano editor:

sudo nano /var/www/html/test.php

And add the phpinfo() method that displays informationHow to Install Google Chrome on Ubuntu : Tutorial for Beginners about PHP.

<?php
   phpinfo();
?>

Save the changes and close the file.

Now open your web browser and try to open it by going to http://SERVER_IP/test.php

PHP 8 on Ubuntu 20.04
PHP 8 on Ubuntu 20.04

If you see an output like this, then PHP 8 is correctly installed on Ubuntu 20.04

Conclusion

PHP 8 is a version loaded with new features that have been released for everyone. This fairly easy to get version promises a performance improvement that makes it attractive to existing developers and sysadmins. Now you can install it on Ubuntu 20.04 without any problems.

So, are you a developer? do you like PHP? leave us a comment and share our post.

Scroll to Top