50

I have these things:

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

Edit: I do not have SSH access.

ilhan
  • 8,700
  • 35
  • 117
  • 201
  • 2
    I followed the instructions on Composers website. http://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. – Rottingham Jan 03 '14 at 00:37
  • 3
    This question appears to be off-topic because it is about a specific web host. – Daniel A. White Jan 03 '14 at 00:40
  • 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. – Michael Berkowski Jan 03 '14 at 00:40
  • @Rottingham, I didn't say that I have SSH. – ilhan Jan 03 '14 at 00:43
  • 4
    @DanielA.White, what? no, this is very common, most of the shared hosts do not have SSH. – ilhan Jan 03 '14 at 00:49
  • @MichaelBerkowski, I don't have shell access. – ilhan Jan 03 '14 at 00:49
  • @ilhan 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) – Michael Berkowski Jan 03 '14 at 00:51
  • @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. – ilhan Jan 03 '14 at 00:51
  • @ilhan 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. – user555 Jan 03 '14 at 01:12
  • @user555, can't I do this with Cron jobs? – ilhan Jan 03 '14 at 01:18
  • 1
    @ilhan 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. – user555 Jan 03 '14 at 01:32
  • @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. – ilhan Jan 03 '14 at 01:42
  • @ilhan If you have trouble with your WAMP stack you better ask a new question describing your problems in detail. – user555 Jan 03 '14 at 03:26
  • It can be installed using a PHP script, see [this previous question][1]. [1]: http://stackoverflow.com/questions/24530766/downloading-composer-via-php-script – Jodes Aug 10 '15 at 13:45
  • @ilhan Did you solve it? – Umair Sep 24 '19 at 10:33
  • 1
    @Umair 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". – ilhan Sep 24 '19 at 14:25

7 Answers7

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
Johnathan Elmore
  • 2,156
  • 1
  • 19
  • 25
  • 3
    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"` – Francisco Luz Aug 22 '15 at 13:09
  • 1
    If you don't have access to cUrl, you can download composer via wget. `wget https://getcomposer.org/composer.phar` – creg Nov 11 '17 at 16:46
  • I did not find the `[ - z ...` line to be necessary. Just needed to add the alias at the bottom. – Reed Sep 19 '18 at 12:10
  • I had to rerun "source ~/.bashrc" the next time I used SSH. – Eaweb May 10 '21 at 10:25
  • `~/.bashrc` didn't work for me but `~/.profile` did. (IONOS Shared Hosting) – Binozo Aug 23 '22 at 09:15
38

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.

Kevin Newman
  • 878
  • 9
  • 12
  • 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? – ilhan Jan 03 '14 at 01:49
  • EasyPHP, XAMPP, and WampServer didn't work (because they want admin rights I think). UwAmp worked. In Windows 7 without admin rights. – ilhan Jan 03 '14 at 02:42
  • 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. :-) – Kevin Newman Jan 06 '14 at 02:21
  • 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? – Abhishek Asthana Apr 18 '14 at 20:03
  • 1
    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.). – Kevin Newman Apr 18 '14 at 20:48
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

niutech
  • 28,923
  • 15
  • 96
  • 106
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

Nikolay Traykov
  • 1,537
  • 17
  • 26
6

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.

ZurabWeb
  • 1,241
  • 1
  • 12
  • 21
6

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/

Flo Schild
  • 5,104
  • 4
  • 40
  • 55
Dung
  • 19,199
  • 9
  • 59
  • 54
  • 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. – Flo Schild Aug 19 '16 at 07:52
0

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.

devphil
  • 21
  • 1