Is there a way to use Sage 9 with PHP 8.1?

Hello guys,
I have to upgrade Php version from 7.4 to 8.1 on my project.
Unfortunately Sage 9 doesn’t seem to be compatible with php 8.1.
Some dependencies blocked the migration : illuminate/support for example.

Some of you did find a way to migrate your php version ?

Thanks a lot for your help !

Hi @Clementine_FERNANDEZ,

I upgraded a Sage 9-project just recently to work with PHP 8.1 so I can gladly share what worked for me:

Essentially you’d have to replace the sage-installer and sage-lib packages in the theme’s composer.json to use the forked variants that have been updated to work with PHP 8.x.

This is my composer-file:

{
  "name": "roots/sage",
  "type": "wordpress-theme",
  "license": "MIT",
  "description": "WordPress starter theme with a modern development workflow",
  "homepage": "https://roots.io/sage/",
  "authors": [
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    },
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "QWp6t",
      "email": "hi@qwp6t.me",
      "homepage": "https://github.com/qwp6t"
    }
  ],
  "keywords": ["wordpress"],
  "support": {
    "issues": "https://github.com/roots/sage/issues",
    "forum": "https://discourse.roots.io/"
  },
  "autoload": {
    "psr-4": {
      "App\\": "app/"
    }
  },
  "repositories": [
    { "type": "vcs", "url": "https://github.com/jeh5256/sage-installer" },
    { "type": "vcs", "url": "https://github.com/jeh5256/sage-lib" }
  ],
  "require": {
    "php": "^7.4|^8.0",
    "composer/installers": "^2.0",
    "soberwp/controller": "~2.1.0",
    "roots/sage-installer": "^2.0",
    "roots/sage-lib": "dev-master",
    "log1x/blade-svg-sage": "dev-chore/illuminate-8.x"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^2.8.0",
    "filp/whoops": "^2.12"
  },
  "scripts": {
    "test": ["phpcs"],
    "post-create-project-cmd": [
      "Roots\\Sage\\Installer\\ComposerScript::postCreateProject"
    ]
  }
}

Note that I reorder the packages slightly and referenced the log1x/blade-svg-sage which is optional but also needs an update to be compatible, thus listing this as well.

If I remember correctly the illuminate/support-package is listed as a dependency with another package so it can be safely omitted here.

Compare to Sage 9’s default composer.json.

Let me know if that works out for you!

4 Likes

Thanks a lot for your help @evance .
This solution doesn’t work for me, I still have issues when I run composer update :

Problem 1
    - Root composer.json requires roots/sage-installer ^2.0, found roots/sage-installer[dev-master, dev-tailwind-2-support, dev-bulma-scss-fix, dev-bootstrap-4.3.0, dev-bootstrap-4.3.1, 1.0.0, ..., 1.6.4] but it does not match the constraint.

Problem 2
    - Root composer.json requires roots/sage-lib dev-master -> satisfiable by roots/sage-lib[dev-master].
    - roots/sage-lib dev-master requires composer/installers ~1.0 -> found composer/installers[v1.0.0, ..., v1.12.0] but it conflicts with your root composer.json require (^2.0).
1 Like

Yes, because you didn’t change / add the necessary repositories – please review the complete composer.json I’ve posted and compare it to the Sage 9 default in order to spot all the changes.

Okay it’s clear now, thanks a lot !

1 Like

I used @evance’s composer example to update Sage 9 on php 8.1 but I encountered illuminate/filesystem/Filesystem errors.

Removing blade-svg-sage and installing illuminate/support resolved the issue for me.

% composer remove log1x/blade-svg-sage  
% composer require  illuminate/support
1 Like

The log1x/blade-svg-sage-package doesn’t exist with “dev-chore/illuminate-8.x” any more so instead the whole require-block should read:

"require": {
  "php": "^7.4|^8.0",
  "composer/installers": "^2.0",
  "soberwp/controller": "~2.1.0",
  "roots/sage-installer": "^2.0",
  "roots/sage-lib": "dev-master",
  "log1x/blade-svg-sage": "^3.0"
},

If you do not want / need to use log1x/blade-svg-sage then you have to composer require illuminate/support explicitely.

2 Likes