While working on a project with Acquia Dev Desktop (ADD), we needed to run a specific version of PHP which is not included with ADD by default. We started hacking ADD and came up with our own solution. For those in a hurry, you can go directly to the solution.
This article would not have been possible without significant contributions from my colleague Benoit Borrel.
While working for one of our clients, we had to work with some tools which were a part of their workflow. Their websites were hosted on Acquia Cloud so they were using Acquia Dev Desktop (ADD) - Acquia's development stack and cloud client. This tool allows developers to "run and develop Drupal sites locally and to optionally sync them with Acquia Cloud".
At the time of writing this post ADD is was version 2.1 and it supported only up to PHP 7.0.14. At first, we thought it was good enough. But soon we discovered that the cloud servers were running more cutting-edge versions such as PHP 7.1.8.
The first issue came when we had to update our Composer packages. Running composer from different environments running different versions of PHP may result in each environment downloading a different version of the same package. A workaround is to always have the same environment run the composer update. However, we needed to ensure that the environment with the oldest version of PHP was able to run all the updated libraries. For example, the latest
doctrine/common libraries require PHP ~7.1, so using ADD 2 with PHP 7.0.14 we couldn't run it.
Another issue arose when we decided to update to Drupal 8.4.x. According to an issue on drupal.org, Drupal 8.4.x requires Drush 8.1.12+, but ADD 2 ships with Drush 8.1.10.
Facing such issues, we asked Google, "how to add a version of PHP to Acquia Dev Desktop?" No good results came up so we decided to start hacking ADD and ultimately found a solution.
Adding a specific version of PHP to Acquia Dev Desktop
Our solution worked on a Mac, but we believe it should work somewhat similarly on Windows.
Step 1: Install the required version of PHP
Install the desired PHP version with Brew, in our situation it was PHP 7.1.8_20:
$ brew install homebrew/php/php71
Step 2: Copy PHP files into Acquia Dev Desktop
Stop ADD if it's running and copy the PHP files into the Acquia Dev Desktop directories:
$ cp -r /usr/local/Cellar/php71/7.1.8_20/ /Applications/DevDesktop/php7_1 $ cp /usr/local/etc/php/7.1/php.ini /Applications/DevDesktop/php7_1/bin/php.ini
Note: We tried to create a symlink to prevent file duplication but it didn't work, so we ended simply copying the files into ADD, respecting its directories nomenclature and structure.
Step 3: Make Acquia Dev Desktop detect the new version of PHP
/Applications/DevDesktop/Acquia Dev Desktop.app/Contents/MacOS/static.ini and after the last contiguous line under
[php/4] add the following lines:
[php/5] id=php7_1 executablePath=php7_1/bin/php cgiExecutablePath=php7_1/bin/php-cgi configPath=/Applications/DevDesktop/php7_1/bin/php.ini
Note: If you are using Finder to navigate to the file, you may have to right click on the Acquia Dev Desktop application icon to see its content.
Step 4: Configure Acquia Dev Desktop
Open the ADD Preferences and select the Config tab. Now, in the Default PHP Version, select the one we just added. Make sure you select PHP mode Fast CGI and have PHP use the php.ini we previously copied into ADD in Step 2. Back in the ADD Preferences main window, in the left panel select the site you are working on, and then in Default PHP Version select the desired version. Then, click Ok and restart Apache.
Step 5: Configure Drush to use the same PHP version
To configure ADD's Drush to use the same PHP version, edit
/Applications/DevDesktop/tools/drush and replace the following:
# Before [ -z "$PHP_ID" ] && PHP_ID=php5_5 # After export PHP_ID="php7_1"
Step 6: Update Acquia Dev Desktop's version of Drush
To udpate Acquia Dev Desktop's Drush, edit
/Applications/DevDesktop/tools/composer.json and make the following change:
// Before "drush/drush": "8.1.10" // After "drush/drush": "^8.1.12"
Note: Drupal 8.4.x requires Drush 8.1.12+.
Now, in the terminal, go to the same directory as
composer.json and run this command to finish:
composer update --optimize-autoloader
Et voilà! We have just installed a custom version of PHP on Acquia Dev Desktop. Feel free to share your experiences in the comments below to help other fellow readers.