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 ...

Steps to Install Composer for All Users in CageFS

Step 1: Download Composer Installer

Use wget to grab the official Composer installer:

wget https://getcomposer.org/installer -O composer-setup.php

Step 2: Run the actual installer for Composer

php -d allow_url_fopen=On composer-setup.php

This will generate composer.phar file

Step 3: Move the composer utility into the /usr/local/bin directory and change permissions

mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Step 4: Update cagefs to allow composer

Create new config file

vi /etc/cagefs/conf.d/composer.cfg

[composer]
comment=Composer dependency manager
paths=/usr/local/bin/composer

Step 5: Update CageFS
Apply the changes to update the CageFS skeleton and all user jails:

cagefsctl --force-update


Done!
You now have Composer installed on your shared hosting account and can manage PHP dependencies directly from your SSH terminal.

Drop Your Comments Below