Composer is the dependency manager for PHP projects (Laravel, Symfony, WordPress packages, and more). You can install it inside your own cPanel account using the built-in Terminal — no SSH client, keys, or support ticket required.

Before you start: everything below runs in cPanel's built-in Terminal. It helps to know your account's PHP version first (cPanel → MultiPHP Manager) — Composer 2 needs PHP 7.2 or newer.

Step 1 — Open the Terminal in cPanel

Log in to cPanel and open Terminal (in the Advanced section, or type "Terminal" in the search box). Accept the one-time notice — I understand and want to proceed. A terminal opens, already logged in to your account; the prompt looks like username@server:~$. Run every command below there.

Step 2 — Download and install Composer

Paste this whole block. It creates a bin folder in your home directory, downloads the official installer, verifies it, and installs Composer.

mkdir -p ~/bin
cd ~

# download the installer and verify its signature (official source)
EXPECTED="$(php -r "copy('https://composer.github.io/installer.sig','php://stdout');")"
php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
php -r "echo (hash_file('sha384','composer-setup.php')==='$EXPECTED')?'installer OK'.PHP_EOL:'CHECKSUM MISMATCH'.PHP_EOL;"

# install Composer into ~/bin, then clean up
php composer-setup.php --install-dir="$HOME/bin" --filename=composer
rm -f composer-setup.php

You should see installer OK, then Composer (version 2.x.x) successfully installed. If you see CHECKSUM MISMATCH, don't continue — delete composer-setup.php and run the block again.

Step 3 — Make the composer command available

# add ~/bin to your PATH permanently, and for the current session
grep -q 'HOME/bin' ~/.bashrc || echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
export PATH="$HOME/bin:$PATH"

Step 4 — Confirm it works

composer --version

A line such as Composer version 2.8.x means you're done.

Using Composer

Run Composer from the folder that holds your project's composer.json:

cd ~/public_html/myapp        # go to your project
composer install             # install everything in composer.json
composer require guzzlehttp/guzzle   # add a package
composer update              # update packages
composer dump-autoload       # rebuild the autoloader

To use a specific PHP version, call Composer through that PHP binary:

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

Swap ea-php82 for the version you need. Update Composer itself with composer self-update.

Troubleshooting

  • composer: command not found — run source ~/.bashrc or reopen the Terminal. Fallback: full path ~/bin/composer.
  • Could not open input file: composer — check it exists with ls -l ~/bin/composer, then redo Step 3.
  • Cannot run on non-CLI SAPI — call a CLI PHP directly: /opt/cpanel/ea-php82/root/usr/bin/php ~/bin/composer ...
  • Allowed memory size exhaustedCOMPOSER_MEMORY_LIMIT=-1 composer update
  • CHECKSUM MISMATCHrm -f ~/composer-setup.php and repeat Step 2.

Note: Composer runs in the cPanel Terminal only — not the File Manager. Always use the official getcomposer.org installer shown here. Don't see Terminal in cPanel? Contact support to enable it.

Ця відповідь Вам допомогла? 0 Користувачі, які знайшли це корисним (0 Голосів)