VVV icon indicating copy to clipboard operation
VVV copied to clipboard

Ability to select PHP version used during site provisioning

Open spenserhale opened this issue 4 years ago • 10 comments

What was The Command Used To Provision

composer_setup

What Kind of VVV Provision Was This

This was a reprovision of an already working VVV

Logs/What Broke

Expected I set PHP74 version in site config, but provisioner ran an older PHP version. Log:

default:  ▷ Running the 'site-demo-sites' provisioner...
    default: Composer detected issues in your platform:
    default:
    default: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.34-13+ubuntu18.04.1+deb.sury.org+1.
    default:
    default: PHP Fatal error:  Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.34-13+ubuntu18.04.1+deb.sury.org+1. in /srv/www/demo-sites/public_html/vendor/composer/platform_check.php on line 24
    default: Error: Could not process the 'wp-config.php' transformation.
    default: Reason: Unable to locate placement anchor.

Config:

 demo-sites:
    nginx_upstream: php74
    hosts:
      - demosites.test
    db_name: demo-sites
    tideways: true
    custom:
      wp_type: subdirectory

utilities:
  core:
    - memcached-admin # Object cache management
    - opcache-status # opcache management
    - phpmyadmin # Web based database client
    - webgrind # PHP Debugging
    - tls-ca # SSL/TLS certificates
    - mongodb # needed for Tideways/XHGui
    - tideways # PHP profiling tool, also installs xhgui
    - wpcli-dev # Install a dev environment to use and contribute to WP-CLI
    - php # Install all the php utilities available automatically

Possible Solution

Have the set PHP version by nginx_upstream, to be used during its provision

Steps to Reproduce (for bugs)

  1. vagrant reload --provision

Your Environment

__ __ __ __
\ V\ V\ V / Varying Vagrant Vagrants
 \_/\_/\_/  v3.5.1-git::stable

Platform: platform-darwin19.2.0 shell:/bin/zsh vagrant-goodhosts vagrant-disksize shared_db_folder_disabled, VVV Path: "/Users/spenserhale/vagrant-local"
Vagrant: v2.2.14, VirtualBox: v6.1.18r142142

spenserhale avatar Feb 17 '21 23:02 spenserhale

Thanks for opening your first issue here! Be sure to follow the issue template and include your OS/Vagrant/VVV versions! Don't forget you can get support in the VVV slack at https://varyingvagrantvagrants.org/docs/en-US/slack/

VVV
Join the VVV Slack Workspace

welcome[bot] avatar Feb 17 '21 23:02 welcome[bot]

You can configure in the config file the php version: https://varyingvagrantvagrants.org/docs/en-US/adding-a-new-site/changing-php-version/

VVV
VVV supports the nginx_upstream option in the sites section of config/config.yml to set the PHP version.

Mte90 avatar Feb 18 '21 09:02 Mte90

@Mte90 original reporter knows about the upstream and was using it for their site. But this isn't which version the site runs, it's which version the provisioner runs.

OP had configured the site to run PHP 7.4, however, composer failed because it needs PHP 7.3 or above. The provisioner and composer ran using VVV's default PHP which on the stable branch is v7.2

tomjn avatar Feb 18 '21 09:02 tomjn

I did some thinking last night about this:

  • it's possible a user may want different versions of PHP for their upstream and their provisioning
  • it would be nice to be able to specify a PHP version for the provisioner itself

Given there was a PR to replace repo: with provisioner_repo: to avoid a common mistake, what if instead we did this:

provisioner:
  repo: ....
  branch: ...
  php: ...

As an aside, the Ondrej PHP packages installl named commands for PHP versions, so php74 etc are available if you're making your own provisioners

tomjn avatar Feb 18 '21 09:02 tomjn

I think that the issue is based on the fact that we execute composer for xhgui on the default php version. So ideally we should have a folder for any php version of xhgui and change the loader to use the php version of the website.

Or we can create a command that let to switch the xhgui php version based on.

Mte90 avatar Feb 18 '21 10:02 Mte90

@Mte90 this isn't for xhgui/tideways, the OP has a custom site provisioner that installs things with composer, but the dependencies requires PHP 7.3+, and the default PHP in cli is 7.2

tomjn avatar Feb 18 '21 10:02 tomjn

Uh sorry I was confused. This is not part of https://github.com/Varying-Vagrant-Vagrants/VVV/issues/2309?

Mte90 avatar Feb 18 '21 10:02 Mte90

Nope this is its own thing :)

tomjn avatar Feb 18 '21 11:02 tomjn

My current thinking is this:

sites:
  wordpress-one:
    repo: https://github.com/Varying-Vagrant-Vagrants/custom-site-template.git
    php: 8.0
    hosts:
      - one.wordpress.test

This explicitly sets the PHP version to 8.0, and would replace most uses of nginx_upstream. We would also modify provision-site.sh to change the default version to the version specified before the site provisioner runs, then change it back.

This also gives us the information needed to check if the version is installed and if it isn't, install it. This solve the problem of which version of PHP a provisioner runs in while giving us useful information. The alternative is the brute force approach of changing the default version which falls apart the moment one site needs a different version of PHP from the others.

tomjn avatar Jan 21 '22 14:01 tomjn

PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.28. in /srv/www/boilerplate/public_html/wp-content/plugins/WordPress-Plugin-Boilerplate-Powered/plugin-name/vendor/composer/platform_check.php on line 24 This happens because a plugin require composer with php 8 but is not available in VVV and at the end the provisioner crash

I am working on this

Mte90 avatar Mar 04 '22 11:03 Mte90