Table of Contents

Composer and the Laravel Installer

Composer and the Laravel installer

A zombie developer manually moves files into their project, whereas a Laravel developer leverages composer to install tools and libraries.

Taking on the zombie developer apocalypse on your own would be almost impossible. Getting help from others is essential, and that's exactly what composer allows us to do. Composer is used to include libraries from other developers into our application.

Let's continue.


Composer & The Laravel Installer

How cool would it be if you could open up a command prompt and type in:

$ laravel new blog

And a Laravel app gets created inside a folder named "blog". Well, that's what the laravel installer does. So, let's learn how we can use this on our computer.

The Laravel installer, as well as many PHP packages, make use of a dependency manager called Composer (https://getcomposer.org) to add this functionality.

Composer

So, What exactly is a dependency manager? A dependency manager is a tool to manage your dependencies.

"WHAT!!!?", the definition sounds pretty weird, right? Maybe it would help if I explain how composer works with a "Pizza Analogy".

Let's pretend we could use a command to make us a pizza:

$ composer make pizza

Pizza

By default, we are given a pepperoni pizza. But let's say we wanted this command to make us a pizza with different toppings. Perhaps we wanted a meat-lovers pizza. We would probably need the following toppings:

{
    "toppings" : [
        "peperoni", "ham", "bacon", "beef", "sausage"
    ]
}

Now, if we save this file in our current directory and name it 'composer.json' and run the command again:

$ composer make pizza

DING! We now get our meat-lovers pizza instead of our pepperoni pizza.

Hazzzaa!

As you can see Composer is a way of managing the things we need to build our app (or pizza).

Composer is also a command line tool which can be used to install other tools, such as the laravel installer. So, before adding the laravel installer we need to install composer.


Installing Composer

Visit https://getcomposer.org/, click on the 'Getting Started' button. If you are on Windows you can click to download the installer and run through the .exe setup.

If you are on Mac you will need to click on 'Downloading the Composer Executable' and download the file. Then navigate to where you downloaded the installer file and run the following command:

$ php installer

Then to install composer globally you will need to run:

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

And now you will be able to run the composer command anywhere on your machine.

Adding the Laravel Installer

After installing Composer we are now ready to add the Laravel Installer. To do this we can simply run the following command:

$ composer global require "laravel/installer"

And now we can easily create a new laravel app by typing:

$ laravel new app_name

Then navigate to your new app_name folder in a command prompt. And run:

$ php artisan serve

Finally, navigate to http://localhost:8000/ in your browser and you will see a welcome 'Laravel' screen.

Now you're ready to start building your amazing app!

Warning: If the laravel installer does not globally work you may need to specify where the composer bin directory is located on your machine. Visit https://devdojo.com/articles/composer-bin-directory-path to learn how to do this.

How awesome is this?

With a single command, you can be up and running with a new Laravel app in a few seconds!

You can learn more about the Laravel installer at https://laravel.com/docs/installation#installing-laravel.