Installing Composer PHP package manager

botond published 2018/06/24, v - 00:23 time

In this brief description, you will learn about Compose PHP package manager installation. This suite is not always needed, but in some cases you may not be able to avoid it. For example, I had to use it on this Drupal-based web site, so I installed it from the beginning, and since then I can effectively manage it, update this CMS system.

 

In this installation guide I have previously prepared perfect server i will install Composer so the next server version will already include this. Regardless, the Composer package can be installed on any Linux system that has the above PHP server, so she doesn't need any special background.

 

 

There are two ways to install Composer: In local mode, when the package manager is part of a project, it can only be used in the project directory, or it can be installed globally as an executable program available from the entire Linux system. I prefer the latter as it may be needed at any time eg. another website on the same server, so it makes more sense to deploy it centrally.

Composer from Debian 9 already includes a in official Debian repositories, and for Ubuntu, universe trunks. However, these packages are usually much older than the version downloaded from the creators, so here we now run the manual installation.

 

First, log in as root, then go to the / tmp directory, where you temporarily store the files:

sudo su
cd /tmp

Create a temporary directory, log in and then wget command to download the Composer a from the official site:

mkdir composer
cd composer
wget https://getcomposer.org/installer

This will give you a file called "installer". Install using php (since this is a php file):

php /tmp/composer/installer

The installer checks the required PHP conditions and then downloads an executable (also php) file with the .phar extension. Output:

Downloading...

Composer (version 1.6.5) successfully installed to: /tmp/composer/composer.phar
Use it: php composer.phar

From now on, you will be able to run the installation of various library dependencies with this file, but before that you need to place it in a place where you can access it from anywhere, such as / usr / local / bin:

mv /tmp/composer/composer.phar /usr/local/bin/composer

At the same time, we take down its extension so that it just needs to be run as a composer. So we have an ubiquitous (in PATH) executable file that any user can easily run.

If the file is still not executable, make it executable with the following command:

chmod +x /usr/local/bin/composer

Finally, delete the working directory:

cd /tmp
rm -rf composer/

To check the result, quit root and run composer as a regular user with a version check:

composer --version
Composer version 1.6.5 2018-05-04 11:44:59
The authors of the program strongly advise against running Composer as root, since third-party packages may pose a threat to the system. About this here is a description (in English) in the documentation.

Now you can see that Composer is very easy to install and you can now use it comfortably on any server for any project or website.