Current Location: Home> Latest Articles> How to Upgrade PHP 7.1 to PHP 7.3 on Ubuntu 16.04 + Apache2

How to Upgrade PHP 7.1 to PHP 7.3 on Ubuntu 16.04 + Apache2

gitbox 2025-06-15

1. Update apt-get Sources

Before switching PHP versions, we first need to update the apt-get sources to ensure that all software on the system is up to date. Run the following commands to update the package sources:

sudo apt-get update
sudo apt-get upgrade

2. Install PHP 7.3

Next, we need to install PHP 7.3. Use the following commands to install PHP 7.3 and its related modules:

sudo apt-get install php7.3
sudo apt-get install libapache2-mod-php7.3

You may encounter dependency issues during the installation, so follow the on-screen prompts to resolve them.

3. Switch to PHP 7.3

3.1 Disable PHP 7.1 Module

After installing PHP 7.3, Apache might still use the PHP 7.1 module by default. To enable PHP 7.3, we first need to disable the PHP 7.1 module. Use the following command:

sudo a2dismod php7.1

3.2 Enable PHP 7.3 Module

Once PHP 7.1 is disabled, enable the PHP 7.3 module with the following command:

sudo a2enmod php7.3

3.3 Restart Apache Server

After enabling the new PHP module, restart the Apache server for the changes to take effect:

sudo systemctl restart apache2

4. Verify PHP 7.3 Installation

To verify if PHP 7.3 is successfully installed, run the following command to check the PHP version. If it outputs PHP 7.3, the installation is successful:

php -v

Additionally, you can verify the PHP version by creating a simple PHP file (e.g., phpinfo.php) and adding the following content:

<?php phpinfo(); ?>

Place this file in the root directory of your Apache server, then visit "http://localhost/phpinfo.php" in your browser. If the page displays PHP 7.3, the version switch has been successful.