The inevitable with Sage 9
With Sage 10 being quite new, lots of older WordPress projects are still using Sage 9. Which is not a bad thing until you start to realize that the PHP train keeps rocking with a new version every year and unfortunately as well with a deprecated version each year.
This deprecated version of PHP is not an immediate risk for your website, it could be your hosting provider dropping support of a certain older PHP version on their servers for example.
So far the journey of updating PHP inside Sage 9 projects was a walk in the park with at most having to make minor changes inside your theme Composer files. This is about to change with the deprecation of PHP 7.4 making the first next available PHP version being 8.0 which unfortunately is not compatible together with Sage version 9.
The solution.
luckily for Roots stack developers there is another solution that makes Sage 9 compatible with PHP 8.0, the changes involved are:
Steps:
- Applying a patch to the latest version of 'roots/sage-lib' Composer package (version 9.0.9).
- Updating your composer.json file inside the theme folder to accommodate for PHP 8.0+.
- Testing.
- Done!
Step 1 - Downloading the package and applying the patch.
Download the latest version of the 'roots/sage-lib' Composer package from Roots's GitHub page, the contents of the package we are going to change slightly with a patch.
The main patch is actually an open Merge Request into the official Github Repository but has been marked as deprecated. This patch allows us to run the magical PHP 8 version in Sage 9!
Here is the patch that should be applied to the package you just downloaded. You can also download the code from the feature branch here: https://github.com/mcaskill/sage-lib/tree/feature/laravel-7
After the patch has been applied, we still want to upgrade the illuminate packages to at least version 8.12 as they are the earliest version that are stated to work with PHP 8.0, newer illuminate package versions havent been tested yet.
After finishing the version constraints you can ZIP or host the package on your own Composer package repository e.g the GitLab Composer Registry or via BitBucket or another solution.
Step 2 - Updating your theme composer file and including the new package.
Changing the theme composer.json file, change the Require statement of 'PHP' to at least 8.0.
Remove the roots/sage-installer package as we do not need it since the Sage theme is already installed and require your new version of the roots/sage-lib package inside the composer.json file.
If you're hosting the package yourself as stated above you can simply add your repo under 'repositories' and install your newly made package that way.
In case you're not hosting the package, there is a way of requiring the package as 'ZIP', that should be done as followed:
Note that the "require" and "autoload" are included since adding a package as ZIP changes the way Composer loads the package. To prevent issues with requiring the composer package as ZIP we have to include the 'require' and 'autoload' statements for the package to get recognized correctly.
Now all is settled and it is time to go onto testing!
Step 3 - Testing.
Finally our work is mostly done, remove your 'vendor' folder optionally delete your 'composer.lock' file and clear your composer cache. Then it is time to run:
composer install
And fingers crossed you've correctly managed to make your Sage 9 install work with PHP 8.0 ๐.
Step 4- Done!
Was this guide useful? Or do you have something to add? Let us know and mail us at info@lemone.com!
For more information about our drive, visit https://lemone.com/
Top comments (1)
Thank you for this. A couple questions:
Which
composer.json
are you updating, the one at the root or in the theme directory?Where do you put the zipped file. In the root? In the theme directory? In the vendor file? Do you need to specify the path?