Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing composer on a shared host

I am trying to install composer on my shared host for the first time.

When I run curl -sS https://getcomposer.org/installer | php I am getting a Composer successfully installed
User it: php composer.phar

when I run php composer.phar i am getting this warring error:

Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI

any ideas on how to fix this ? and why i am getting this error ? :(

when I run php -v i get this back

PHP 5.4.39 (cgi-fcgi) (built: Mar 25 2015 14:20:20)  
Copyright (c) 1997-2014 The PHP Group  
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies  
    with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies

Do I need to run this using CLI version if so how would i do this ?

Any help would be nice thank you.

like image 727
Stuart Compaan Avatar asked Apr 23 '15 05:04

Stuart Compaan


People also ask

Do I need to install composer on server?

yes, but it's not necessary to download vendors with composer install . you can move composer binary file to Server and move your vendor too, then place vendor folder on your project and use composer dump-autoload .

Can I use composer in Cpanel?

Your cPanel account must possess SSH access in order to use Composer.


2 Answers

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

Or

php-cli $(which composer) ...
like image 51
Adambean Avatar answered Oct 19 '22 01:10

Adambean


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!

like image 37
Diggery Avatar answered Oct 19 '22 01:10

Diggery