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
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.
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
Once PHP 7.1 is disabled, enable the PHP 7.3 module with the following command:
sudo a2enmod php7.3
After enabling the new PHP module, restart the Apache server for the changes to take effect:
sudo systemctl restart apache2
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.