Starting Out with Laravel

In this post and three more to come, I will walk you through a very popular framework called Laravel which is the framework for the PHP programming language used for building wonderful web applications using simple, and expressive syntax. Laravel adapts fully the MVC design pattern which stands for Model, View, and Controller.

The official Laravel Philosophy: Quote from the official Laravel website states the goal of this framework.

“Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching.

Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality. Happy developers make the best code. To this end, we’ve attempted to combine the very best of what we have seen in other web frameworks, including frameworks implemented in other languages, such as Ruby on Rails, ASP.NET MVC, and Sinatra.

Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.”

Quick look at the license: Laravel is an open-source licensed under the MIT open source.

Who is the target for this post?

If you are new to Laravel and you want to learn this powerful framework whether it is your first or you already know other frameworks, then this post is for you.

The first post will focus only in getting you setup. So, I will walk you through the steps for installing Laravel.

Now before we jump into installing Laravel, there are few server requirements that you need to have setup first. However, Laravel has developed its own platform which satisfies all of the system requirements I was talking about in the previous sentence and that is the Laravel Homestead virtual machine. So, if you want to use Homestead, the link to install it can be found at the Laravel website: LaravelHomestead. Otherwise here are the components that you need to have ready before installing Laravel.

· PHP >= 5.6.4

· OpenSSL PHP Extension

· PDO PHP Extension

· Mbstring PHP Extension

· Tokenizer PHP Extension

· XML PHP Extension

To meet these server requirements, in my case I have installed the latest version of the Wamp server. So, if you don’t have Wamp server installed, then you would need to install it. The download page can be found at Wampserver.com and you just need to choose the version 32 or 64 bits depending on your system architecture.

WampServer version for Windows machines

Once you have downloaded WampServer, you just have to install it in your machine following the wizard. After the installation is completed, launch the server and if the installation was successful, by navigating to your localhost you should see this.

Wamp server screen after successful installation

After successfully installing WampServer and getting it up and running, there are few more things that you need to set if you are using a Windows machine. That’s the environment variable for your account if you want to use the command prompt. You need to copy the path of your php.exe which is located in the Wamp folder and edit the PATH variable by pasting your path separated by a semicolon to delimit with other paths already in there. Now you need to do the same thing for MySQL.

Once you have the path for PHP and MySQL set up, now you can test it in the command line by typing: PHP –v

Now that you have everything installed and set up, we can go ahead and installed Laravel. Laravel uses Composer to manage its dependencies. Therefore, before installing Laravel, we will need to install Composer and this is actually the file we will use to install Laravel in our machine. By navigating to Composer website, you will find this script that you can run in your command line. Make sure to download Composer in your Wamp folder. Here is the script you need to run:

php -r “copy(‘https://getcomposer.org/installer', ‘composer-setup.php’);”

php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) ===’55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”

php composer-setup.php

php -r “unlink(‘composer-setup.php’);”

As soon as you run the above script to the command line, if everything goes as expected, you will get something like :

Installation of Composer was successful

The next step is to install Laravel using Composer in the command line. You need to execute this command in the same location as where the Composer resides. So, it will be in the Wamp folder.

composer create-project --prefer-dist laravel/laravel test "5.2.*"

After running the above command, if the installation was successful, you should see something like the following:

Laravel installed successfully

Another way to install Laravel is via Laravel Installer. So, to do that, you need to download the Laravel installer from the command line using Composer. Here is the command you need to run:

Composer global require "laravel/installer"

In order for your system to locate the laravel executable, you need to include the ~/.composer/vendor/bin directory or the equivalent directory for your OS in your PATH. Once you have that set up, use the laravel new command to create a fresh new installation. For example, running the command:

Laravel new example

Will create a directory named example containing a fresh Laravel installation with all of Laravel’s dependencies already installed.

The next thing you need to do before you can start using Laravel, you need to configure your application’s document/web root to the public directory. Second thing, after installing Laravel, you might need to configure some permissions so that directories within the storage and the bootstrap/cache should be writable by your web server or Laravel will not run.

Alright, this wraps up the Laravel installation. For my next entry in this series, I will talk about Eloquent ORM which provides a simple ActiveRecord implementation for working with databases.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.