About Jamie on Software

Jamie on Software is the online journal of web developer and writer Jamie Rumbelow.

Jamie likes books, guitars, programming, open source and food. He writes about these things too. This is where he puts the things he writes.

My Books

Tags
Tweets
Feeds
We Love
Powered by Squarespace
Thursday
Oct042012

Using Composer on (gs)

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

PrintView Printer Friendly Version

EmailEmail Article to Friend

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

October 5, 2012 | Unregistered CommenterDrew at (mt) Media Temple

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

October 5, 2012 | Unregistered CommenterDrew at (mt) Media Temple

@Drew, thank you for the fix and the extra tip!

October 6, 2012 | Registered CommenterJamie Rumbelow

Thanks Jamie. This worked perfectly. Got ZF2 up and running on my (gs).

October 15, 2012 | Unregistered CommenterChris Rasco

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.phar

Should be:
curl -s https://getcomposer.org/installer | php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar

Without "composer.phar" at the end of the command.
Thanks for saving me hours of hairpulling!

--C

October 28, 2012 | Unregistered CommenterCasey

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

November 23, 2012 | Unregistered CommenterDavid Barratt

I contacted MediaTemple (mt) and I got this response:


As a courtesy, I examined this software, as well as your (gs) Grid-Service server. From what I can tell, it may simply not be possible to install this software in the shared hosting environment.

sad day. :(

thanks anyways.

November 24, 2012 | Unregistered CommenterDavid Barratt

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>