installing composer on a shared host

白昼怎懂夜的黑 提交于 2019-12-03 13:48:50

I resolved this by explicitly calling the version of PHP it asked for. Keep in mind that on a shared server environment there is often multiple versions of PHP running and even though you may have set up your default in your cPanel config, bash commands often resolve to another (lower) version.

First, I created a bin directory and moved composer.phar into it. Then, I added this alias to my .bash_profile and it worked like a charm:

alias composer="/usr/php/54/usr/bin/php-cli ~/bin/composer.phar"

Hope this helps!

As Composer is now available via WHM you can use this to find it:

which composer

This returned path "/opt/cpanel/composer/bin/composer" for me. If this returns nothing then disregard the rest of this answer, as Composer is not available to you at system level.

You can now use php-cli to call this with Composer's absolute path:

php-cli /opt/cpanel/composer/bin/composer install
php-cli /opt/cpanel/composer/bin/composer update
php-cli /opt/cpanel/composer/bin/composer require whatever/example

You may however need to alias php-cli if your system claims this isn't found. It very much depends how PHP has been deployed on the WHM server. You can do this by adding a user alias to the end of your ".bashrc" file as follows:

alias php-cli=/opt/cpanel/ea-php72/root/usr/bin/php

Replace ea-php72 with the release of PHP you want to use. Submit this as a command in the shell to make it available immediately, otherwise it'll become available when you open your next Bash session.

If you want to make this available with just composer alone you could create this alias again in ".bashrc":

alias composer=/opt/cpanel/ea-php72/root/usr/bin/php /opt/cpanel/composer/bin/composer

The location of the php versions installed will vary from host to host. Try finding them with:

locate /bin/php

For me this lists all php versions and I can then replace php with, for example:

/usr/bin/php71-cli

To access the command line interface version rather than the default cgi one. Then as stated by @Diggery you can create an alias.

alias composer='/usr/bin/php71-cli bin/composer.phar'

There are many suggestions on StackOverflow on how to test for a cli installation but the above is the only one that worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!