Installing Composer overview

You must use a VPS in order to run Composer due to the amount of resources it requires.

Composer is a dependency management tool for PHP projects. It allows you to declare the libraries your project requires and installs/updates them for you.

It is deployed as a PHAR (PHP Archive) file. Some PHP projects are now suggesting that Composer be used to manage external libraries during installation. MediaWiki is one such example, stating in their installation instructions:

Enable the PHP phar extension in your phprc file

View the following articles for instructions on how to create a phprc file.

If the file already exists, view the following articles for instructions on how to update it (depending on if you're using an FTP client or SSH):

Once your create your phprc file, it will be located in the following directory on your web server (This example uses PHP 5.6):


Place the following lines into the phprc file:

extension = 
suhosin.executor.include.whitelist = phar

Save the file and close it. You can verify if the settings have updated by viewing a phpinfo.php file. You could also run the following command and confirm that it outputs "Phar":

[server]$ php -m | grep Phar

If you do not see the changes updating, view the following article for assistance:

Change the default PHP CLI your shell uses

If you wish to have your commands default to a specific version of PHP, view the following article:

This example uses PHP 5.6

Installing Composer

View the following link for further details:

Install Locally

Installing Composer locally is good if you only have one project to maintain.

  1. Log into your server via SSH.
  2. Navigate to your project directory.
    [server]$ cd ~/<path-to-your-project>
    Replace <path-to-your-project> with the path to your project. If the project directory is named "project" and it's on the domain "", the path would be "".
  3. Run the Composer installer.
    [server]$ curl -sS | php
    If that does not work, try this instead
    [server]$ php -r "readfile('');" | php
  4. If successful, you'll see the following message:
    #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /home/example_username/ 
    Use it: php composer.phar

    This downloads the 'composer.phar' file.

Install Globally

  1. Log into your server via SSH.
  2. Navigate to your home directory.
    [server]$ cd ~
  3. Make a directory for installation. You can choose any valid directory name, but these instructions will assume the directory "~/.php/composer".
    [server]$ mkdir -p ~/.php/composer
  4. Navigate to the installation directory.
    [server]$ cd ~/.php/composer
  5. Run the Composer installer.
    [server]$ curl -sS | php

    If that does not work, try this instead:

    [server]$ php -r "readfile('');" | php
  6. View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. Then add the following path for the composer.phar file.
    export PATH=/home/<username>/.php/composer:$PATH
    Replace <username> with your shell username
  7. Save the file and close it.
  8. Run the following to update your .bash_profile:
    [server]$ . ~/.bash_profile
  9. Rename the composer file for easier handling.
    [server]$ mv ~/.php/composer/composer.phar ~/.php/composer/composer

Using Composer

If you installed Composer locally, then you would invoke Composer like this while in the project directory:

[server]$ php composer.phar <composer-command>

If you installed Composer globally, you should be able to invoke Composer this way:

[server]$ composer <composer-command>

In either case, replace <composer-command> with the composer command you want to run. Composer commands can be found listed in the Composer documentation.


You may receive the following error when downloading Composer:

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The phar extension is missing.
Install it or recompile php without --disable-phar

This is either because you haven't updated your phprc file with the phar extension, or you're using the wrong version of PHP to download it. View the 'Configuring your environment' section above to fix this.

See also

Did this article answer your questions?

Article last updated PST.