Install and Configure Laravel 5.1 and do simple authentication

Install And Configure Laravel 5.1 and do simple authentication

Here, I am going to explain how to install a fresh Laravel 5.1 package in Ubuntu and how to configure and how to do a simple authentication process in Laravel 5.1.

Install Laravel 5.1 – Server Requirements

The Laravel framework has a few system requirements. Of course, all of these requirements are satisfied by the Laravel Homestead virtual machine:

1. PHP >= 5.5.9
2. OpenSSL PHP Extension
3. PDO PHP Extension
4. Mbstring PHP Extension
5. Tokenizer PHP Extension

Installing Laravel 5.1

Laravel uses Composer to handle all dependencies. You need to install Composer first if composer is not installed. In case the Composer is already installed, skip the below steps and go to step “Install Laravel 5.1 with following command:”.

Composer installation steps for Ubuntu:

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

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

Composer reference for different platforms:


Install Laravel 5.1 with the following command:

composer create-project laravel/laravel blog "5.1.*"
Provide the permission using below commands for “storage” and “bootstrap”, which are available inside the blog directory, and created.

sudo chmod -R 777 storage/
sudo chmod -R 777 bootstrap/cache/
After the installation is done, create the virtual host and point the document root to “your_application_path/blog/public” since “public” is the document root of the laravel application. This is where the Laravel application will receive all the requests.


Here I am providing how to create virtual host in nginx in ubuntu:


virtual host ref:–3

Quick steps for nginx

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/
sudo nano /etc/nginx/sites-available/

/*update the root path*/
root /home/vignesh/projects/blog/public;

sudo ln -s /etc/nginx/sites-available/
sudo service nginx restart
nano /etc/hosts

/*add the below lines in hosts file */

That’s it… virtual host created successfully.


Run this url in broswer You will get the Laravel 5.1 page. Thus the Laravel 5.1 package is installed successfully.


Then create the database “your_db_name” and configure .env file which is available inside the blog directory.

After configuring the database connections I will do the following steps for simple authentication.




Add the below lines in


// Providing Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Providing Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

Create the view file as given in the link


Use the above link how to create blade files for authentication process.


Load the url


The register form loads, and when you submit the form you will get an error.


Run these below comments in terminal inside your project directory:
(ref :


To create the user table:

php artisan migrate
After running the above command successfully, Users table will be created in your database with basic columns.


Now do submit auth/register to create first user account.


Basing configure in

/* Will get redirected to this path after successful login */
protected $redirectPath = '/admin/dashboard';
/* Will get redirected to this path if login failed */
protected $loginPath = '/auth/login';

Use this command to create the admin controller:


php artisan make:controller AdminController
Add this line “return view(‘admin.index’);” in index method of app/Http/Controllers/AdminController.php without the double quotes
and create “admin” directory inside resources and create files index.blade.php. Then add this line in index.blade.php file:

< ?php echo "This is the admin page";?>

Add middleware authentication checking for your secured routes:


auth is used to access the particular page for logged in users only, these pages are not accessible to guests.

Route::group(['middleware' => 'auth'], function () {
These routes are only accessible by users who can login. Not for guests.


Route::group(['middleware' => 'auth'], function () {
Route::group(['prefix' => 'admin'], function () {
Route::get('/adminindex', [
'uses' => 'AdminController@index',
'as' => 'admin.adminindex'
Thats it… this url will be and will be accessible only for logged in users.
Now you can use to access the login and submit your created credentials. It will work fine.