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).
- 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:
- Create a folder for php version 5.6 by typing this command
mkdir -p ~/.php/5.6
- Go to the folder you just created.
Run a pwd command to check your location. And it should return something like this
- In this folder, create a phprc file without extensions. Run this command
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.
- Paste this code to force PHP 5.6 to be used.
- Run this command to update the .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
- 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.
- Update your .bash_profile by running this code
- Then add the following to your .bashrc by running this code.
- 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.