Install Composer on a Dreamhost VPS Instance
I have started to experiment with web development tools again and quickly ran into frameworks and tools which utilize Composer and there is mixed information on how to use composer with Dreamhost in a VPS environment, so I’m creating a blog post here. I’ll also add how to provision additional specific frameworks as we explore them as well.
- Through the Dreamhost console, verify which version of PHP you’re running.
- Domains > Manage Domain
- Look for the domain and you’ll see the PHP version, such as 5.6
- SSH into your VPS server
- The Phar extension for PHP must be enabled, do this by:
- verify you’re in the correct directory by typing “pwd”
- it should respond that you’re at /home/{{username}}
- Create a new directory “mkdir .php” – if you receive an error that it already exists, that is okay
- Move into that directory “cd .php”
- Now you’ll create a directory with the same name as your PHP version, in this case I’ll name it “mkdir 5.6”
- Move into that directory “cd 5.6”
- Now we’ll create (or edit) a file named phprc by typing “nano phprc”
- This will now have a full screen text editor, copy and paste the following into the editor:
extension = phar.so suhosin.executor.include.whitelist = phar
- To save changes you’ll press control-x, then Y, then {{enter}}
- You’ll be back at the command prompt.
- Test it by typing: “php -m | grep Phar” – the results should simply say “Phar”. If it just returns you to the command prompt without anything, then double-check your steps above.
- Enter the following to return back to your home directory: “cd ~”
- Now you’ll enter the website you want to use composer with, for example for my website www.sample.com you’ll enter “cd www.sample.com”
- Now you can install Composer here, or if necessary move into a subdirectory, if necessary.
- To install composer, simply type: “curl -sS https://getcomposer.org/installer | php”
Now to use it, whenever you are referred to use Composer, simply go into this directory and you’ll need to use the command “php composer.phar” followed by whatever you’ve been prompted to use composer for, such as:
- You’re instructed to use:
composer require twbs/bootstrap
- What you’ll type is:
php composer.phar require twbs/bootstrap
This is based on the assumption that you’ll only use Composer for one or two things, but if you’re a developer or will be using composer a lot of times, you’ll want to checkout how to make it available globally: https://help.dreamhost.com/hc/en-us/articles/214899037-Installing-Composer-overview
Note that about 90% of the information for this was based on that dreamhost.com hosted article, however how some finer elements were missing, and certain assumptions about using linux were made that not everyone will necessarily know. Additionally, the part about how to convert the composer call that most websites reference into the php composer.phar part is also missing.
Enjoy!
Hi there – thanks for the instructions. I’m struggling through this at the moment.
I am stuck here though:
To save changes you’ll press control-x, then Y, then {{enter}}
You’ll be back at the command prompt.
Test it by typing: “php -m | grep Phar” – the results should simply say “Phar”. If it just returns you to the command prompt without anything, then double-check your steps above.
I have triple checked everything above. and still nothing and composer won’t install:
“The phar extension is missing”
Is there anything else I am missing here?