How do I install Composer on a shared hosting?
Asked Answered
B

7

50

I have these things:

How can I install Composer? (My aim is to install Restler)

Edit: I do not have SSH access.

Bibulous answered 3/1, 2014 at 0:35 Comment(16)
I followed the instructions on Composers website. getcomposer.org/doc/00-intro.md#installation-nix. You will want to use a terminal to ssh into your host. I use BlueHost so in the CPANEL I had to tell it to allow remote ssh connections, then use PuTTY and connect to run the command lines.Cark
This question appears to be off-topic because it is about a specific web host.Abjuration
If you have shell access on your shared host (you will need it for composer to work) then you don't have to do anything except to save composer.phar somewhere and make it executable.Atory
@Rottingham, I didn't say that I have SSH.Bibulous
@DanielA.White, what? no, this is very common, most of the shared hosts do not have SSH.Bibulous
@MichaelBerkowski, I don't have shell access.Bibulous
@Bibulous If you don't have shell access you won't be able to use composer on that host. Instead you have to do it locally in development then upload your files with the populated vendor/ and composer.lock to the shared host (like Kevin says below)Atory
@dan, I have tried to extract composer.phar with 7-Zip, it was unable to extract the files. Then I have tried to run composer.phar by clicking on it, it didn't run, the browser tried to download the file.Bibulous
@Bibulous You do realize that a PHAR file is to be executed by the PHP interpreter? It should not be extracted and certainly not opened by a browser. As others have stated if you don't have shell access (ssh) then your only bet is to use composer locally and then copy over the vendor/ directory.Iridaceous
@user555, can't I do this with Cron jobs?Bibulous
@Bibulous Well you could, but then you would have to delete the cron job manually. Composer was designed to run from the shell. If I were you I'd stay away from trying to push a square peg into round hole. Just install composer locally and copy over the vendor/ dir, it will save you a lot of trouble.Iridaceous
@user555, I have just installed EasyPHP to the computer I use, then Git, and then Composer. There are missing DLLs. I have tried with XAMP but there I cannot start Apache, probably because I do not have admin rights.Bibulous
@Bibulous If you have trouble with your WAMP stack you better ask a new question describing your problems in detail.Iridaceous
It can be installed using a PHP script, see [this previous question][1]. [1]: #24531266Tillio
@Bibulous Did you solve it?Groundsheet
@Groundsheet I have used a web site where you enter a composer.json file and it installs all the dependencies and makes a zip file for you to download the result. But I don't remember what web site it was. Just google "online composer php".Bibulous
T
40

It depends on the host, but you probably simply can't (you can't on my shared host on Rackspace Cloud Sites - I asked them).

What you can do is set up an environment on your dev machine that roughly matches your shared host, and do all of your management through the command line locally. Then when everything is set (you've pulled in all the dependencies, updated, managed with git, etc.) you can "push" that to your shared host over (s)FTP.

Togs answered 3/1, 2014 at 0:40 Comment(5)
I'm having trouble installing some DDL files to EasyPHP and, and running XAMPP's Apache server. I might trie to install a Linux on Qemu. So I can install them there. What do you suggest?Bibulous
EasyPHP, XAMPP, and WampServer didn't work (because they want admin rights I think). UwAmp worked. In Windows 7 without admin rights.Bibulous
I've had issues all the various **MP servers on Windows. My brother likes XAMPP for that it's worth. I'm on OSX most of the times these days, and just started using Ampps. It's been pretty great so far, though I literally just installed it 2 days ago. :-)Togs
with this method if in future i require a new dependency will i be able to install that directly of will i have to follow this same setup again?Deneb
Yes. You'll always have to set up everything locally and push it live over FTP (and possibly clean things out manually, if packages are removed, etc.).Togs
H
53

This tutorial worked for me, resolving my issues with /usr/local/bin permission issues and php-cli (which composer requires, and may aliased differently on shared hosting).

First run these commands to download and install composer:

cd ~
mkdir bin
mkdir bin/composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar bin/composer

Determine the location of your php-cli (needed later on):

which php-cli

(If the above fails, use which php)

It should return the path, such as /usr/bin/php-cli, /usr/php/54/usr/bin/php-cli, etc.

edit ~/.bashrc and make sure this line is at the top, adding it if it is not:

[ -z "$PS1" ] && return

and then add this alias to the bottom (using the php-cli path that you determined earlier):

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

Finish with these commands:

source ~/.bashrc
composer --version
Herren answered 3/4, 2015 at 17:10 Comment(6)
Some shared hosting you might need these commands instead: DOWNLOAD: curl -sS https://getcomposer.org/installer | php55 -d suhosin.executor.include.whitelist=phar ALIAS: alias composer="php55 -d suhosin.executor.include.whitelist=phar ~/bin/composer.phar"Cento
If you don't have access to cUrl, you can download composer via wget. wget https://getcomposer.org/composer.pharDelinquency
I did not find the [ - z ... line to be necessary. Just needed to add the alias at the bottom.Olav
I had to rerun "source ~/.bashrc" the next time I used SSH.Bizet
~/.bashrc didn't work for me but ~/.profile did. (IONOS Shared Hosting)Polycythemia
If which doesn't work for you, you can use whereis. I wasn't able to let it work with php, and php-cli was not found. However, when I used whereis php-cli, and I used that path, it workedEdrick
T
40

It depends on the host, but you probably simply can't (you can't on my shared host on Rackspace Cloud Sites - I asked them).

What you can do is set up an environment on your dev machine that roughly matches your shared host, and do all of your management through the command line locally. Then when everything is set (you've pulled in all the dependencies, updated, managed with git, etc.) you can "push" that to your shared host over (s)FTP.

Togs answered 3/1, 2014 at 0:40 Comment(5)
I'm having trouble installing some DDL files to EasyPHP and, and running XAMPP's Apache server. I might trie to install a Linux on Qemu. So I can install them there. What do you suggest?Bibulous
EasyPHP, XAMPP, and WampServer didn't work (because they want admin rights I think). UwAmp worked. In Windows 7 without admin rights.Bibulous
I've had issues all the various **MP servers on Windows. My brother likes XAMPP for that it's worth. I'm on OSX most of the times these days, and just started using Ampps. It's been pretty great so far, though I literally just installed it 2 days ago. :-)Togs
with this method if in future i require a new dependency will i be able to install that directly of will i have to follow this same setup again?Deneb
Yes. You'll always have to set up everything locally and push it live over FTP (and possibly clean things out manually, if packages are removed, etc.).Togs
O
28

I have successfully installed Composer (and Laravel) on my shared hosting with only FTP access:

  1. Download and install PHPShell on a shared hosting

  2. In PHPShell's config.php add a user and an alias:

    php = "php -d suhosin.executor.include.whitelist=phar"

  3. Log in to PHPShell and type: curl -sS https://getcomposer.org/installer | php

  4. When successfully installed, run Composer: php composer.phar

Ocher answered 9/10, 2014 at 11:33 Comment(7)
My shared hoster has proc_open disabled, is there a workaround for this?Although
Same here @ConquerorsHakiLam
Try popen(), exec(), shell_exec(), passthru() or system().Ocher
But how do you run the the commands if you have only ftp access like i do with 000webhostRochester
@IchHabsDrauf That's why you install PHPShell on your hosting using FTP and then run commands in it.Ocher
Does this solution still work even today? I tried it but fail to get Composer installed. Even though step 3 doesn't give an error, step 4 gives an error that it can't find composer.pharThanh
@Ocher you are awesome! this made my dayEmmittemmons
A
17

You can do it that way:

  • Create a directory where you want to install composer (let's say /home/your_username/composer)
  • Go to this directory - cd /home/your_username/composer
  • Then run the following command:

    php -r "readfile('https://getcomposer.org/installer');" | php

  • After that if you want to run composer, you can do it this way (in this caseyou must be in the composer's dir): php composer.phar

  • As a next step, you can do this:

    alias composer="/home/your_username/composer/composer.phar".

    And run commands like you do it normally: $ composer install

Hope that helps

Attaway answered 18/11, 2015 at 18:41 Comment(3)
some servers have a default bash file where you can put the aliasGiroux
I already know that, but don't know how it happens, couse I am not very good with bash. Thanks for your comment!Attaway
probably you will find a file call .bashrc outside the public folder and you can put the alias there. You need to restart the ssh console (close and open)Giroux
M
5

I was able to install composer on HostGator's shared hosting. Logged in to SSH with Putty, right after login you should be in your home directory, which is usually /home/username, where username is your username obviously. Then ran the curl command posted by @niutech above. This downloaded the composer to my home directory and it's now accessible and working well.

Mira answered 18/4, 2015 at 16:6 Comment(0)
S
5

SIMPLE SOLUTION (tested on Red Hat):

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

to use it: php composer.phar

SYSTEM WIDE SOLLUTION (tested on Red Hat):

run command: mv composer.phar /usr/local/bin/composer

to use it: composer update

now you can call composer from any directory.

Source: http://www.agix.com.au/install-composer-on-centosredhat/

Specification answered 24/5, 2016 at 14:51 Comment(1)
NB: if you move composer.phar to /usr/local/bin/composer, you rename composer.phar in composer. Then the command you have to run is composer and not composer.phar. I edited your post with the correction. However, this solution will probably not work in a shared hosting, as the user will not likely be able to move a file to a system folder.Nonsuch
B
-1

Most of the time you can't - depending on the host. You can contact the support team where your hosting is subscribed to, and if they confirmed that it is really not allowed, you can just set up the composer on your dev machine, and commit and push all dependencies to your live server using Git or whatever you prefer.

Byssinosis answered 12/7, 2016 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.