UnderHost
Knowledgebase Docs

Composer for PHP: install and manage packages on UnderHost

Use Composer, the PHP package manager, on UnderHost: install it on a VPS, run it on accounts with SSH, build vendor/ for shared hosting, match the server PHP version, and fix common errors.

On this page

Composer installs the PHP libraries your project depends on. You list them in composer.json, Composer downloads them into the vendor/ folder, and composer.lock records the exact versions so every install is the same. Laravel, Symfony and most modern PHP applications rely on it.

Where you can run Composer

ServiceRun Composer on the server?How
Cloud VPS and dedicated serversYes, with full root accessInstall it once for the whole server
Managed Business hostingYes, SSH access is includedRun it in your account over SSH
Shared hostingNo, shared plans do not include SSHRun it on your computer or in CI, then upload vendor/

Install Composer

First check whether it is already there:

terminal
composer --version
php -v

On a VPS or dedicated server (as root), install it for all users with the official installer. Check the installer's hash against the one on getcomposer.org/download first:

as root
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "echo hash_file('sha384', 'composer-setup.php'), PHP_EOL;"   # compare with getcomposer.org
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
composer --version

In a hosting account with SSH (no root), install it in your home folder instead:

as your account user
mkdir -p ~/bin
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

Everyday commands

CommandWhat it does
composer installInstalls the exact versions in composer.lock. Use it on servers.
composer require vendor/packageAdds a package and updates both files.
composer update vendor/packageUpdates one package within the limits in composer.json.
composer remove vendor/packageRemoves a package.
composer outdated --directLists packages with newer versions available.
composer auditChecks installed packages against known security advisories.
composer dump-autoload -oRebuilds the optimized class autoloader.

Commit composer.json and composer.lock to Git. Do not commit vendor/; it is rebuilt from the lock file.

Shared hosting: build, then upload

Shared plans include PHP and let you choose the PHP version, but not SSH. Run Composer on your computer or in a CI job, then upload the result.

  1. Match the server's PHP version

    Check the version set for your site in cPanel → Select PHP Version, then tell Composer to resolve packages for it, even if your computer runs a newer PHP:

on your computer
# set the target PHP version once (use your site's version)
composer config platform.php 8.3

# build production dependencies
composer install --no-dev --optimize-autoloader
  1. Upload the project

    Zip the project including vendor/, upload it with FTP or the cPanel File Manager, and extract it. Uploading one zip file is much faster than thousands of small files. See FTP vs SFTP.

  2. Keep the web root clean

    Where your framework allows it, point the domain at the project's public/ folder so vendor/ and config files are not reachable from the web.

Production installs

on the server
composer install --no-dev --optimize-autoloader --no-interaction
  • --no-dev skips development tools such as test frameworks.
  • --optimize-autoloader makes class loading faster.
  • Run Composer as the user that owns the site files, never as root inside a website folder.
  • Automate it in your deploy. See Deploy from Git.

Troubleshooting

"Allowed memory size exhausted": Composer needs more memory than the PHP command-line limit. Run COMPOSER_MEMORY_LIMIT=-1 composer install. On shared hosting, build locally instead.

"Your requirements could not be resolved" or "requires php >=": a package needs a newer PHP than you have. Raise the site's PHP version, or set platform.php to the server's version and pick package versions that support it.

"the requested PHP extension ... is missing": enable the extension in Select PHP Version → Extensions on cPanel, or install it on your VPS. See PHP Selector.

Class not found after upload: vendor/ is missing or incomplete. Upload it again as one zip, or run composer dump-autoload -o.

Site works locally but not on the server: the server runs an older PHP than your computer. Set platform.php as shown above and rebuild.

FAQ

Your site can use Composer packages, but you cannot run Composer on the server, because shared plans do not include SSH. Build vendor/ on your computer or in CI and upload it.
Usually no. Commit composer.json and composer.lock and rebuild vendor/ during deploy. On shared hosting you upload the built vendor/ folder, but it still does not need to be in the repository.
composer install. It installs exactly what you tested. Run composer update on your computer, test, then commit the new lock file.

Related: Deploy Laravel | Deploy Symfony | Deploy from Git | PHP Selector in cPanel

Was this article helpful?

Need a developer-friendly server?

Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.

Related articles

Back to Developer Tools