
Upgrading your PHP version is crucial to maintaining the security, performance, and compatibility of your web applications. With the release of PHP 8, developers can take advantage of exciting new features, improved performance, and enhanced security compared to PHP 7. Ubuntu 20.04, combined with the Apache web server, offers a robust environment for hosting PHP-based applications, making it an excellent choice for this upgrade. This guide will show you how to Upgrade From PHP 7.x to PHP 8 on Ubuntu 20.04 with Apache web server.. Check the migration guide for new features and incompatible changes.
Before proceeding, it is recommended to make a backup of your server. Then, test the backup by deploying a new instance from the backup, then verify that the test instance boots and has the correct data. If you do not make a backup before proceeding, you risk losing your data.
Before upgrading PHP, find all the PHP 7.x modules currently installed on the server. These will need to be upgraded along with PHP core to their respective 8 versions.
Take note of the version number of the current PHP installation; this will be needed later.
Ubuntu may not yet have PHP version 8 in its official repositories, and you can install PHP 8 from the ondrej/php repository, a long-time and community-trusted repository for Ubuntu PHP packages.
Add the necessary repository.
Install PHP 8.
Install related PHP modules; below are some of the most frequently used. Please refer back to step 1 and manually install any modules necessary that are missing, replacing 7.x with 8.0.
Once complete, restart PHP
Verify PHP has been installed correctly.
The a2enmod and a2dismod scripts can be used for enabling and disabling PHP versions in Apache.
Disable the previous PHP version installed. Replace 7.x with the version number noted in step 1.
Enable PHP 8.
Restart the Apache web server.
Navigate to the document root of a website on the server. For this example the document root is /var/www/html.
Create a PHP file.
Add the following content to the file.
Open a browser and access the file at http://[ip-address]/phpinfo.php or http://[domain]/phpinfo.php and verify it displays the correct PHP version.
Remember to remove
phpinfo.phpwhen finished to prevent exposing sensitive information about your server.
You have now successfully migrated from PHP 7.x to PHP 8 on your Apache web server.
0 Comments
Be the first to comment and share your perspective with the community.