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
| Service | Run Composer on the server? | How |
|---|---|---|
| Cloud VPS and dedicated servers | Yes, with full root access | Install it once for the whole server |
| Managed Business hosting | Yes, SSH access is included | Run it in your account over SSH |
| Shared hosting | No, shared plans do not include SSH | Run it on your computer or in CI, then upload vendor/ |
Install Composer
First check whether it is already there:
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:
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:
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
| Command | What it does |
|---|---|
composer install | Installs the exact versions in composer.lock. Use it on servers. |
composer require vendor/package | Adds a package and updates both files. |
composer update vendor/package | Updates one package within the limits in composer.json. |
composer remove vendor/package | Removes a package. |
composer outdated --direct | Lists packages with newer versions available. |
composer audit | Checks installed packages against known security advisories. |
composer dump-autoload -o | Rebuilds 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.
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:
# 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
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.Keep the web root clean
Where your framework allows it, point the domain at the project's
public/folder sovendor/and config files are not reachable from the web.
Production installs
composer install --no-dev --optimize-autoloader --no-interaction
--no-devskips development tools such as test frameworks.--optimize-autoloadermakes 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
vendor/ on your computer or in CI and upload it.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
Need a developer-friendly server?
Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.





















