Using Composer PHP on Shared Space

2.7k Views Asked by At

I'm using Bluehost and do have access to SSH, thankfully. I've also set my PHP to 5.4 in the Control Panel settings. Now, here's the two big questions that I can't seem to grasp: how do I install Composer and furthermore, after installing Composer, how do I get the dependencies included?

In this case, I am attempting to use the official Tumblr PHP Library, which has dependencies -- all of which can be found on Packagist.

I've referred to this question in which the OP is using HostGator. I have attempted to install Composer in a similar fashion and have done so with seemingly successful results. The issue, however, is that I don't know where to install it on Bluehost so I now have Composer installed in several random places on the server simply because I don't know how to navigate to find where to put it in this shared space.

I know this is the issue (i.e. it's installed in the wrong place) because when I use the composer phar files and syntax to install the packages, I get errors saying the commands don't exist.

I really hate asking for hand-holding assistance, but if someone could walk me through the proper installation of Composer on a shared space and the proper installation of a Composer package from Packagist on the same shared space, it would be much appreciated. I've dug through the Composer documentation and can't seem to find a proper guide -- if one can even exist -- for this case. At this point, I'm wondering if it's going to be different for every web host.

7

There are 7 best solutions below

0
On

I think you should do something like this. In console

echo $PATH

Use one of these pathes

mv composer.phar {selected path}/composer
chmod +x {selected path}/composer

Now you can simply call composer everywhere

2
On

You should probably not use Composer on the remote host, but instead install it on the local machine that is used to upload your project to Bluehost. There you can manage all the stuff that is needed to fetch the dependencies, which might include having the ZIP extension enabled or having a ZIP program available, having GIT or Mercurial installed if you have to grab a version from a branch, and so on.

All these dependencies of using Composer might not be available on that remote host, and frankly: You really do not want to install these development tools on a production machine anyway, I think. Any software that potentially helps an attacker shouldn't be present if it can be avoided.

0
On

The issue, however, is that I don't know where to install it on Bluehost...

In order to fix this problem, you need to figure out where exactly your project folder is. Composer needs to be installed in that folder. If you have access to a UNIX shell, I recommend that you change your directory to that project folder

cd $_SERVER['DOCUMENT_ROOT']/project_folder/

Generally, your remote server will follow the same file directory tree as that on your local machine. However, if you are unsure as to how your file structure may be organized, you can always print working directory of your local machine:

pwd

After you have successfully located the correct file path on your shared space, simply install composer:

curl -sS https://getcomposer.org/installer | php

This will report back something like:

All settings correct for using Composer Downloading...

Composer successfully installed to: /var/www/my_project/composer.phar

Use it: php composer.phar

You now have access to your composer.phar in your project. Let me know if you need any further help.

1
On

When installing composer, the biggest problem I ran into was that Bluehost's command line php was 5.2 and composer needs 5.3+.

Fortunately, Bluehost does give you access to 5.4. You can find it at

/ramdisk/php/54/bin/php54-cli 

I ended up setting up an alias to call composer.phar using the above php command and it's worked great. You can see more details on how to install composer on bluehost.

0
On

One problem on Bluehost is that the php command on Bluehost does not execute php-cli. So I "bypass" that by having my own php script earlier in the PATH and then forwarding the arguments to php-cli. In the same process I made script named composer which calls php-cli composer.phar directly.

So, this setup has worked for me on Bluehost:

In ~/bin I have the composer.phar and two bash scripts called php and composer. In ~/.bash_profile I have prepended ~/bin to my PATH.

  • ~/bin/php looks as follows:

    #!/bin/bash
    php-cli "$@"
    
  • ~/bin/composerlooks as follows:

    #!/bin/bash
    php-cli ~/bin/composer.phar "$@"
    
  • And the additions to ~/.bash_profile are these:

    PATH=$HOME/bin:$PATH
    PATH=$PATH:$HOME/.composer/vendor/bin
    export PATH
    

    (I have also added ~/.composer/vendor/bin as can be seen, this is handy for global access for some composed applications (for me that is laravel)).

Remember to source ~/.bash_profile. (Or reconnect)

0
On

Once you install composer as mentioned by KLVTZ. In the bluehost environment, use the php-cli instead of php.

php-cli composer.phar install
0
On

If you have composer installed in your root directory (under public_html), might be something related to PHP version. As Bluehost when chosing PHP version "Be aware that this only modifies your ~/public_html/php.ini file. If you choose to use PHP 5.4, you'll want to make sure your crons use "/usr/php/54/usr/bin/php" instead, as otherwise it will use PHP 5.2."

So you can try with the command

/usr/php/54/usr/bin/php-cli composer.phar install