Skip to content

Multiple php versions on development servers

All the development servers on Dropsolid Platform use PHP-FPM to process the PHP scripts of your project.

There are some implications as a developer, you have to be aware of as there can be multiple PHP versions available on the development server of your project.

The CLI PHP version has to be specified in some cases

As there are multiple PHP versions on the server, drush/drupal console/composer/... has to be executed with the correct version to have the expected outcome.

Dropsolid infrastructure ensures the correct php version in the following situations:

  • The execution of the deploy script while building We did this by prefixing the $PATH variable with the specific PHP path for that environment:

    export PATH="/opt/php/7.1:$PATH"
    
    This way, all calls for the PHP binary will use the specified one.

  • A call executed through a drush alias on the live server (e.g. uli's from platform) we used the PHP option in the alias to specify the PHP path

    ...
    $aliases[$project . '.live'] = array(
        'root'                    => '/var/www/customprojects_D8/PROJECT/staging/docroot',
        'php' => '/opt/php/7.1/php', //ansible generated for staging, do not remove
        'path-aliases'            => array(
    ...
    

  • Drush cronjobs are automatically prefixed with the specific PHP path for that environment:
    DRUSH_PHP=/opt/php/7.3/php drush8 @PROJECT.ENV cron
    
    So for all the automatic or platform integrated parts, no manual actions are required.

When do you have to be aware of this?

  • If you use an ssh connection to execute (drush) commands, you still have to set the updated $PATH variable, as there is no way to predict the env you want to target with your commands.
  • Non-drush cronjobs won't be automatically prefixed with the correct PHP version, contact infra to update the DRUSH_PHP variable to the correct version, or update/set the DRUSH_PHP env var in your custom executed script.
  • When connecting from your local environment to the server with an outdated drush alias file.

    The best approach is to use an updated aliases file and a drush alias to execute drush commands, as it will use the correct PHP version.

    The possibility to get the alias files from the platform is on the roadmap, but for now the following command will sync the alias from the server to local.

    scp PROJECT@SERVER:.drush/PROJECT.aliases.drushrc.php etc/drush/PROJECT.aliases.drushrc.php
    
    Afterwards, every(*) drush command you execute from your local machine with the updated aliases will use the correct PHP version.

    (*) the drush @PROJECT.ENV ssh command which opens a shell in the project root on the remote server won’t be aware of the defined PHP version. You still have to set the updated $PATH variable, as it is unfortunately not possible to pass environment variables over ssh with drush.

The logs section per environment contains the FPM access / error logs

PHP errors will now be visible in the FPM log instead of the apache log.

Nice extra in the FPM access log is that you can see how long the PHP script ran and how much RAM and CPU processing it used.