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.
- 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
- 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
- Create a folder for php version 5.6 by typing this command
mkdir -p ~/.php/5.6
- 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
- In this folder, create a phprc file without extensions. Run this command
nano phprc
A nano text editor will pop up. - Paste this code inside the editor.
extension = phar.so
suhosin.executor.include.whitelist = phar - 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.
- Check if your settings have been updated by typing this command, and it should output “phar”
php -m | grep Phar
- 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.
- We will need to edit the .bash_profile using nano, by entering this command.
nano .bash_profile
- Paste this code to force PHP 5.6 to be used.
export PATH=/usr/local/php56/bin:$PATH
- Run this command to update the .bash_profile
. ~/.bash_profile
- Run php -v to check your PHP version.
- 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.
- Navigate to your home folder, by typing cd ~
- Create a directory for the composer installation.
mkdir -p ~/.php/composer
- Navigate to the folder you created
cd ~/.php/composer
- Run the code to install Composer
curl -sS https://getcomposer.org/installer | php
- 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
- Update your .bash_profile by running this code
. ~/.bash_profile
- Then add the following to your .bashrc by running this code.
source .bash_profile
- If the installation is successful, rename the composer file
mv ~/.php/composer/composer.phar ~/.php/composer/composer
- Viola! Done! You may run composer any folder you are in your SSH.
composer composer-command
4 comments. Leave new
Thanks, saved my day
You’re welcome! 🙂
I’m glad I was able to help.
impressive thanks
You’re welcome. Glad to be of help!