Share this:

PHP is a popular open-source programming language that is widely used for web development.

The latest version of PHP, version 8.x, was released in November 2021 and comes with several new features and improvements over its predecessor, PHP 7.x.

In this blog, we’ll be discussing how to install the latest version of PHP 8.x on Ubuntu.

Prerequisites

Before we start, it’s important to check if your Ubuntu system is up to date. You can do this by running the following commands in your terminal:

sudo apt-get update
sudo apt-get upgrade

Step 1: Add PPA repository

The latest version of PHP 8.x is not yet included in the default Ubuntu repository, so we need to add a third-party repository to our system. To do this, we’ll be using the Ondřej Surý PPA repository. Run the following commands in your terminal to add the repository:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Step 2: Install PHP 8.x

Now that the repository is added, we can proceed to install PHP 8.x. To install the latest version of PHP 8.x, run the following command in your terminal:

sudo apt-get install php8.0

Step 3: Verify the installation

To verify the installation, run the following command in your terminal:

php -v

This should display the version of PHP installed on your system, which should be PHP 8.x.

Step 4: Configure PHP 8.x

Once you have installed PHP 8.x, you can configure it to your needs by editing the php.ini file. The location of the php.ini file depends on your system, but it is usually located in the /etc/php/8.0/ directory. You can edit the file using any text editor, such as nano or vi.

sudo nano /etc/php/8.0/cli/php.ini

Step 5: Installing PHP extensions

PHP extensions are libraries that add additional functionality to PHP. Some popular extensions include mysql, curl, gd, and mbstring. To install a PHP extension, you’ll need to use the apt-get command.

For example, to install the mysql extension, you can run the following command in your terminal:

sudo apt-get install php8.0-mysql

Replace mysql with the name of the extension you wish to install.

Once the extension is installed, you’ll need to restart your web server for the changes to take effect. If you’re using Apache, you can do this by running the following command:

sudo service apache2 restart

If you’re using Nginx, you can do this by running the following command:

sudo service nginx restart

To check if the extension is installed and working properly, you can create a PHP script with the following contents:

<?php
phpinfo();
?>

Save the file as info.php and place it in your web server’s document root directory. Then, access the file in your web browser by visiting http://localhost/info.php. This will display information about your PHP installation, including a list of installed extensions. Look for the extension you just installed in the list to make sure it is installed and working properly.

In conclusion, installing PHP extensions is a simple process that can greatly enhance the functionality of your PHP installation. Whether you’re a web developer or just someone who uses PHP for your projects, installing the right extensions can make a big difference in your work.

Conclusion

In this blog, we’ve discussed how to install the latest version of PHP 8.x on Ubuntu. With the new features and improvements offered by PHP 8.x, it’s worth taking the time to upgrade to the latest version.

Whether you’re a web developer or just someone who uses PHP for your projects, upgrading to PHP 8.x is a great way to take advantage of its latest features and performance improvements.

Share this:

Categorized in: