Development and databases

Install PHP dependencies with Composer on your hosting

Reviewed on 4 min read composer dependencias

Composer installs the PHP libraries a project needs, based on composer.json. When composer.lock exists, it can reproduce the versions you have tested. It is available over SSH and in the cPanel terminal.

Check the environment

Open the terminal and run:

php -v
composer --version
php --ini

These commands show the command-line PHP, which is usually the general version selected in cPanel's PHP selector, with its modules, although it does not always match. If it is not your website's version, if the website has a different one set for its folder, or if a command needs another one, use the path to its binary, for Composer too: /opt/alt/php84/usr/bin/php "$(command -v composer)" install. Before installing, check the project's requirements and the extensions of the interpreter Composer will use.

If composer is not found, check command -v composer and ask support for the path available on your account. You do not need administrator privileges to manage the project's dependencies.

Install the tested versions

Work in the folder that contains composer.json and composer.lock, preferably in a new release or a test environment:

cd /home/usuario/apps/mi-proyecto &&
composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader &&
composer check-platform-reqs --no-dev

Replace the path with your project's. The example leaves out development dependencies for a production install; your test process may need them. If the lock file is missing, prepare and test one in development before deploying.

composer update resolves new versions and changes the lock file. Use it as part of the update process in development, review the change and test the application before publishing it. To install a release you have already tested, use install. See the difference between install and update.

Composer can run the project's scripts and plugins during installation. Use trusted code and check what operations they carry out; installing dependencies is not necessarily free of side effects on the application.

Fix a missing extension

A message like this means Composer's PHP is missing a required extension:

requires ext-zip * -> the requested PHP extension zip is missing from your system

Check the version with php -v and its modules with php -m. Enable zip for that same version in the PHP module selector, check again and repeat the installation.

If you need to run it with a different interpreter, use its absolute path together with a PHP installation of Composer whose path you have checked. Changing PHP in an .htaccess file does not change the interpreter used by that command.

Do not get around an unmet requirement with --ignore-platform-reqs: the installation might finish and the application then fail at runtime. If a system library is missing or the extension is not available, check compatibility with support.

Check the result

Check that Composer finishes without errors, that vendor/autoload.php exists and that check-platform-reqs validates the real environment. Then test the website and its scheduled tasks. This check is no substitute for functional tests and does not verify the web PHP if it differs from the terminal's.

If you hit a memory or disk space error, review your plan's resources and the size of the dependencies. You can prepare an artefact in a compatible environment, but you must check its requirements on the hosting before publishing it.

You may also find useful

Something wrong or out of date? Tell us and we will review it.