Using Composer PHP on Shared Space
Asked Answered
I

7

8

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.

Isaacs answered 7/12, 2013 at 19:9 Comment(0)
A
5

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

php-cli composer.phar install
Audre answered 21/4, 2014 at 14:17 Comment(0)
C
4

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.

Carib answered 20/5, 2014 at 21:23 Comment(1)
I am having the same problem that you had. I followed your instructions at the link you mentioned, but when I get to creating an alias... I can't get it to work. I don't understand how you created the alias. If I try running that code nothing happensDuumvir
M
3

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.

Mesquite answered 7/12, 2013 at 20:26 Comment(2)
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.. This is quite good to know! As far as I now understand, one has to install XAMPP first and then Composer afterwords?Marriage
Composer requires PHP to be installed. You can use XAMPP or any other method you find to install PHP. Composer itself is basically just a download of the phar file - the install method described just makes sure that PHP settings are correct on your installation.Mesquite
S
2

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.

Septate answered 7/12, 2013 at 20:30 Comment(0)
S
2

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)

Shields answered 16/4, 2015 at 8:2 Comment(0)
F
0

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

Fastigiate answered 7/12, 2013 at 20:20 Comment(0)
I
0

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
Ipswich answered 3/10, 2016 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.