How to change the php version in Lando 8.1.2

This is my first question. I'm a beginner. I'm working in a wordpress project with sage. When I try to run the template, there is a mistake:

enter image description here

The composer version is ok, but Lando version is php7.4 and I need the php8.1 version.

I've tried to change the php version in lando.yml and then using the command lando rebuild but it doesn't work. I'm also working with manjaro. Any help will be welcome. Thanks!

2

4 Answers

For pantheon recipes:

I hope this saves someone as confused as I was some time. I changed my .lando file to 8.1 and rebuilt, then tried destroy & start. Both failed.

It turned out I had to go to pantheon.yml and change php version there also. I suppose that's a 'dependency' which holds lando back.

1

You could start with lando init

$ lando init ? From where should we get your app's codebase? remote git repo or archive ? Please enter the URL of the git repo or tar archive containing your application code https://wordpress.org/latest.tar.gz ? What recipe do you want to use? wordpress ? Where is your webroot relative to the init destination? wordpress ? What do you want to call this app? my-wordpress-app 

Then you get a .lando.yml where you need to specify the php version for the appserver.

# .lando.yml name: my-wordpress-app recipe: wordpress config: webroot: wordpress services: appserver: type: php:8.1 #add these lines 

You also might need to destroy and rebuild after making that php-change:

lando destroy -y && lando start 

Sources:

The error you see is because the environment you are in on that point is php 7.4. And in your composer.json you already have 8.2. The file which throws the error is auto generated when you did "composer install" and in your composer.json you had already upgraded php to 8.2 probably.

What I did in my Lando project is the following:

To be able to switch between 2 lando's with php 7.4 and 8.2 back and forth (like when switching git branches and sometimes work in 7.4 and sometimes 8.2) you need to change the name on top of the .lando.yml file. this makes new containers and also keeps your old php 7.4 containers to easily switch back

  • Stop the current running lando first

lando stop

  • Change the "name" on top of your .lando.yml file (Only necessary if you think you'll ever want to switch to 7.4 again)
# Old name name: my-project # Make sure the running lando has been stopped first, "lando stop" will look # for the current "name" to stop things # Change to: name: my-project-php-8-2 

Change everything which points to php 7.4 to 8.2

config: # Old php: '7.4' # Change to: php: '8.2' services: appserver: overrides: # Old image: my-project/php:7.4-apache-4 # Change to: image: my-project/php:8.2-apache-4 

Maybe there is a Dockerfile too

# Old FROM devwithlando/php:7.4-apache-4 # Change to: FROM devwithlando/php:8.2-apache-4 

If you want to search your whole project for occurrences of 7.4 you can use this regex:

[^0-9A-Za-z]7(|\.|-|_)4[^0-9A-Za-z]

I found other places which I needed to update php version like

  • composer.json
  • gitlab-ci.yml
  • Maybe you have more files which need the new php version?

If everything is updated correctly I would do this:

  • Throw away your vendor/ folder
  • One of these:
    OR lando start (which makes new containers because the Lando "name" changed)
    OR lando rebuild if you did not change your "name" on top of the .lando.yml file (Maybe you need destroy and start, not 100% sure)
  • Update your composer.json file and check if all bundles are able to use php 8.2
  • composer install (inside your lando with the new php 8.2 version)

An extra thing to take care is with changing the name of your database host

# Old: DB_HOST=database.myproject.internal # Change to new: DB_HOST=database.myprojectphp82.internal 

To use particular PHP version you can add in config - except using in

services: myservice: 

Example Wordpress lando.yml

name: testwordpress recipe: wordpress config: webroot: . php: 8.1 

For details on particular PHP version you can check lando official guide

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobm1raG6Fen6OoaawZaSkeqS0wKeenmWknbJuvMepZK%2Bdoqi2sLqMoqVmpJGjsbB5l2ZoZmo%3D