nstall Composer on cPanel Without Root Access nstall Composer on cPanel Without Root Access

Master Composer on cPanel Without Root Access: Quick Guide

Field-Ready Guide for PHP Developers on cPanel Hosting Without Root Access

🔍 Introduction

If you manage PHP projects on a cPanel server, you may have noticed that Composer, the PHP dependency manager, is not installed by default. This guide shows you how to check if it’s installed, install it locally, and use it effectively.

🧰 What is Composer?

Composer is a dependency management tool for PHP. It allows you to:

  • Automatically install the libraries required for your projects.
  • Easily manage package updates.
  • Ensure compatibility between different PHP versions and packages.

🧪 Check if Composer is Installed on cPanel

Connect via SSH and type:

which composer

Result:

  • ✅ If installed: shows the path (e.g., /home/youruser/composer)
  • ❌ If empty: Composer needs to be installed manually

🛠️ Install Composer Locally on cPanel

  1. Navigate to your home directory:
    cd /home/youruser
  2. Download the installation script:
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  3. Install Composer:
    php composer-setup.php --install-dir=/home/youruser --filename=composer
  4. Remove the script:
    php -r "unlink('composer-setup.php');"
  5. Verify the installation:
    /home/youruser/composer --version

🔗 Add Composer to the PATH

Current session:

export PATH=/home/youruser:$PATH

Permanent:

  1. Edit the .bashrc file:
    nano ~/.bashrc
  2. Add at the end:
    export PATH=/home/youruser:$PATH
  3. Reload the file:
    source ~/.bashrc

🚀 Use Composer in Your PHP Projects

  • Install dependencies:
    cd ~/my-project
    composer install
  • Update packages:
    composer update

📘 Conclusion

Installing Composer on cPanel is simple and does not require root access. Once installed locally and added to your PATH, you can manage PHP dependencies as if Composer were installed globally.

For more information, see the official Composer documentation.