How to Upgrade PHP Version on Ubuntu Server from 7.3 to 8.1

How to change php verson in Ubuntu server 7.3 to 8.1 ||


PHP is a widely used scripting language for web development, and keeping it up-to-date is crucial to leverage the latest features and security enhancements. Ubuntu Server, a popular choice for hosting web applications, often ships with an older version of PHP. In this blog post, we will explore the process of upgrading the PHP version on an Ubuntu Server from 7.3 to 8.1. We will cover the steps involved in adding a new PHP repository, installing the updated PHP version, and configuring the server to use the new version.

Check this blog How to Configure Apache Web Server in Ubuntu: Step-by-Step Guide

  1. Adding a New PHP Repository

To upgrade the PHP version on Ubuntu, we need to add a repository that provides the desired PHP version. There are several third-party repositories available that offer different PHP versions. In this example, we will use the Ondřej Surý’s PPA repository, which is well-maintained and supports multiple PHP versions.

Step 1: Adding the Repository Key Open a terminal window and execute the following command to import the repository key:

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

Step 2: Updating Package Lists Next,

update the package lists to include the newly added repository:

sudo apt update
  1. Upgrading PHP Version

Once we have added the PHP repository, we can proceed with upgrading the PHP version.

Step 1: Installing the Desired PHP Version To install PHP 8.1, execute the following command in the terminal:

sudo apt install php8.1

During the installation process, the package manager will handle the installation of PHP 8.1 and its dependencies.

Step 2: Verifying the Installation After the installation completes, we can verify the PHP version by running the following command:

php -v

This command should display the newly installed PHP 8.1 version information.

  1. Configuring the Server to Use the New PHP Version (400 words)

Now that we have upgraded PHP to version 8.1, we need to configure the server to use this new version.

Step 1: Disabling the Previous PHP Version By default, Ubuntu Server enables Apache’s PHP module for the installed PHP version. To disable the previous PHP version, execute the following command:

sudo a2dismod php7.3

Step 2: Enabling the New PHP Version

To enable PHP 8.1, execute the following command:

sudo a2enmod php8.1

Step 3: Restarting Apache

To apply the changes,restart the Apache web server using the following command:

sudo systemctl restart apache2
  1. Testing the Upgrade

To ensure that the PHP upgrade was successful, we can create a simple PHP script and verify that it runs with the new PHP version.

Step 1: Create a Test PHP File Create a new file named “test.php” in the web server’s document root (usually located at “/var/www/html/”) and add the following content:


Step 2: Access the PHP Info Page Open a web browser and navigate to “http://localhost/test.php” (replace “localhost” with the server’s IP address if accessing remotely). If everything is configured correctly, the PHP info page should load, displaying the PHP 8.1 version information.


Upgrading the PHP version on an Ubuntu Server is a straightforward process that involves adding a new PHP repository, installing the desired PHP version, and configuring the server to use the new version. In this blog post, we covered the steps required to upgrade PHP from version 7.3 to 8.1. By following these steps, server administrators and developers can ensure they have access to the latest features, performance improvements, and security enhancements provided by the updated PHP version. Keeping PHP up-to-date is essential for maintaining a secure and efficient web hosting environment.

Check My Social Profile Links




About The Author

How to change php verson in Ubuntu server 7.3 to 8.1 ||

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow by Email