ddev icon indicating copy to clipboard operation
ddev copied to clipboard

"default PHP version" global config

Open tyler36 opened this issue 3 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe

This morning I was reviewing a Laravel-related PR.

I set up the Laravel project as describe in the docs.

ddev start
ddev composer create --prefer-dist laravel/laravel

I noticed it was downloading an older version of Laravel (8.83.1 instead of 9.2.0). This was because I was running composer inside the ddev container which defaults to php 7.4.

Describe the solution you'd like

I would like a global setting to control the PHP version for new projects. Eg.

preferred_php_version: "8.1"

If I create a new ddev project, this value should be used for "php_version" in .ddev/config.yml

Users would be able to keep new projects on older, or later, versions of PHP as they need.

Describe alternatives you've considered

No response

Additional context

Drupal 10 will be released in Dec 2022. Currently, that has a minimum PHP version of 8.0.2 although it may be bumped to 8.1. CraftCMS currently requires 8.0.2 with 8.1 recommened. Laravel is 8.0

Not sure when DDEV will change its default PHP version, but a global setting will prevent some support requests and give control back to the user.

Ideally, a global config like this could also be extended to preferred database type and version as well. We have a test server that runs PHP 7.2 and Postgres 10. PHP & database global settings would help me preconfig any new project to match this server out-of-the-box.

tyler36 avatar Jul 04 '22 03:07 tyler36

The default PHP version for Laravel is already 8.0, https://github.com/drud/ddev/blob/master/pkg/ddevapp/laravel.go#L51 - so if using https://ddev.readthedocs.io/en/latest/users/cli-usage/#laravel-quickstart you should have gotten 8.0. Is there something going wrong?

DDEV will change default to php 8.0 and mariadb 10.4 in the next major version, which maybe should be pretty soon.

Your idea of a global default_php_version is a good one though!

rfay avatar Jul 04 '22 13:07 rfay

Hmm ... not sure what is going on then

$ ddev --version
ddev version v1.19.3

$ php -v
PHP 7.2.34-32+ubuntu20.04.1+deb.sury.org+1
  • Config DDEV and accept all defaults
$ ddev config
...
Configuration complete. You may now run 'ddev start'. 
  • Check ddev config file: .ddev/config/yaml
$ cat ./.ddev/config.yaml| grep php_version
php_version: "7.4"
# php_version: "7.4"  # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"

OS: Ubuntu 20.04 via WSL2 on Win10

tyler36 avatar Jul 05 '22 00:07 tyler36

The php version default is set when the project is created. The default is currently 7.4, but if you are creating a project of type laravel, it goes to 8.0. So your project type may not be laravel, or perhaps it was created before the change, don't know. Once the php_version is set in config.yaml, then changing the project type won't override it.

$ mkdir junk
rfay@rfay-mbp-2021:~/workspace$ cd junk
rfay@rfay-mbp-2021:~/workspace/junk$ ddev config --project-type=laravel
Creating a new ddev project config in the current directory (/Users/rfay/workspace/junk)
Once completed, your configuration will be written to /Users/rfay/workspace/junk/.ddev/config.yaml

You have specified a project type of laravel but no project of that type is found in /Users/rfay/workspace/junk
Project type has no settings paths configured, so not creating settings file.
Configuration complete. You may now run 'ddev start'.
rfay@rfay-mbp-2021:~/workspace/junk$ ddev start
...
Don't forget to create the .env file with proper database settings
You can do it with this one-liner:
ddev exec "cat .env.example | sed  -E 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' > .env"
Read more on https://ddev.readthedocs.io/en/stable/users/cli-usage/#laravel-quickstart
Successfully started junk
Project can be reached at https://junk.ddev.site https://127.0.0.1:49170
rfay@rfay-mbp-2021:~/workspace/junk$ ddev php --version
PHP 8.0.18 (cli) (built: Apr 21 2022 10:49:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.18, Copyright (c), by Zend Technologies
rfay@rfay-mbp-2021:~/workspace/junk$

rfay avatar Jul 05 '22 03:07 rfay

Thanks for the update. That makes sense from a project point of view. I assume then, should the feature be added, that a global setting of 8.1 would:

  • ddev config --project-type=laravel -> 8.1 (currently 8.0)
  • ddev config -> 8.1 (currently 7.4)
  • ddev config --php-version 8.0 -> 8.0 (user specifically asked for this)

I know you working through the docs at the moment. Do the docs contain a table listing ddev php version vs project-type php versions?

tyler36 avatar Jul 05 '22 03:07 tyler36

Currently, and I imagine in the future, project types like Laravel and Drupal 9 have specific overrides, so don't get the default. So your comment points out the danger and difficulty. Those overrides would have to check and see if there was a competing request from a global.

So I think it would be difficult to implement what you're suggesting. For example, it would be impossible to do "the right thing" for project types like Drupal 6 or Magento 1, which require old versions of PHP.

No, there are no docs that I remember that cover defaults. It would be really hard to maintain, as these things change pretty regularly. (Drupal 9 and Laravel have already changed this year).

Mostly, people should set the php_version to what they think is appropriate for their project and not rely on the defaults, IMO. (And note that the defaults only matter at project creation time)

rfay avatar Jul 05 '22 04:07 rfay

Opened

  • https://github.com/drud/ddev/issues/3957

for the bumps that need to be done.

I don't really think that the suggestion described here is going to work due to the issues described in https://github.com/drud/ddev/issues/3953#issuecomment-1174596647

rfay avatar Jul 05 '22 20:07 rfay

If I'm not mistaken, this has all been resolved, the laravel default PHP version is set now and the default PHP version for all projects will be 8.1 in upcoming v1.22.0. Am I right @tyler36 ? If not, we'll reopen.

rfay avatar Jun 26 '23 21:06 rfay

All good. 😄

tyler36 avatar Jun 26 '23 23:06 tyler36