Installing Composer on Dreamhost

How to enable Phar and install Composer on Dreamhost.

This should work with PHP 5.4 as well, just swap out instances of 5.3 with 5.4 :)

Make PHP 5.3 default

At Dreamhost there are two php binaries. ‘php’, which is version 5.2, and ‘php-5.3′ which is 5.3. We need to use 5.3 and Phar/Composer gets confused if the version of the ‘php’ command isn’t actually version 5.3.

$ mkdir -p ~/bin
$ ln -s /usr/local/bin/php-5.3 ~/bin/php
$ echo "export PATH=~/bin/:\$PATH" >> ~/.bash_profile
$ echo "export PATH=~/bin/:\$PATH" >> ~/.bashrc

Here we make our own little bin directory and creates a symlink to ‘php-5.3′ called ‘php’. We then add this directory to the beginning of the path so this directory is searched first when you try to run ‘php’. So if you log in and out of the shell (to reload the .bash_profile), you should get 5.3 if you run php --version.

Enable Phar

$ mkdir -p ~/.php/5.3
$ echo "extension = phar.so" >> ~/.php/5.3/phprc
$ echo "suhosin.executor.include.whitelist = phar" >> ~/.php/5.3/phprc
$ php -m | grep Phar

Last step should output “Phar”, if it all worked. If not, try the php.ini-way instead in this guide (which is where I found how to do this in the first place, but found it a bit unclear. Especially the last suhosin stuff).

Install Composer

$ curl -s https://getcomposer.org/installer | php -- --install-dir=~/bin
$ chmod u+x ~/bin/composer.phar
$ composer.phar

That last step should then give you a bunch of info and no error messages. And Composer should be ready to go :)

  • Braunson Y

    Great, super handy, tx!

    • http://www.geekality.net/ Torleif Berger

      It is indeed!

  • Rafael Ortega Bueno

    Thanks!!!

  • http://twitter.com/designofseven Luca Bertaiola

    Is this still valid for php 5.4 on Dreamhost ?

    • http://www.geekality.net/ Torleif Berger

      Didn’t know they had made 5.4 available, but I assume so? Maybe switch to using PHP 5.4 instead though. Let me know how it works out :)

    • luglio7

      Yes it works with php5.4
      wohoo

      • http://www.geekality.net/ Torleif Berger

        Sweet! Thanks for letting me know :)

  • Lango

    Worked great. The only thing I had to change was in the last step with teh curl command, I couldn’t use ..install-dir=~/bin, I had to use the full directory. So …install-dir=/home/username/bin

  • Ziiweb

    I had to reboot the system to get the new version of php, after “php -v”.

    • http://www.geekality.net/ Torleif Berger

      Reboot? Should just be a path issue which might require relogging the shell. But good to hear you managed to get it to work anyways :)

  • ziiweb

    Thanks, insteof of “php — –install-dir=~/bin” I had to write “php — –install-dir=/home/me/bin”

  • Adam

    Great, thanks!

  • Pingback: Para lembrar mesmo: Como instalar no Dreamhost o composer/Laravel | Piadas que rolam pela net

  • Nico

    Thanks much!

  • kminek

    based on your info i put together small shell script to automate the process: https://github.com/kminek/dhcomposer :)

  • Andrew

    Worked great, but I too had to use the full path to my bin folder…composer returned this when I used the relative path:

    #!/usr/bin/env php
    All settings correct for using Composer
    The defined install dir (~/bin) does not exist.

  • John Horner

    No need to log out of the shell and log in again to reload your .bash_profile, just do “source .bash_profile” and it reloads.

    • http://www.geekality.net/ Torleif Berger

      That would work too. I should probably start doing that. Relogging just feels more… definite :p

  • glitchdata

    Worked beautifully. And for those of you looking to get Zend Framework 2 going, its a simple update.

    http://wiki.glitchdata.com/index.php?title=ZF2:_Skeleton