Composer is a dependency manager for PHP: it downloads and keeps track of the external libraries a PHP application needs (Laravel, Symfony, and many other modern PHP projects rely on it). If you're deploying a custom PHP application that comes with a composer.json file, you'll need Composer installed on your hosting account to run it. Here's how to get it working on shared hosting.
Before You Start
- You need SSH access enabled on your hosting account. If you haven't set this up yet, do that first: it's a one-time step in your control panel.
- You need a way to reach the shell: an SSH client (like a terminal app on your computer) or your control panel's built-in browser terminal.
- You should know which PHP version your project requires, since shared hosting often runs a different CLI PHP version than your website's default.
If you're not sure what SSH is or haven't turned it on, see the related article linked at the end of this page before continuing.
Step 1: Connect to Your Server
The connection step is the same whether your account is on cPanel or DirectAdmin: connect using your SSH client and your hosting account's SSH credentials, or open the browser-based terminal from your control panel. Once connected, you're in a normal Linux shell in your home directory.
Step 2: Download and Install Composer
- Make sure you're in your home directory by running cd ~.
- Download the official installer script:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - Run the installer to generate a local Composer file:
php composer-setup.php - This creates a file called composer.phar in your current folder. Remove the setup script, since you no longer need it:
php -r "unlink('composer-setup.php');" - Confirm it works:
php composer.phar --version
Because most shared hosting accounts don't give you permission to install software system-wide, keep composer.phar in your project folder (or your home directory) and call it directly with php composer.phar instead of a global composer command.
Step 3: Run Composer Commands for Your Project
- Move into your project's folder, the one containing its composer.json file.
- Install the dependencies it lists:
php /path/to/composer.phar install - To update dependencies to their latest allowed versions later:
php /path/to/composer.phar update
Shared hosting accounts often cap how much memory the PHP command line process can use, which can cause Composer to fail partway through with a memory error. If that happens, add -d memory_limit=-1 right after php in the command, for example: php -d memory_limit=-1 /path/to/composer.phar update.
Keeping Composer Updated
Composer itself gets updated separately from your project's dependencies. Run this occasionally to update the Composer tool:
php composer.phar self-update
A Note on Permissions
Everything above runs under your own hosting account's user, the same one your files already belong to, so there's no need for extra permissions and nothing here affects other accounts on the server. If a command fails with a permissions error, check that you're inside your own home directory and that the project folder is writable by your account.
If you haven't enabled SSH access yet, start there: see How to Enable and Use SSH Access on Your Hosting Account.