How to run Composer on a shared hosting server
Hello my fellow humanoid,
Yes I know, Composer makes coding life very easy when developing PHP apps that depend on other awesome libraries. If you don't know this then you must be living under a rock. When it comes to deploying your app onto your hosting server you will simply repeat what you did on your localhost if you have access to SSH.
At the root of your project run the command below:
composer install #Add some more dependencies composer update
You can read a direct explanation about the differences between "install" and "update" here.
Now the real bummer :(
The problem begins when you realise your project will be hosted on a shared hosting platform where you will not have access to SSH to run bash commands.
You need a way to run bash commands on your shared hosting server so download PHPShell.
Extract files and upload into a folder (eg. myshell) on your server using the usual ftp ways.
Now, open the file config.php in your favourite text editor and set a username and password under [users].
Next, under [aliases] add an alias to PHP
php = "php -d suhosin.executor.include.whitelist=phar"
Save config changes and upload to the server.
Now open the shell through your browser. Eg: http://example.com/myshell/phpshell.php
Enter your username and password to move along.
To verify PHP, run the command below:
It should display the PHP version number. So go up to the main app root directory.
Now download composer into the root
curl -sS https://getcomposer.org/installer | php
Now you can install your app dependencies. The folder named mytempdir will be created and store composer's cached files.
COMPOSER_HOME="mytempdir/" php composer.phar install #or COMPOSER_HOME="mytempdir/" php composer.phar update
And you wait for composer to complete the task in the composer.json file.
You can execute the same script anytime you add new dependencies to your composer.json file.
With the help of PHPShell you can actually run most of the bash commands on your server.
Let me know if you hit a dead-end and I will be glad to assist you with it in the comments form below.
And if I missed any step or made some errors please let me know in the comments form below.