Use Composer

composer, php, dependencies, vendor, autoload, ssh · 0 found this helpful

Composer installs the libraries a PHP project depends on, listed in composer.json. It writes them to a vendor folder.

Composer 2 is installed at /usr/local/bin/composer. You run it from SSH or the browser terminal in Developer. Both come with Business and Pro.

Check

Open SSH or the browser terminal:

composer --version

If it isn't found, install it for your user only:

cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=$HOME/bin --filename=composer
rm composer-setup.php
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Check the installer's signature on getcomposer.org if you want to be careful.

Use it

cd ~/public_html            # the folder with composer.json

composer install --no-dev --optimize-autoloader   # production install from composer.lock
composer require monolog/monolog                  # add a library
composer update monolog/monolog                   # update one library
composer outdated                                 # what's behind
composer dump-autoload -o                         # rebuild the autoloader

Commit composer.json and composer.lock. Use composer install on the server so versions match your computer.

Use the right PHP version

The command line uses the account default PHP version, not a site's own choice under Performance → Choose PHP for each site. Check:

php -v

To run Composer under a specific version:

/opt/alt/php83/usr/bin/php /usr/local/bin/composer install --no-dev

Replace php83 with the version you need, such as php82. See Change PHP version and extensions.

Out-of-memory errors

CloudLinux caps memory. If Composer is killed:

COMPOSER_MEMORY_LIMIT=-1 composer install --no-dev

Or run composer install on your computer and upload vendor. That uses your computer's memory, so the server limit doesn't apply. See Resource limits explained.

With Git deployment

Add Composer to your deploy tasks. See Automatic deployment from Git. Don't commit vendor unless you have no shell access.

Keep vendor private

If vendor is inside public_html, block it:

# Deny web access to vendor and Composer files
RedirectMatch 404 /\.git
<FilesMatch "^(composer\.(json|lock)|\.env)$">
  Require all denied
</FilesMatch>

Better, keep the project outside public_html and point only the web root at public/.

If something goes wrong

Problem Fix
Your PHP version does not satisfy Switch version or use the binary path
Allowed memory size exhausted Use COMPOSER_MEMORY_LIMIT=-1
ext-xxx is missing Turn the extension on under Performance → Extensions. See Change PHP version and extensions
Killed Hit a CloudLinux limit. Install on your computer instead

Was this helpful?

Still stuck? Ask us and we'll walk you through it.