Back
How to safely upgrade to PHP 7.3

How to safely upgrade to PHP 7.3

- - Articles

The PHP development team released PHP 7.3.0 five days ago. Today we’re happy to announce that Moss fully supports the brand new 7.3 branch of your favorite language!

Upgrading your website to PHP 7.3 with Moss is quite a simple thing: Just choose the new version in the settings of your site(s). However, there are some things to consider before jumping into 7.3. Like with every release, some features come in and others go out. Let’s see how to safely upgrade your application without unpleasant surprises.

Steps

  1. If you’re the author of your website’s application, check out the official migration guide to see if there’re backward incompatible changes that impact your codebase. In such case, release a fix before going further.
  2. If you’re not the author of the application, try to check if the underlying software claims support of PHP 7.3. E.g. WordPress 5.0 officially supports PHP 7.3.
  3. Regardless the former points, we highly encourage you to run a staging or test version of your website(s). Upgrade to PHP 7.3 there and run as many tests as possible to gain confidence that your website runs smoothly with the new PHP version.
  4. Once you’re done with it, upgrade your production website to PHP 7.3 🚀 Remember that with Moss you can have multiple websites on the same server running different PHP versions, so you don’t have to upgrade all your websites at once 😎

What could go wrong?

Despite your application must be PHP 7.3 ready right now, you might still find some problems if you use older versions of PHP applications that don’t comply with PHP 7.3 yet. Let’s see three examples.

ProblemPHP 7.3. breaks compatibility of composer < 1.6.0

The deployment of your website might fail if it runs composer to install your application’s dependencies:

Installation failed, reverting ./composer.json to its original content.

  [ErrorException]
  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?  

Exception trace:
 () at /usr/share/php/Composer/DependencyResolver/RuleSetGenerator.php:286
 Composer\Util\ErrorHandler::handle() at /usr/share/php/Composer/autoload.php:258
 require() at /usr/share/php/Composer/autoload.php:258
 {closure}() at n/a:n/a
 spl_autoload_call() at /usr/share/php/Composer/DependencyResolver/Solver.php:75
 Composer\DependencyResolver\Solver->__construct() at /usr/share/php/Composer/Installer.php:459
 Composer\Installer->doInstall() at /usr/share/php/Composer/Installer.php:216
 Composer\Installer->run() at /usr/share/php/Composer/Command/RequireCommand.php:175
 Composer\Command\RequireCommand->execute() at /usr/share/php/Symfony/Component/Console/Command/Command.php:259
 Symfony\Component\Console\Command\Command->run() at /usr/share/php/Symfony/Component/Console/Application.php:844
 Symfony\Component\Console\Application->doRunCommand() at /usr/share/php/Symfony/Component/Console/Application.php:192
 Symfony\Component\Console\Application->doRun() at /usr/share/php/Composer/Console/Application.php:231
 Composer\Console\Application->doRun() at /usr/share/php/Symfony/Component/Console/Application.php:123
 Symfony\Component\Console\Application->run() at /usr/share/php/Composer/Console/Application.php:104
 Composer\Console\Application->run() at /usr/bin/composer:44

In previous releases of PHP, the keyword continue behaves like a break if it’s within a switch block. Such behavior has been deprecated because it doesn’t align with how it works in other programming languages. Composer fixed this problem long time ago (September 2017), but you might face this issue if you’re using an old version. [In case you’re a Moss user, remember that you can easily update composer on a regular basis by setting up a cron job]

Fix: Update composer by running
sudo composer self-update

Problem: composer self-update doesn’t work in composer < 1.7

This is not related to PHP 7.3, but trying to fix the previous problem you might get affected by this one.

  [RuntimeException]
  SHA384 is not supported by your openssl extension, could not verify the phar file integrity

Exception trace:
 () at phar:///usr/local/bin/composer/src/Composer/Command/SelfUpdateCommand.php:218
 Composer\Command\SelfUpdateCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:843
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:251
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:59
 require() at /usr/local/bin/composer:24

The names of hash functions in OpenSSL 1.1.1 (and above) are lowercase. In previous versions both lowercase and uppercase names were accepted. Composer versions prior to 1.7 (September 2018) expected a hash algorithm called ‘SHA384’, but ‘sha384’ can be received instead – and hence the bug in the self-update command.

Fix: Update composer manually by running
sudo wget https://getcomposer.org/download/1.8.0/composer.phar -O /usr/local/bin/composer && sudo chmod 755 /usr/local/bin/composer

Note that you can change 1.8.0 for the version of your choice.

Problem: issue with phpMyAdmin < 4.8.3

This is the same break/continue issue we’ve discussed before, but this time it affects phpMyAdmin. Some of our customers install phpMyAdmin via Moss to help them manage the databases of their applications. Before upgrading phpMyAdmin to PHP 7.3, just check you have v4.8.3 (August 2018) or later.

Fix: Upgrade phpMyAdmin.

Conclusion

If you want to avoid any pitfall when upgrading to PHP 7.3, just review this short article and you should be ready to go! The process should be mostly painless, especially if you count on the appropriate tools ☺️

Don’t miss a post! Subscribe to the Moss Blog