Using composer on Gandi Simple Hosting

July 31, 2015

development production

_Update: Good news, you can now use composer natively on Gandi Simple Hosting with thier update to PHP 5.6._

TL;DR Install composer in ~/web/includes and set the config option cache-dir to ~/tmp/composer in your composer.json. Change to your htdocs directory and run ~/web/includes/composer install.

However, not having to think is sometimes a bonus

When it comes to web hosting I'm a fan of Digital Ocean, price, quality, support, community. All second to none.

However, not having to think is sometimes a bonus and for me that's where Gandi Simple Hosting comes in.

Simply choose the configuration you want; PHP, Node.js, or Python with the desired database MySQL, PostgreSQL or mongoDB. You get a container in the Gandi cloud with the environment all ready to go. Sites (apache vhosts) can be added in the Gandi services panel, but from here you're free to do as you please.

Great. Now I have a PHP/PostgreSQL instance, turn on SSH and I can login and git clone my repo fantastic, no … wait, how to install the dependancies? If you've been developing with PHP recently then you probably are making use of composer, unfortunately Gandi doesn't come with composer pre-installed, luckily it's pretty simple and there is just one gotcha I came across.

SSH into your instance, and cd ~/web/includes and install composer (you could put it anywhere writable but ~/web/includes was the most commonly accessible place I could find):

curl -sS | php

Next cd ~/web/vhosts/ edit your composer.json because here's the gotcha: set the config option cache-dir to somewhere writable, ~/tmp/composer for instance.

  "config": {
    "cache-dir": "~/tmp/composer"

That's it. ~/web/includes/composer install.


It's worth noting that in a lot of cases frameworks such as Laravel have a /public directory—this is good practice and keeps config files out of the public server. In this instance you should place your code in it's own directory next to htdocs. For instance, ~/web/vhosts/ the you should make htdocs a symbolic link to my-app/public. Take a look at my post on Absolute zero downtime deployment for an expansion on this idea.