My name is Stefan Ashwell and when I'm not coding personal projects or painting miniatures, I'm a Software Engineer at Holmes Media in Market Harborough.

This blog is a place for me to write about things that require that little bit extra to solve. We all have gaps in our knowledge and every now and then I need to reach out on search engines or blogs to find an answer. Often, these answers come from multiple sources. This blog serves as a personal resource, but if it's helpful for me I'm sure it'll help others too!

Getting Started with Laravel

Posted on 22 June 2017

Laravel is a modern PHP framework for building web apps. Laravel ships with lots of features that will make your life as a developer easier. First off though, we’ll be getting started with Laravel by installing our development environment.

Once you’re up and running you can move on to some of the other Laravel tutorials here.

Getting Started with Laravel – Installation Requirements

At the time of writing, the latest version of Laravel is 5.4 which needs the following server requirements:

  • PHP >= 5.6.4 (although I recommend PHP7!)
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

In addition to the above, you will need to have Composer installed.

Installing Laravel

There are two ways to install Laravel. Using the Laravel installer or via Composer’s create-project command. Both are super easy and it’s up to you which one you use.

Using Laravel Installer

First, you’ll need to download the Laravel installer using Composer:

composer global require "laravel/installer"

Now, to create a new project all you need to do is run the following command:

laravel new webite

In the example above, Laravel will be installed in a new directory called website. Simple!

Using Composer create-project

If you’d prefer to use Composer to install Laravel, all you need to do is run the following command:

composer create-project --prefer-dist laravel/laravel website

Again, Laravel will be installed in a new directory called website. Still simple!

Configuring Laravel

We’re almost there now, with just a couple of commands you have Laravel installed. Next you just need to adjust some configuration settings and you’re ready to get coding.

Config Settings

Environment variables control most of the configuration. As a first step, copy the .env.example file:

cp .env.example .env

Open your new .env file and complete the settings as required. The following settings are typically what you need to enter at this stage:

APP_NAME=My Website
APP_ENV=development
APP_KEY=[should be set by the installer]
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://dev.mywebsite.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password

All available configuration can be found in the config directory and it’s all well documented. I encourage you to have a scoot around and see what’s there.

Permissions

The storage and bootstrap/cache directories need to be writable by the web server. Set this appropriately on your server.

Public Directory

Finally, point your domain’s document root to the public directory.

All Done

There you have it, Laravel is installed and you’re ready to start coding. As you can see the process is really quick and easy. You can be up and running with the framework in a matter of minutes.

I hope you’ve enjoyed this getting started with laravel guide. Thanks for reading!