By btribble on
In moving a composerized dev Drupal 9 site to live on Siteground hosting, I have encountered the following error when trying to use any drush cmd:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.14". You are running 7.4.33. in /home/customer/www/xxx/public_html/vendor/composer/platform_check.php on line 24
The Drupal status page reports php 8.1.14. Running php -v reports php 8.1.14. The .htaccess includes: AddHandler application/x-httpd-php81 .php .php5 .php4 .php3
Using composer update works fine, but using any drush cmd throws the error.
Any help would be appreciated.
Comments
Drupal hacks for SiteGround hosting
Short version: They don't support it, because their default PHP-CLI version is still
PHP 7.4server-wide, which reached end-of-life on Nov 23, 2022.Long version: They have other PHP versions available, but you need some hacks to get it to work, and they've already hacked their local
/usr/local/bin/drushscript to try and get it to work, but it doesn't with PHP8.1, unfortunately.However, I managed to hack it into working with the following steps:
First, install your own local version of Drush, as their installed one is only drush v8.3.5 and D9/10 wants a current version like 11.4.
ocomposer require drush/drushThen you need to edit your
vendor/drush/drush/drushscript and add the following line to the top of it to force it to run PHP 8.1:#!/usr/local/bin/php81Then edit your ~/.bash_profile script and add to the end of it:
PHP_BIN=php81export PHP_BIN
alias php=/usr/local/php81/bin/php
alias drush='~/www/YourDomain.com/vendor/drush/drush/drush'
alias composer='composer --ignore-platform-reqs'
then logout and log back in again or run
source ~/.bash_profileto load the aliases. This will remap yourphp,drush, andcomposerscripts to work the way you need it to.This should work until the
drush/drushcomposer package gets updated, and then you'll have to re-apply the first line to the script to get it to work again.SiteGround tech support has said in
Ticket 4363590(if you want to refer to it) that they have escalated this to management, but it will probably be weeks before anything gets changed. Considering their current installed versions of PHP and DRUSH, I don't expect much in the way of better Drupal support. Even though they plug Drupal as one of their supported platforms, I got this as one of the comments from tech support:So I wouldn't hold your breath on official support, but this should get you up and working!
Cheers,
- Brian
Fix for Siteground
Thanks a lot Brian, while this didn't correct the problem it got me headed in the right direction.
For others having this problem, this fix is specific to Siteground hosting.
Change line 1 of vendor/drush/drush/drush needs to be edited from: #!/usr/bin/env php to #!/usr/bin/env php81
Add to ~/.bashrc : alias drush="/usr/local/php81/bin/php-cli /home/<user>/www/<domain>/public_html/vendor/drush/drush/drush"
Change line 1 of vendor/bin/drush and changing #!/usr/bin/env php to #!/usr/bin/env php81
Thanks btribble!
I am on siteground, and finally found this post. One thing though, I really dislike having to change vendor/bin/drush top part to "#!/usr/bin/env php81" every time it updates. Anyway around this? Thanks!
I really dislike having to
You could create a patchfile, such as what is shown below, then apply it via cweagans/composer-patches:
SiteGround
In the process of upgrading from Drupal 9 to Drupal 10 using SiteGround, I ran into the same issues regarding the PHP versioning and the suggestions here proved to be insightful. To their credit, SiteGround's technical support people were extremely helpful.
Thank you
I made the changes except for --- Add to ~/.bashrc : alias drush="/usr/local/php81/bin/php-cli /home/<user>/www/<domain>/public_html/vendor/drush/drush/drush" ---
and it works properly now. Thank you
Composer PHP CLI
Thanks for all the suggestions - they are working just fine.
Despite having PHP8.1 running in the CLI (and for the server), I'm now seeing the following error on Siteground when trying to initiate Drush scripts:I have changed my site's composer.json."platform-check": falsebut that doesn't seem to have prevented these errorsEDIT: Had forgotten to tweak /vendor/bin/drush as in btribble's post.
I'm having the same issue
I'm having the same issue with SiteGround running PHP 8.1 on bash.
Setting up .bashrc makes sense, and it's logical.
alias php='/usr/local/bin/php81'
alias drush='/usr/local/bin/php81 -d memory_limit=2048M [directory path]/public_html/[project name]/vendor/drush/drush/drush.php'
alias composer='/usr/local/bin/php81 -d memory_limit=4096M /usr/local/bin/composer.phar'
However overriding /vendor/bin/drush with "#!/usr/local/bin/php81" feels wrong, even with a patch.
I'm starting to realize that SiteGround isn't an ideal choice for Drupal.
Optimised for Wordpress
I've raised this issue multiple times with SG, in the hope that they'll move away from [the insecure] PHP7 sooner. But I remember having similar conversations with many other hosts' tech support regarding PHP5 (feels like yesterday), and they did upgrade... eventually
I think most of their client base is using Wordpress and it feels like Drupal isn't really a priority. Most of the sites hosted by SG are probably still running PHP7, and SG will be using that metric to drive their upgrade path. However, among the cheaper end of the hosting marketplace, SG seems good value.
Not Restricted to a Specific Webhost
I ran into this issue myself on a few projects that use shared hosting. As others in this thread have related, it's most likely due to support of Wordpress, an assertion backed up by numerous blog posts and articles. It's also unnecessary, since anyone keeping a Wordpress site current would have no issues running on PHP8.x. It would be the same as if us Drupal practitioners were pushing hosts to run deprecated environments in order for us to keep obsolete sites up.
@diamondsea has a good workable solution, which should be able to be adapted to many situations. For host-specific needs, it's best reach out to tech support to find our their pathing to alternate PHP runtimes for the CLI.
Did anyone ever figure out a
Did anyone ever figure out a way to do this without hacking Drush?
shared hosting
This is one of the compromises of using a shared hosting environment.
I´m actually not using shared
I´m actually not using shared hosting but a virtual private server using ispconfig.
However I need to have multiple PHP versions installed with the default being 7.4.
I have the shell setup with PHP 8.1 for my Drupal 10 sites, and php -v shows 8.1. drush st also shows php 8.1.
But running drush updb will always use the system wide default, which is php 7.4. Most other drush commands work fine.
Never mind, I figured it out.
Never mind, I figured it out.
Because drush uses /usr/bin/env php you need to create a symlink named "php" to the php version you wish to use, and then include it in the shell PATH.
A Method That Doesn't Need Hacking
Agaric has an article on dealing with this issue—and I can vouch it works very well.
Essentially, any changes made to .bashrc, .bash_aliases, .bash_profile, .profile, etc. by themselves will have no effect on which PHP Drush uses. It requires a different approach to path to the PHP version you want it to run with. One way to set this up:
mkdir bin)ln -s /usr/bin/[your_php_verison] ~/bin/php. Make sure this matches what your provider offers.bin/php -venv-vars:PATH: /home/[your account]/bin:/usr/bin:/bin
Once this is up, test it by running
drush @alias st.Hope this helps!
change php version in command line
I have a Drupal site hosted by Siteground too.
I wanted to install a module that require php >8 with Terminal and SSH but the command
php -vsaid I was in php 7.4.33.But if you check in /usr/local/bin you note that there are stored also the other version of php
So I used the command
php81 /usr/local/bin/composer.pharrequire etc.. to install the module in php 8.1 (use php82 if you prefer 8.2 version)The php version choosed is used only for the single command.
The disadvantage is that from now on instead of just the
composercommand you will have to use always the extended one.Hope this can help you
My solution for SiteGround:
I posted my solution in a comment below.
Drupal 10 and SiteGround
I'm using SiteGround shared hosting and I was struggling with the error:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.33
Let me share the solution.
Here is my
.bashrc:(make sure to update the /home/
userto your username andexample.comto your site name)If you modify the .bashrc make sure to run:
Add this string to the end of the root Drupal dir
.htaccessfile:Also, adding this string helps after
composer updatecommand, becausecomposer updatereplaces the.htaccessand the site starts to show the error "Composer detected issues in your platform".If you are still facing the problem with
drush updbtryexample.com/update.phpinstead.few more steps for drush
First, thank you so much! I used your changes to .bashrc and then had to change the drush alias to:
(vendor directory was above public_html)
I have a staging site with its own vendor/drush directory, and had to take that into account:
alias drush="/usr/local/php81/bin/php-cli /home/user/www/staging.example.com/vendor/drush/drush/drush"I could have used 2 different aliases, one for each site, alternatively.
another option, set aliases to run specific flavors
Per the thread above - I used the commands and rather than set a drush or composer alias, I set my aliases to derivatives of drush and composer, that way I have the "system" siteground drush/composer for my drupal 7 site as I transition it to drupal 10.
My .bash_profile:
alias composer10='php83 /usr/local/bin/composer.phar'
alias drush10='/usr/local/php83/bin/php-cli ./vendor/drush/drush/drush'
10 being for drupal 10.
Drupal 11 and SiteGround
Thanks
I have a few sites in siteground running Drupal 10. I tried to upgrade to drupal 11 the other day following the instructions here https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-8-or-....
I hept getting this error:
Problem 1- drush/drush[13.0.0, ..., 13.6.0] require php >=8.2 -> your php version (8.1.32) does not satisfy that requirement.
- Root composer.json requires drush/drush ^13 -> satisfiable by drush/drush[13.0.0, ..., 13.6.0].
I was having the same problem as you were having.
After finding your solution and contacting Siteground help I modified your solution slightly for Drupal 11.
This worked for me:
alias composer="/usr/local/php83/bin/php-cli /home/customer/composer.phar"alias php="/usr/local/php83/bin/php-cli"
alias drush="/usr/local/php83/bin/php-cli /home/customer/www/example.com/public_html/vendor/drush/drush/drush"
Setting Drush version and path documentation page
Thanks to everyone for sharing solutions here! I recently looked at this task, and updated the Drush documentation page, with a lot of inspiration from this Forum post: https://www.drupal.org/docs/develop/development-tools/drush
I copy-pasted your awesome comment with a step-by-step set up for a symlink solution, which looks really interesting, so thanks for sharing it @karolus!
Thanks for updating the documentation
Thanks for updating the documentation.
But I'm not sure about the `hotel` here:
Sure, that may be a bit
Sure, that may be a bit outdated to use, and I updated it to web host.