hmpft_lolli
  • About
  • Art + Design
  • Má Praxe
  • Studies
  • Tech

Installing Composer in DreamHost

February 23, 2017CharlotteCode, Tech4 comments

Composer is a dependency manager for PHP. It is deployed as a PHAR (PHP Archive) file. Installing them on shared servers like DreamHost (DH) is easy. DH’s help website provides a lot of information, but segregated into different pages and may need some other tweaks to work.

In this tutorial, I will be using PHP version 5.6 as an example using SSH.

Configuring the environment and enabling phar extension in a phprc file.

  1. By default, phar files are not enabled in DH. To enable this we will need to create a phprc file (works like php.ini).

    /home/your_username/.php/5.6/phprc

  2. Make sure you are in your user home directory. You navigate to the home folder typing cd ~.
    Then check your current location by typing pwd. It should return something this:

    /home/your_username

  3. Create a folder for php version 5.6 by typing this command
    mkdir -p ~/.php/5.6
  4. Go to the folder you just created.
    cd .php/5.6
    Run a pwd command to check your location. And it should return something like this

    /home/your_username/.php/5.6

  5. In this folder, create a phprc file without extensions. Run this command
    nano phprc
    A nano text editor will pop up.
  6. Paste this code inside the editor.
    extension = phar.so
    suhosin.executor.include.whitelist = phar
  7. After pasting the code, press CTRL + X on your keyboard, you will be prompted to save. Type letter y and hit Enter to save the file.
  8. Check if your settings have been updated by typing this command, and it should output “phar”
    php -m | grep Phar
  9. If it doesn’t work, you may need to change the PHP version the shell uses. To do this, make sure you’re in the user home directory.
  10. We will need to edit the .bash_profile using nano, by entering this command.
    nano .bash_profile
  11. Paste this code to force PHP 5.6 to be used.
    export PATH=/usr/local/php56/bin:$PATH
  12. Run this command to update the .bash_profile
    . ~/.bash_profile
  13. Run php -v to check your PHP version.
  14. Try running php -m | grep Phar right now. This should respond with “phar”, and confirm that everything is setup for installing Composer.

Installing Composer (Globally)

In this tutorial, I would show how to install Composer Globally, so you may access it any folder you maybe in.

  1. Navigate to your home folder, by typing cd ~
  2. Create a directory for the composer installation.
    mkdir -p ~/.php/composer
  3. Navigate to the folder you created
    cd ~/.php/composer
  4. Run the code to install Composer
    curl -sS https://getcomposer.org/installer | php
  5. In your .bash_profile, add this new path for the composer.phar file. Change your_username with your shell username. Save and close the file.
    export PATH=/home/your_username/.php/composer:$PATH
  6. Update your .bash_profile by running this code
    . ~/.bash_profile
  7. Then add the following to your .bashrc by running this code.
    source .bash_profile
  8. If the installation is successful, rename the composer file
    mv ~/.php/composer/composer.phar ~/.php/composer/composer
  9. Viola! Done! You may run composer any folder you are in your SSH.
    composer composer-command 
Tags: code snippet, ssh, tutorial

Related Articles

How to zip a folder via SSH Terminal

June 20, 2016Huxley

4 comments. Leave new

Ram
November 14, 2017 10:57 am

Thanks, saved my day

Reply
Charlotte
November 14, 2017 11:07 am

You’re welcome! 🙂
I’m glad I was able to help.

Reply
victor
September 15, 2018 12:40 pm

impressive thanks

Reply
Charlotte
September 16, 2018 11:07 pm

You’re welcome. Glad to be of help!

Reply

Leave a Reply to victor Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Me

  • Facebook
  • Twitter
  • Linkedin
  • Dribble

About Hmpft!

Hmpft! is the personal blog of Charlotte Mae Efren. She is a freelance User Experience Designer and an Art Hobbyist currently residing in Cebu, Philippines.

She graduated both Master of Design and Master of Information Systems.

Disclaimer

The words and opinions expressed here are my own, and do not, in any way, represent the views of my universities and/or employer.

Images used in Má Praxe are copyrighted to their respective owners. Drawings derived from them are for practice and educational purposes only.

Copyright © 2020 Hmpft! Part of PixelMai.