VVV icon indicating copy to clipboard operation
VVV copied to clipboard

feat(php): Set PHP version per site

Open Mte90 opened this issue 3 years ago • 15 comments
trafficstars

Ref: https://github.com/Varying-Vagrant-Vagrants/VVV/issues/2367 Part of: https://github.com/Varying-Vagrant-Vagrants/varyingvagrantvagrants.org/pull/207

Checks

  • [x] I've updated the changelog.
  • [x] I've tested this PR
  • [x] This PR is for the develop branch not the stable branch.
  • [x] This PR is complete and ready for review.

Mte90 avatar Mar 04 '22 11:03 Mte90

Thanks for opening this pull request! Make sure CHANGELOG.md gets updated with this change, additionally any docs that need updated can be found at https://github.com/Varying-Vagrant-Vagrants/varyingvagrantvagrants.org

update-docs[bot] avatar Mar 04 '22 11:03 update-docs[bot]

It isn't yet ready, after the first on set the php version I get:

update-alternatives: error: alternative /usr/bin/php for php not registered; not setting

On it

Mte90 avatar Mar 04 '22 15:03 Mte90

Now seems working, now check also if the same version is already configured and avoid to set it again at the same version

Mte90 avatar Mar 04 '22 16:03 Mte90

I tested it and nothing crashed like in the CI

Mte90 avatar Apr 11 '22 13:04 Mte90

Fixed the linting and removed the example for nginx_upstream parameter in default-config.yml. Also if nginx_upstream is not set and php parameter is set use that value for nginx_upstream (I have to test it).

Mte90 avatar Jul 26 '22 09:07 Mte90

Fixed the issues you reported, I am not sure if I fixed the doc stuff.

Mte90 avatar Jul 26 '22 17:07 Mte90

Added a version validation that check if the string has a length different from 3. I am not sure if this way is the best one anyway (require some testing).

Mte90 avatar Aug 01 '22 12:08 Mte90

Things look good, I need to test before I can approve but I think this PR is the priority for releasing 3.10.1

tomjn avatar Aug 08 '22 13:08 tomjn

Looks like there are some CI issues finding functions in site templates:

    default:  * wordpress-one provisioner clone successful
    default: PHP Notice:  Undefined index: HTTP_HOST in /srv/www/wordpress-one/public_html/wp-includes/functions.php on line 6052
    default: Notice: Undefined index: HTTP_HOST in /srv/www/wordpress-one/public_html/wp-includes/functions.php on line 6052
    default:  * sourcing of vvv-init.sh reported success
    default:  * VVV is adding an Nginx config from /srv/www/wordpress-one/provision/vvv-nginx.conf
    default: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    default: nginx: configuration file /etc/nginx/nginx.conf test is successful
    default: /tmp/vagrant-shell: line 556: vvv_restore_php_default: command not found
    default:  ! The 'site-wordpress-one' provisioner ran into problems, the full log is available at '/var/log/provisioners/2022.08.01_12-27-27/provisioner-site-wordpress-one.log'. It completed in 17 seconds.

tomjn avatar Aug 08 '22 13:08 tomjn

I am not able to replicate your issue maybe in the PR the permissions on that file are wrong?

In the meantime I found another bug and fixed it.

I see the error on CI but it is very strange as I changed just the file content, maybe doesn't find our custom commands? As on develop there aren't errors.

Mte90 avatar Aug 23 '22 08:08 Mte90

Local tests failed with:

    default:  ✔ The 'site-wordpress-two' provisioner completed in 2 seconds.
==> default: Running provisioner: site-phpeight (shell)...
    default: Running: /var/folders/dw/wdtnsdn154db04ymxv90t9tm0000gn/T/vagrant-shell20220907-23209-1feiyc8.sh
    default:  ▷ Running the 'site-phpeight' provisioner...
    default: /tmp/vagrant-shell: line 51: vvv_warning: command not found
    default:  ! The 'site-phpeight' provisioner ran into problems, the full log is available at '/var/log/provisioners/2022.09.07_13-44-29/provisioner-site-phpeight.log'. It completed in 0 seconds.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

tomjn avatar Sep 07 '22 13:09 tomjn

Fixed a vvv_warning -> vvv_warn, though 8.0 is probably being interpreted as a number as it considers it the wrong format. We can't expect users to always wrap it in quotes so some string manipulation will be needed to format the value in the 0.0 format

tomjn avatar Sep 07 '22 13:09 tomjn

It's reporting a missing 8.0 as expected:

    default: Cloning into '/srv/www/phpeight'...
    default:  * phpeight provisioner clone successful
    default: PHP Notice:  Undefined index: HTTP_HOST in /srv/www/phpeight/public_html/wp-includes/functions.php on line 6052
    default: Notice: Undefined index: HTTP_HOST in /srv/www/phpeight/public_html/wp-includes/functions.php on line 6052
    default:  * sourcing of vvv-init.sh reported success
    default:  * VVV is adding an Nginx config from /srv/www/phpeight/provision/vvv-nginx.conf
    default:  * Upstream value 'php80' doesn't match a valid upstream. Defaulting to 'php'.
    default: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    default: nginx: configuration file /etc/nginx/nginx.conf test is successful
    default:  ✔ The 'site-phpeight' provisioner completed in 17 seconds.
==> default: Running provisioner: post-provision-script (shell)...

tomjn avatar Sep 07 '22 13:09 tomjn

I changed it to:

    length=$(echo "$DEFAULTPHP" | wc -c)
    if [[ $length > '3' ]]; then
      vvv_warn " ! Warning: PHP version defined is using a wrong format: '${DEFAULTPHP}' with length '${length}'"
    else

and got:

    default:  ▷ Running the 'site-phpeight' provisioner...
    default:  ! Warning: PHP version defined is using a wrong format: '8.0' with length '4'
    default:  * Pulling down the master branch of https://github.com/Varying-Vagrant-Vagrants/custom-site-template.git

Looks like there's a newline or terminating character that isn't being handled. Incrementing 3 to 4 leads to an unhandled error:

    default: Running: /var/folders/dw/wdtnsdn154db04ymxv90t9tm0000gn/T/vagrant-shell20220907-30221-7dsbtn.sh
    default:  ▷ Running the 'site-phpeight' provisioner...
    default:  ! The 'site-phpeight' provisioner ran into problems, the full log is available at '/var/log/provisioners/2022.09.07_13-50-27/provisioner-site-phpeight.log'. It completed in 0 seconds.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

tomjn avatar Sep 07 '22 13:09 tomjn

I added the removal of hidden breaklines but I wasn't able to find a way to validate a "version string" expect for the length.

Mte90 avatar Sep 13 '22 13:09 Mte90

@Mte90 would it make more sense to validate the presence of that version of PHP rather than the validity of the version string?

e.g. it doesn't matter if php : Octopus is a valid because there'll never be a phpOctupus nginx upstream or an octopus folder and CLI

tomjn avatar Sep 23 '22 12:09 tomjn

Well this simplify a lot but this means that they need to have already provisioned to be able to have that PHP version in VVV. Anyway is better of my fake solution.

Mte90 avatar Sep 26 '22 08:09 Mte90

@Mte90 extensions always provision before sites so it'll be installed beforehand, but if it is missing it'll just revert to default PHP

tomjn avatar Sep 26 '22 09:09 tomjn