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:

  1. Log in to your account using SSH.

  2. 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.phar
    

    📘

    Note

    To confirm composer installed correctly, type the following command:

    ls -lh ~/bin/composer.phar
    

    The composer.phar file should be listed in the ~/bin directory.

  3. To create a helper script to run composer, type the following command:

    cat > ~/bin/composer << 'EOF'
    #!/bin/bash
    php $HOME/bin/composer.phar "$@"
    EOF
    
  4. To make the helper script executable, type the following command:

    chmod +x ~/bin/composer
    
  5. 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_profile
    

    📘

    Note

    • To confirm composer is configured correctly, type the following command from any directory:

      composer -V
      

      Composer 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.