Learning Laravel: Composer and The Laravel Installer

Home / Coding / Learning Laravel: Composer and The Laravel Installer
Learning Laravel:  Composer and The Laravel Installer

I spent years writing Laravel code at UWM but you might have noticed that I almost never wrote anything on this blog about it.  I am hoping to address that here and now.  If you don’t already know, Laravel is a free, open-source PHP web framework, intended for the development of web applications following the model–view–controller architectural pattern.In this first post, we are going to touch on some of the fundamentals.  Specifically, we are going to go over how to install composer and the Laravel installer.  Composer or the Laravel installer can both be used to create a new laravel project.  It is up to you which one you want to use.

Composer

Composer is a dependency manager for PHP.  It allows you to define what dependencies your project has and quickly pull them in.  It’s very similar to Brew on your mac or NPM for your javascript apps.  You can pretty easily install Composer by copying the text at the top of the download page and pasting it into a terminal window.

It’s as easy as that.  If you then run php composer.phar, you can run composer.

You really want that composer.phar file to be globally available, though.  In order to do that, you can next run sudo mv composer.phar /usr/local/bin/composer.phar in your terminal.  Next, you will need to run nano ~/.bash_profile, add alias composer="/usr/local/bin/composer.phar" to your bash_profile, and then source ~/.bash_profile to specify the source for your bash_profile.  At this point, you should be able to run composer from any folder on your machine.

So, now that you have composer, you can run composer create-project laravel/laravel example-app to create a new laravel app.

When you run the command, it will create a new example-app folder.  If you cd example-app and php artisan serve, it will start the Artisan development server at http://localhost:8000.

The Laravel Installer

If you don’t want to use composer to create your Laravel app, you do have the option of the Laravel Installer.  The only thing is that you need to use composer to install the Laravel Installer, so one way or another, you are going to need composer.  You can install the Laravel installer by running composer global require laravel/installer.

Once it is installed, you can add the .composer/vendor/bin folder to /etc/paths and then you can run laravel new example-app from any folder on your machine (similarly to how you did it above with composer).

Now, it is just a matter of running cd example-app and php artisan serve like you did before.

 

So, is the Laravel installer or composer the superior method?  I would say that it just comes down to what works for you.  The Laravel installer has integrations with git and github that composer doesn’t have.  Those might be worth it to you.

Have any questions, comments, etc?  Please drop a comment, below.

 

[ Cover photo by Fotis Fotopoulos on Unsplash ]