How to Install PHP Composer in cPanel Shared Hosting
Composer is a popular dependency manager for PHP, but many shared hosting environments don’t have it pre-installed. Thankfully, if you have SSH access in cPanel, you can set it up in your account without needing root permissions.
Here’s a quick guide.
Step 1: Access Your Hosting via SSH
First, log in to your hosting account through SSH.
You can connect to your hosting account in two ways:
- Using an SSH client with your SSH credentials:
ssh username@yourdomain.com
- Directly from cPanel using the built-in Terminal feature:
- Go to cPanel → Terminal and you’ll have SSH access in your browser instantly.
Step 2: Download Composer Installer
Use wget to grab the official Composer installer:
wget https://getcomposer.org/installer -O composer-setup.php
Step 3: Create a Local Bin Directory
This will store your Composer binary:
mkdir -p $HOME/bin
Step 4: Install Composer with allow_url_fopen Enabled
Some shared hosting environments disable allow_url_fopen by default, which Composer needs to download packages.
You can temporarily enable it with:
php -d allow_url_fopen=On composer-setup.php --install-dir=$HOME/bin --filename=composer
Step 5: Add Composer to Your Path
This ensures you can run composer from anywhere:
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Step 6: Verify the Installation
composer --version
You should see output like:
Composer version 2.x.x ...
Done!
You now have Composer installed on your shared hosting account and can manage PHP dependencies directly from your SSH terminal.
