How to install PHP composer

This article describes how to install and configure PHP composer, the dependency manager solution. 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 configure your shell environment to use composer, type the following commands:
    echo 'alias composer="php -d allow_url_fopen=On ${HOME}/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}/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 composer installer, type the following commands:

    cd ~
    curl -k -O https://getcomposer.org/installer
    
  4. To install composer, 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.

Get Composer Hosting

Article Details

  • Level: Intermediate

Related Articles

Show More

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.