cPanel

Use Composer for PHP packages on cPanel hosting

Run Composer on cPanel shared hosting: check it is available, pick the right PHP version, install and update dependencies, handle memory errors and deploy without dev packages.

IntermediatecPanel hosting2 min read

Composer is the standard package manager for PHP. Frameworks such as Laravel and Symfony, and many custom projects, need it to install their libraries into a vendor folder. On MdmHost cPanel hosting you can run Composer from Terminal or SSH.

Before you start

  • Shell access: cPanel Terminal or SSH with keys.
  • Your project with a composer.json (and ideally a composer.lock) uploaded to the server, outside public_html where possible.

Check Composer and PHP

composer --version
php -v

The PHP version on the command line can differ from your website's version. If your project needs a specific version, run Composer through that PHP binary:

/opt/cpanel/ea-php83/root/usr/bin/php /opt/cpanel/composer/bin/composer install

On CloudLinux alt-php the binary is /opt/alt/php83/usr/bin/php. Use which composer to find the Composer path on your server.

If Composer is not installed

Install a local copy in your home directory:

cd ~ && curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=$HOME/bin --filename=composer
rm composer-setup.php

Then run it as ~/bin/composer, or add export PATH=$HOME/bin:$PATH to ~/.bashrc.

Install dependencies for production

cd ~/apps/myproject
composer install --no-dev --optimize-autoloader
  • install uses the exact versions in composer.lock, so production matches what you tested.
  • --no-dev skips testing and debugging packages.
  • --optimize-autoloader makes class loading faster.

Use composer update only when you deliberately want newer versions, preferably on your own computer, then commit the new lock file.

Tip: If Composer struggles on the server, run composer install --no-dev on your computer with the same PHP version and upload the vendor folder. It is just files.

Missing PHP extensions

Composer stops with messages like "requires ext-intl". Enable the extension in Select PHP Version. The command-line PHP must have it too; check with php -m. Avoid --ignore-platform-reqs on production: the site may break at runtime.

Troubleshooting

  • "Allowed memory size exhausted": run php -d memory_limit=-1 $(which composer) install. If the process is killed, you hit the account memory limit; install locally and upload.
  • Killed or very slow: CloudLinux limits stopped the process; see resource usage.
  • Git authentication for private packages: add an SSH deploy key as in Git Version Control, or use a token in auth.json (never commit it).
  • Class not found after deploy: run composer dump-autoload -o.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.