Forget XAMPP! Create a dev environment | Part 2 | Install composer
Tags: php, composer, apache2, environment
Published: 2020-08-07 17:46:52

In the first part, we installed our PHP runtime library.
Now that we can access it from terminal, we can move forward to install the most useful tool that is ever existed for PHP, and that is **Composer**

<img width="100px" src="https://getcomposer.org/img/logo-composer-transparent.png"/>

> Composer is the package manager for PHP. It's fairly complex, so it's would be wise to read the docs... ooor you could just use this cheatsheet for now: https://devhints.io/composer

# Prerequisities

### Linux

You have to enable some of the PHP extensions in order to download composer with the `copy` method.

On linux that is fairly easy.
```bash
$ sudo apt install php7.3-curl php7.3-openssl php7.3-mbstring
```

### Mac OS

You don't really need to do anything, if i recall correctly everything went smoothly without enabling anything at all.
But if something comes up, try to follow along the windows version.

### Windows

Now this is will be a little bit longer. If you've been following around this "tutorial" series then you will be able to find the `php.ini` configuration file.

If however you have your own runtime library, and you don't know where is it, the fastest way to figure it out is to enter this command in cmd ( or powershell )

```cmd
php --ini
```
If you're lucky, you will find a line saying `Loaded Configuration File` containing the route to your php.ini

> If you've got an error, that means that either php is not installed properly, or the path to it is not set amongst the envornmental variables on windows. If that is the case you should move back to my first tutorial in this series and try again.

In that file you have remove the `;` semicolon character at the beggining of these lines:

```
;extension=curl
;extension=openssl
;extension=mbstring
```

# Install

If you've done everything correctly now you should be able to install composer. Follow this link: https://getcomposer.org/download/

And copy&paste the 4 commands from the bordered box.

For global installation follow this guide: https://getcomposer.org/doc/00-intro.md#globally

The Mac and Linux versions are fairly easy, you just have to use this command:
```bash
$ mv composer.phar /usr/local/bin/composer
```

However, Windows is a little bit different. But we have a huge advantage if we installed php with chocolatey. Because the runtime folder is added to the PATH. So modifying the official composer guide, we will get to something like this

```cmd
C:\tools\php> echo @php "%~dp0composer.phar" %*>composer.bat
```

If you did everything right, by entering the following command: 
```
composer --version
```

You should see something like this:

```
Composer version 1.10.6 2020-05-06 10:28:10
```

GG boi, now you have composer installed

![#goodjob](https://media.giphy.com/media/3o7abKhOpu0NwenH3O/source.gif)

> Sidenote: There are some rare cases when a project is heavily relying on a specific composer version, thus it should have it's unique php archive. I'm not saying it's bad, but it's a good practice to have composer installed globally anyways.