Knowledge Base

How to install composer

This article describes how to install and configure PHP Composer, the dependency manager solution. PHP Composer enables you to manage dependencies for each project independently, and is used by frameworks such as Laravel.

PHP Composer Install

To install Composer PHP, follow these steps:

  1. Log in to your account using SSH.
  2. To configure your shell environment to use PHP Composer, type the following commands. Replace username with your account username:
    echo 'alias composer="php -d allow_url_fopen=On /home/username/composer.phar"' >> ~/.bashrc
    source ~/.bashrc

    You can use composer with alternate PHP versions as well:

    • On an account that has CageFS enabled, all you need to do is select the PHP version in cPanel that you want to use. For information about how to do this, please see this article.
    • On an account that does not have CageFS enabled, you must manually specify the path to the PHP executable in the ~/.bashrc file. For example, if you want to run composer using PHP 5.5, type the following commands instead:
      echo 'alias php="/opt/php/php-5.5.0/bin/php"' >> ~/.bashrc
      echo 'alias composer="/opt/php/php-5.5.0/bin/php -d allow_url_fopen=On /home/username/composer.phar"' >> ~/.bashrc
      source ~/.bashrc

      For more information about how to use alternate PHP versions on A2 Hosting servers that do not use CageFS, please see this article.

  3. To download the PHP Composer installer, type the following commands:

    cd ~
    curl -k -O https://getcomposer.org/installer
    
  4. To install Composer PHP, type the following command:

    php -d allow_url_fopen=On installer
    • To confirm composer installed correctly, type the following command:
      composer -V

      Composer should display the version number. If it does not, repeat steps 2 to 4, paying close attention to the paths.

    • To update the composer installation to the newest version in the future, type the following command:

      composer self-update

More Information

For more information about PHP Composer, please visit https://getcomposer.org.