Quick summary: Composer is the dependency manager for PHP projects. On cPanel, you must run Composer from the command line (Terminal or SSH) and have certain PHP extensions/options available. Depending on your hosting type, you can install Composer globally (requires root access) or locally in your project directory (recommended on shared hosting).

Before you begin — prerequisites

  • SSH access or access to the cPanel Terminal (cPanel → Home → Advanced → Terminal). If the Terminal option is disabled, ask your hosting provider. To find out how to access cPanel, see our internal guide: How to access my cPanel account.
  • If you install Composer for all accounts: root access root (VPS / dedicated server). On shared hosting: install Composer locally in your user directory (no root required).
  • Required PHP extensions: phar (usually available), and mbstring or iconv. Check/enable them via PHP Selector or MultiPHP (see: How to change the PHP version and extensions).
  • Useful PHP directives: allow_url_fopen = On and (for very old versions) zend.detect_unicode = Off. If you cannot modify php.ini, there are workarounds (see below).
  • On CloudLinux servers protected by CageFS: the administrator must expose the Composer binary to CageFS accounts (procedure shown below).
cPanel menu: Terminal icon to open the console
Open the Terminal from cPanel (Home > Advanced > Terminal) to run CLI commands.

Choose the method

Two approaches:

  1. Global installation (root) — the administrator installs Composer for all accounts (useful on VPS/dedicated).
  2. Local installation (without root) — install Composer in your user or project directory. Recommended on shared hosting.

Method A — Global installation (root administrator)

Procedure to make Composer available system-wide.

  1. Connect via SSH as root : ssh [email protected] (replace example.com and the user according to your configuration).
  2. Verify that the CLI version of PHP used by Composer provides phar and mbstring / iconv, and that allow_url_fopen is enabled. The administrator can adjust these options via the MultiPHP INI Editor or EasyApache 4 if necessary.
  3. Access to the MultiPHP INI Editor in cPanel to modify PHP options
    Example: MultiPHP INI editor to modify the PHP directives applied to the domain or to the CLI interface.
  4. Download and verify the official Composer installer, then install it into /usr/local/bin :
    cd /tmp
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    EXPECTED_SIG=$(php -r "echo trim(file_get_contents('https://composer.github.io/installer.sig'));")
    php -r "if (hash_file('sha384', 'composer-setup.php') === '$EXPECTED_SIG') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
    php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    rm composer-setup.php
    After installation, /usr/local/bin/composer must be executable. (If necessary: chmod +x /usr/local/bin/composer.)
  5. Verify the installation: composer --version.
  6. If the server uses CloudLinux + CageFS, expose Composer to CageFS accounts: create a configuration file and update CageFS (command executed as root):
    cat > /etc/cagefs/conf.d/composer.cfg <<'EOF'
    [composer]
    comment=Composer
    paths=/usr/local/bin/composer
    EOF
    cagefsctl --force-update
    This step makes the binary accessible to users jailed by CageFS.

Method B — Install Composer locally (no root) — recommended on shared hosting

Install Composer in your project directory or your home directory and run it as your cPanel user.

  1. Open the cPanel Terminal or connect via SSH using your cPanel account.
  2. Change to the project directory (e.g. ~/public_html/mon-projet ~/public_html/mon-projet) :
    cd ~/public_html/mon-projet
    cPanel Terminal showing the cd public_html command to access the web directory
    Change to the project root before installing dependencies.
  3. Download the installer and create composer.phar composer.phar in the current directory:
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    # Résultat : composer.phar dans le répertoire courant
    Run Composer locally with php composer.phar php composer.phar or create an alias (next step).
  4. To run Composer as a regular command, two simple options:
    1. Create an alias (temporary / for the current user):
      echo "alias composer='php ~/public_html/mon-projet/composer.phar'" >> ~/.bashrc
      source ~/.bashrc
    2. or move it and make it executable in ~/.local/bin ~/.local/bin or ~/bin ~/bin and add that directory to the PATH PATH :
      mkdir -p ~/bin
      mv composer.phar ~/bin/composer
      chmod +x ~/bin/composer
      # si nécessaire, ajoutez au PATH
      echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
      source ~/.bashrc

Run Composer when you cannot modify php.ini

If you do not have the ability to edit php.ini php.iniyou can force PHP directives on the command line:

php -d allow_url_fopen=1 -d zend.detect_unicode=0 composer.phar install
Note: zend.detect_unicode applies to very old PHP versions; on recent versions the directive no longer exists.

Useful commands

  • composer --version — displays the Composer version.
  • composer diagnose — self-diagnostic tool to detect configuration issues.
  • composer install — installs the dependencies listed in composer.json.
  • composer update — updates dependencies while respecting their constraints.
  • composer self-update — updates Composer itself (only for the copy you manage).
  • If you encounter a memory error:
    COMPOSER_MEMORY_LIMIT=-1 composer install

Troubleshooting — common errors and solutions

1) "command not found"

Cause: the binary composer is not in the PATH. Solutions:

  • If you installed it globally: check that /usr/local/bin is in the PATH or run it directly /usr/local/bin/composer --version.
  • If you have a local copy: add the folder containing composer (e.g. ~/bin) to the PATH in ~/.bashrc and source ~/.bashrc, or create an alias.

2) Warning "Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI"

Meaning: the PHP interpreter invoked by composer is the SAPI used by the web server (cgi/fcgi) rather than the CLI binary. Solution: explicitly invoke the PHP CLI binary. Example (replace the version):

/opt/cpanel/ea-php74/root/usr/bin/php ~/bin/composer diagnose
If your hosting provides multiple PHP builds via SCL, you can use scl enable ea-php74 'composer diagnose' (available only if SCL is installed).

3) Composer uses the wrong PHP version

Cause: php on the PATH points to another version. Solution: call the full CLI binary (absolute path) as shown above or adjust the alias to point to the correct CLI binary.

4) "Composer could not find a composer.json file"

Make sure you are in the folder containing composer.json (project root) before running composer install.

5) Write errors in vendor/ or permission denied

Check that you run Composer as the user who owns the web files (do not run Composer as root on a web project). Fix ownership if necessary:

chown -R votre_user:votre_user vendor/

6) CageFS (CloudLinux) related issues

If CageFS blocks access to the Composer binary, ask the administrator to add Composer to the CageFS configuration and run cagefsctl --force-update (see procedure above).

Best practices and security

  • Do not run composer install or composer update as root on a web project: some packages may run post-install scripts that execute with the same privileges.
  • For a production site: use composer install --no-dev --optimize-autoloader and keep composer.lock in your version control system to ensure reproducible dependencies.
  • If you automate installations (CI/CD), limit the risks with --no-plugins --no-scripts when necessary and verify the imported packages.

Useful internal links

Resources and references


Need help? If you prefer our team to perform the installation on a VPS/dedicated server or to check the CageFS configuration, open a ticket specifying the target PHP version and whether the server uses CloudLinux/CageFS. On shared hosting, a local installation in your project folder remains the recommended method.

Reference documentation

  • How to Set Up PHP Composer — cPanel & WHM Documentation
  • How to install composer on cPanel version 130 and higher — cPanel Support

Documentation consulted on October 17, 2026. Tools may vary depending on your hosting.