Installing composer
Learn how to install and configure composer, a PHP dependency manager.
This article describes how to install and configure composer, the dependency manager solution for PHP. Composer enables you to manage dependencies for each project independently, and is used by frameworks such as Laravel.
Installing composer
To install composer, follow these steps:
-
Log in to your account using SSH.
-
To download and install composer, type the following commands:
cd ~ mkdir -p ~/bin wget https://getcomposer.org/installer -O composer-setup.php php ~/composer-setup.php --install-dir=$HOME/bin --filename=composer.pharNote
To confirm composer installed correctly, type the following command:
ls -lh ~/bin/composer.pharThe composer.phar file should be listed in the ~/bin directory.
-
To create a helper script to run composer, type the following command:
cat > ~/bin/composer << 'EOF' #!/bin/bash php $HOME/bin/composer.phar "$@" EOF -
To make the helper script executable, type the following command:
chmod +x ~/bin/composer -
To configure your shell environment so you can run composer from any directory, type the following commands:
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bash_profile source ~/.bash_profileNote
-
To confirm composer is configured correctly, type the following command from any directory:
composer -VComposer should display the version number.
-
In the future, to update the composer installation to the newest version, type the following command:
composer self-update
-
More information
For more information about PHP Composer, go to https://getcomposer.org.
Updated about 1 month ago
