Installing PHP Composer

Composer installation is only possible when using automatic PHP settings management. In manual mode, you may encounter errors due to missing extensions. To learn how to switch site and web server modes, see the relevant instruction.

  1. Connect via SSH use your hosting service credentials. See the guide: How to connect via SSH protocol.
  2. Get the path to the root directory of your service via pwd command.
  3. Composer installation depends on the PHP version. Paths follow this format: /usr/local/php_version/bin. To view available PHP versions, run:

ls -lah /usr/local | grep php

Example: For PHP 8.0, the path is: /usr/local/php80/bin. Do not use the global (shared) PHP version — it may cause many errors. Instead, we recommend using the Multisite option.

  1. For easier installation, assign variables by running:

PHP_PATH=/usr/local/php80/bin
PHP=$PHP_PATH/php

Now you can use $PHP instead of typing the full path every time.

  1. Create a directory for Composer

mkdir -p bin

To go to the directory, use:

cd bin

  1. Download and install Composer:

curl -sS https://getcomposer.org/installer > composer-setup.php
cd ~
$PHP bin/composer-setup.php --install-dir=bin --filename=composer

  1. To run the selected PHP version and installed Composer simply with php and composer commands, create a .profile file and add:

echo "PATH=\"$PHP_PATH:\$PATH\"" >> ~/.profile
echo "alias composer='$PHP /home/h000000001/bin/composer'" >> ~/.profile

Where /home/h000000001 is the root directory path of your hosting service (from step 2).

  1. For correct execution of the composer command, run:

echo 'source ~/.profile' >> ~/.bashrc
source ~/.profile

  1. Verify Composer installation:

composer

  1. If Composer information is displayed, the installation was successful.

Всё ещё остались вопросы?