I am using Shared Hosting Can I use Composer?
Why not!!! You could certainly plan using composer with your Shared Hosting and let Composer manage your dependencies.
What is Composer?
Composer is a dependency management tool that takes care of required dependencies for PHP applications.
How can it help me?
Composer would initially install and later update the dependencies required by your project. You need not install them manually or later update by replacing the existing installation.
Let’s understand this by an example:
- Installing Dependencies
Your project uses following dependencies
For using these dependencies just need to create a file named composer.json at the root of your project directory and run the composer install command. Composer would install these packages for you.
- Managing Other dependencies
Now, if vendor/package2 also requires ‘vendor/package4’ composer would automatically install ‘vendor/package4’ without an explicit declaration.
- Updating dependencies.
If there is an update for vendor/package, and you require to update to version 1.4 (as in above example). Just change the version to the required in the latest composer.json file and run the composer update command. Composer would update the dependency and other dependencies which it relies on.
Installing Composer on Shared Hosting
Composer could also be installed on a shared hosting(cPanel Server) for a hassle free dependency management of PHP applications.
- Shell SSH access : Navigate to cPanel and enable it, if supported by your hosting provider
- PHP v 5.2 or greater
Use the following commands to get composer:
Get composer.phar[bash]curl -sS https://getcomposer.org/installer | php[/bash]
If you are unable to the above command on your hosting, you could probably download composer.phar from the link below:
In both the cases place the ‘composer.phar’ file in the root of your hosting account.
Add an alias
Edit .bashrc file for your account and add the following[bash]alias composer='<path to php-cli> <path to composer>'[/bash]
e.g.[bash]alias composer=’/usr/local/php56/bin/php-cli ~/composer.phar'[/bash]
Restart your SSH session or type in the following command to reload your bashrc file[bash]source ~/.bashrc[/bash]
just type in composer for using it
This could be helpful in cases wherein you are working with PHP frameworks like Symfony or Applications like Magento 2.0