Archive

Archive for the ‘Web Development’ Category

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.

  1. Through the Dreamhost console, verify which version of PHP you’re running.
    1. Domains > Manage Domain
    2. Look for the domain and you’ll see the PHP version, such as 5.6
  2. SSH into your VPS server
  3. The Phar extension for PHP must be enabled, do this by:
    1. verify you’re in the correct directory by typing “pwd”
    2. it should respond that you’re at /home/{{username}}
    3. Create a new directory “mkdir .php” – if you receive an error that it already exists, that is okay
    4. Move into that directory “cd .php”
    5. Now you’ll create a directory with the same name as your PHP version, in this case I’ll name it “mkdir 5.6”
    6. Move into that directory “cd 5.6”
    7. Now we’ll create (or edit) a file named phprc by typing “nano phprc”
    8. 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
    9. To save changes you’ll press control-x, then Y, then {{enter}}
    10. You’ll be back at the command prompt.
    11. 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.
  4. Enter the following to return back to your home directory: “cd ~”
  5. Now you’ll enter the website you want to use composer with, for example for my website http://www.sample.com you’ll enter “cd http://www.sample.com”
  6. Now you can install Composer here, or if necessary move into a subdirectory, if necessary.
  7. 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!