composer install on cpanel server

To install and use Composer on a cPanel server, you need SSH or Terminal access. Because cPanel & WHM (version 130+) no longer bundles Composer by default, the exact steps depend on whether you have root/WHM access or standard shared cPanel user access. [1, 2, 3, 4]
Option 1: Standard cPanel User (Shared Hosting / No Root)
If you only have access to a single cPanel account, install Composer locally in your user directory: [1, 2]

  • Open the Terminal. Log in via SSH or open the Terminal icon inside your cPanel dashboard. [1, 2]

  • Download and run the installer. Run these commands one by one from your home directory (~): [1, 2]
    bash
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    
    Use code with caution.

  • Create a shortcut (alias). Since standard users cannot write to /usr/local/bin, create a local bin folder or add an alias to your .bashrc file so you can run composer from anywhere: [1, 2]
    bash
    mkdir -p ~/bin
    mv composer.phar ~/bin/composer
    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    
    Use code with caution.

  • Verify the installation:
    bash
    composer --version
    
    Use code with caution.


Option 2: Root / WHM Administrator (VPS or Dedicated Server)

If you have root SSH access, install Composer globally so all cPanel accounts on the server can use it: [1, 2]

  • Log in as root via SSH. [1]

  • Download and install Composer globally into /usr/local/bin (following the official cPanel Composer Installation Guide): [1]
    bash
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    php -r "unlink('composer-setup.php');"
    
    Use code with caution.

  • Update CageFS (CloudLinux servers only). If your server runs CloudLinux with CageFS, expose the binary to cPanel users: [1]
    bash
    echo -e "[composer]\ncomment=Composer\npaths=/usr/local/bin/composer" > /etc/cagefs/conf.d/composer.cfg
    cagefsctl --force-update
    
    Use code with caution.


Common Troubleshooting on cPanel

  • Running composer install on your project. Navigate to your project folder (e.g., cd ~/public_html/your-project) and run composer install.

  • Wrong PHP version error. If your project requires a specific PHP version (like PHP 8.2) that differs from the server default, call that specific EasyApache PHP binary directly:
    bash
    /opt/cpanel/ea-php82/root/usr/bin/php /usr/local/bin/composer install
    
    Use code with caution.

  • allow_url_fopen or phar errors. Ensure allow_url_fopen = On is enabled in cPanel’s MultiPHP INI Editor. If your server uses Suhosin, pass the whitelist flag when running commands: [1, 2, 3, 4]
    bash
    php -d allow_url_fopen=1 -d suhosin.executor.include.whitelist=phar $(which composer) install
    
    Use code with caution.

If you run into any issues or want specific commands, let me know:
  • Whether you have root/WHM access or a standard cPanel account
  • Your target PHP version
  • Any specific error messages you are seeing
I can give you the exact command string for your environment.

Similar Posts