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 acomposer.lock) uploaded to the server, outsidepublic_htmlwhere possible.
Check Composer and PHP
composer --versionphp -vThe 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 installOn 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.phpphp composer-setup.php --install-dir=$HOME/bin --filename=composerrm composer-setup.phpThen run it as ~/bin/composer, or add export PATH=$HOME/bin:$PATH to ~/.bashrc.
Install dependencies for production
cd ~/apps/myprojectcomposer install --no-dev --optimize-autoloaderinstalluses the exact versions incomposer.lock, so production matches what you tested.--no-devskips testing and debugging packages.--optimize-autoloadermakes 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.
