Using Composer on (gs)
Thursday, October 4, 2012 at 2:36PM I love using MediaTemple for my simple sites. When I don't have complex hosting requirements, I know I can get my PHP applications up and running really quickly. Their support is great, their hosting fast and feature-rich and their prices competitive.
...but there's one problem. (gs), their shared hosting platform, has a limited PHP CLI binary. You can't configure it through a php.ini (see this tweet for more). This makes it impossible to use Composer. Since Composer is the future of PHP, this is quite worrying.
There is, however, a solution. We can use the -d flag to set the runtime config variables required to get Composer running.
Installing Composer:
curl -s https://getcomposer.org/installer | php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar
...and then to run composer.phar:
php -d memory_limit=512M -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar composer.phar
This is ugly, so let's clean it up. We'll add an alias to the bash profile:
$ vim ~/.profile
We'll alias get_composer to our install command and composer to our composer.phar file. This way we can set up new subdomains and such easily:
alias get_composer="curl -s https://getcomposer.org/installer | php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar"
alias composer="php -d memory_limit=512M -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar composer.phar"
Save, and reload the profile (this will be done automatically next login):
$ source ~/.profile
Now, we can use Composer to our hearts' content:
$ get_composer
All settings correct for using Composer
Downloading...
Composer successfully installed to: /blah/domains/efendibooks.com/composer.phar
Use it: php composer.phar
$ composer -V
Composer version cb2a0f4
composer,
mediatemple,
php 


Reader Comments (7)
Hey Jamie! Great article! Every now and then I get a tweet asking about setting up composer on a (gs) Grid-Service. The method you suggest here is very thoughtful and will no doubt help a lot of people. Keep up the excellent work and let us know if we can help you with anything, we're here 24/7 on the phone, chat or Twitter. :)
Drew J
(mt) Media Temple
@MediaTemple
Hey there! Awesome article!
Just a follow up to my last comment: We tried your method and had to add the following to the first code block:
-d suhosin.executor.include.whitelist=phar
Additionally, you can use your own php.ini file and then reference it with -c. So then once you have it set up, you can do something like this instead of using -d:
curl -s https://getcomposer.org/installer | php -c /home/[site#]/etc/php.ini
Thanks again for the awesome article :)
Drew J
(mt) Media Temple
@MediaTemple
@Drew, thank you for the fix and the extra tip!
Thanks Jamie. This worked perfectly. Got ZF2 up and running on my (gs).
This is great! One note -- there's a typo in the first shell command:
curl -s https://getcomposer.org/installer | php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar composer.pharShould be:
curl -s https://getcomposer.org/installer | php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=pharWithout "composer.phar" at the end of the command.
Thanks for saving me hours of hairpulling!
--C
When I run:
php -d memory_limit=512M -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar composer.phar install
I get this error:
[ErrorException]
Invalid argument supplied for foreach()
However, it works perfectly on localhost. Any ideas?
thanks!
david
I contacted MediaTemple (mt) and I got this response:
sad day. :(
thanks anyways.