Just another upgrade guide for PHP 8.2

Ascend
4 min readAug 20, 2023
Photo by Ben Griffiths on Unsplash

With the launch of Laravel 11 not far off, and with it, a minimum requirement of at PHP 8.2, we thought it necessary to document our thoughts on upgrading to PHP 8.2.

PHP has a interesting history of evolution. With each iteration, certainly since PHP 7, developers have enjoyed an enormous leap forward and strengthening of the language with an array of new features, optimisations and enhancements. The journey to PHP 8.2 is no different.

Why bother upgrading? 🤔

Before delving into the how, you have to understand the why.

  1. Performance : Each release of PHP comes with optimisations that boost performance. Whilst the benchmark difference is minimal between 8.1 and 8.2, upgrading ensures your applications run more efficiently. You’ll notice much more increase in performance if coming from 8.0 or less to PHP 8.2.
Source: Maxcluster | Phoronix
  1. Features: PHP 8.2 introduces several new features — such as Readonly classes, deprecated dynamic properties and disjunctive normal form types — as well as other enhancements that can aid in writing cleaner, more efficient code; such as the new standalone types.
  2. Security: Staying updated with the latest PHP version ensures that your applications benefit from the most recent security patches. Below is a chart showing the PHP support dates for active and End-of-Life (EOL) version.
Source: https://www.php.net/supported-versions.php

Pre-Upgrade Checklist 📋

Before initiating any upgrade, you have to ensure you’re prepared:

Backup everything

We cannot be stress this enough. Before making any significant changes, backup your website, databases and any associated files.

Whilst this should be being done anyway but always advisable to take a copy immediately before initiating your upgrade.

Check compatibility

Review the extensions and libraries your application uses. Ensure they’re compatible with PHP 8.2. In the Steps to Upgrade section, we will explain how you should upgrade and run your application locally and then on a staging environment before trying this with your production site.

Update dependencies

Tools like Composer are helpful for things like that as they will help you ensure all dependencies are updated and compatible with the new PHP version. If you’ve installed dependencies manually (?!) you may find this step a touch more cumbersome.

Steps to Upgrade 🧗‍♂️

With preparations complete, you could use these steps as a guide to upgrade:

Update your local environment

Before updating your production environment, it’s essential to update your local environment, which is typically your development computer used foe coding. This gives you a sandbox to identify and fix any issues that arise, which can be caught, triaged and resolved without affecting your live system availability.

Test

Once your local environment is updated, test your application thoroughly. Pay attention to deprecated functions, new error messages, notices or any behavioural changes in your application.

Unit tests may also behave differently or fail if you’re using now deprecated functionality. Running these should be muscle-memory, but if not, ensure they’re all still passing.

Update your staging environment

Same as with your local environment. Once you’ve upgraded your local environment and confirmed it’s working, it’s important to do the same in your staging environments too.

This is because the underlying operating system may be different and require further configuration. For example, if your staging and production environment servers sit on top of Ubuntu but you’re developing in Windows OS or macOS with ARM architecture, some alternative configurations maybe required.

Test

Now you’re updated, test thoroughly again. Rinse and repeat. Do a final idiot check.

Update production

Once you’re satisfied with the testing:

  • Using a Package Manager: If you’re using a package manager like apt for Ubuntu or yum for CentOS, you can update PHP with the appropriate command, e.g. sudo apt-get install php8.2.
  • Compiling from source: If you prefer to compile PHP from source, download the latest PHP 8.2 source code from the official PHP website and follow the compilation instructions.
  • Using a managed interface: Tools like Plesk make the upgrade process super simple as you can install new PHP interpreters from their components library.

Configure

Once installed, ensure you configure PHP (usually through the php.ini file) to meet your application's requirements.

Final testing

With PHP 8.2 installed on your production environment, conduct a final round of tests to ensure everything functions as expected.

Post-Upgrade Recommendations ✅

After upgrading:

  1. Monitor performance: Use tools like New Relic or Datadog to monitor the performance of your application. Look for any anomalies or areas of improvement.
  2. Stay updated on patches: Even after moving to PHP 8.2, keep an eye out for minor patches or updates that address any subsequent issues or vulnerabilities.
  3. Engage the community: PHP has a great community to engage within forums, discussions and other platforms. You may choose to share your upgrade experience, like we are here, so that others may learn from you and provide assistance to you if needed.

Conclusion

Upgrading to PHP 8.2 is more than just a technical requirement; it’s an opportunity. It allows you to harness new features, optimise performance and ensure security.

However, as with any upgrade, preparation is key. Following the steps outlined here will help ensure your transition to PHP 8.2 is as smooth as possible.

Good hunting.

--

--

Ascend

We're Ascend - a digital transformation agency - and in just a few short years we have defied expectations and are emerging as a true leader in our sector.