Getting Started with Laravel

Laravel is a PHP framework introduced in 2011 used to develop web applications. According to Google trends, the number of search terms for Laravel over the past 5 years have eclipsed other frameworks such as Symfony and Zend.

Getting Started with Laravel

Getting started with Laravel is easy. Simply download the Laravel installer via Composer:

$ composer global require "laravel/installer"

To run the laravel executable globally rather than having to specify the absolute path each time, add the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your $PATH.

For example, if you’re using macOS, add the following to the .bashrc file.

export PATH="~/.composer/vendor/bin:$PATH"

Save the file, then in Terminal, run the below command.

$ source ~/.bashrc

You may need to restart Terminal, but now you’ll be able to use the laravel executable to create a project. To do this, you can use the below command.

$ laravel new laravelproject

Where laravelproject is a newly created directory containing the Laravel installation. The command will also download the dependencies via composer that the Laravel project requires.

If you encounter the following error:

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

Your project may be missing an .env file. This can be resolved by creating the file, and copying over the contents of the .env.example file.

Now generate an application key using artisan key:generate.

$ /path/to/your/php artisan key:generate

Clear the application cache, using…

$ /path/to/your/php artisan config:cache

…and you should see the welcome page when loading the Laravel project.

Getting Started with Laravel

If you are not familiar with the framework, it is worth looking over the environment configuration. The config/app.php file is responsible for reading the environment variables within the .env file using the env() helper.

For example, APP_DEBUG can be set to put your application in debug mode. If the variable cannot be found within .env, the default false argument will be used.

// config/app.php  
| Application Debug Mode
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.

'debug' => env('APP_DEBUG', false),

The .env file is a file ignored by Git, so that environment variables can be changed depending on the environment the application sits on.