03 Nov

How to Install and Use Composer in cPanel Terminal

If you have Terminal access in cPanel but get an error like:

bash: composer: command not found

— don’t worry! You can easily install Composer locally for your own user account without needing root access.


Step 1: Open the Terminal

Log in to your cPanel account and open the Terminal app from your dashboard.
If you don’t see it, your hosting provider might need to enable SSH or Terminal access for your account.


Step 2: Install Composer for your user

Run the following commands one by one:

mkdir -p ~/bin
cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=$HOME/bin --filename=composer
rm composer-setup.php
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

These commands will:

  • Download the Composer installer
  • Create a personal bin folder in your home directory
  • Install Composer there
  • Update your system path so you can run composer directly

Step 3: Verify the installation

Run:

composer -V

If the installation is successful, you’ll see something like:

Composer version 2.x.x

Step 4: Use Composer in your project

Go to the directory where your composer.json file is located. For example:

cd ~/public_html/myproject
composer install

Composer will download all dependencies and create a vendor/ folder automatically.


Optional: Run with a specific PHP version

If your hosting server runs multiple PHP versions (like PHP 8.1 or 8.2), use this format:

/opt/cpanel/ea-php82/root/usr/bin/php ~/bin/composer install

Just replace ea-php82 with your actual PHP version path (found under Select PHP Version in cPanel).


Done!

You’ve successfully installed Composer on your cPanel account and can now manage PHP packages or frameworks (like Laravel) directly from Terminal — just like a VPS or local setup.