linux - Tell Composer to use Different PHP Version - Stack Overflow

Ask questions Research chat →

https://stackoverflow.com/questions/32750250/tell-composer-to-use-different-php-version · scraped

deploy

Attachments

Scraped Content

— 282 words · 2026-02-14 02:58:34 UTC ·

Excerpt

I had the same issue and this is how I was able to figure out how to run composer using a different PHP version on a shared hosting without breaking the system :) Luckily, solving this issue with composer using different PHP version is dead simple. Findings: Default PHP was not run from /usr/local/bin or similar folder. Using the which php or whereis php would not give you the best answer. Follow the short guide below: First find the actual path to your composer binary itself. On my shared hosting server, it was at /opt/cpanel/composer/bin/composer I believe most hosting providers using cPanel would have such path to composer. Next, create an alias to the PHP version you want to use. In my project, I needed php 7.4 or newer. As mentioned earlier, the host was using cPanel and the actual default PHP version that the server uses is in the path /opt/cpanel/ You should see different versions of php in the /opt/cpanel/ (prefixed by ea-phpxx) for example, for php 7.4, it would be a folder
I had the same issue and this is how I was able to figure out how to run composer using a different PHP version on a shared hosting without breaking the system :) Luckily, solving this issue with composer using different PHP version is dead simple. Findings: Default PHP was not run from /usr/local/bin or similar folder. Using the which php or whereis php would not give you the best answer. Follow the short guide below: First find the actual path to your composer binary itself. On my shared hosting server, it was at /opt/cpanel/composer/bin/composer I believe most hosting providers using cPanel would have such path to composer. Next, create an alias to the PHP version you want to use. In my project, I needed php 7.4 or newer. As mentioned earlier, the host was using cPanel and the actual default PHP version that the server uses is in the path /opt/cpanel/ You should see different versions of php in the /opt/cpanel/ (prefixed by ea-phpxx) for example, for php 7.4, it would be a folder called ea-php74 and for PHP 8.0, it would be a folder called ea-php80. Now, be sure that php exists in a path similar to this: /opt/cpanel/ea-php80/root/usr/bin If you find php in the folder, then you can now alias it as folows: alias php='/opt/cpanel/ea-php80/root/usr/bin/php' Test that the alias is working by running php --version and check the php version as shown in the screenshot below: Now, run composer as normal. For example php /opt/cpanel/composer/bin/composer update php /opt/cpanel/composer/bin/composer install php /opt/cpanel/composer/bin/composer install Remember how we found the composer binary at /opt/cpanel/composer/bin/composer. If this does not match the path to the compser binary on your server, use the appropriate one.

Visibility

Visible to everyone

Reading Status

Related Bookmarks

My Note


Saved!

Annotations

Export as Markdown
+ Annotate selection

Add Annotation