In this article, we will have explained the necessary steps to install and configure PHP 8 on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
PHP is a recursive acronym for Hypertext Preprocessor and is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Many popular CMS and frameworks such as WordPress, Laravel, and many more are built in PHP.
Install PHP 8 on Ubuntu 18.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install PHP 8 on the Ubuntu system.
Now add the
ondrej/php which has PHP 8 package and other required PHP extensions:
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
Once the repository is added, install PHP packages with the below command:
sudo apt install php8.0
After the installation has completed, you can confirm the installation using the following command:
Step 3. Install PHP 8 Extensions in Ubuntu.
PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with
sudo apt install php8.0-[extensions-name]
For instance, the example below installs the SNMP, Memcached, and MySQL extensions:
sudo apt install php8.0-snmp php-memcached php8.0-mysql
Step 4. Verify the installation.
To confirm the version of PHP installed, from the graphical environment we can create a PHP file
/var/www/html called info.php:
sudo nano /var/www/html/info.php
Add the following line:
<?php phpinfo(); ?>
After adding the following command, save the info.php and go to the web browser and search for
http://localhost or your IP address with a filename using forward slash:
That’s all you need to do to install PHP on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on PHP 8, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.