Creating a Laravel Website with out of the box authentication system
Tags: laravel, programming, authentication
Published: 2022-06-02 00:40:08

---
title: Creating a Laravel Website with out of the box authentication system
published: true
date: 2022-05-25 19:33:59 UTC
tags: Laravel,Programming,authentication,laravel
canonical_url: 
---

Hi everyone,  recently, I have been trying out several different Web Administration panel kits for my favorite PHP Platform, [Laravel](https://laravel.com/). I am looking for an out of the box system that will  provide my end users with:

- A login page
- A my profile area
- Login with a Social Media account
- Use two factor authentication.

In addition, I’d like the administration panel to have developer tools included in order to facilitate rapid application development.

# Laravel Auth

If you are working on a custom solution for a client and will not be distributing your app as opensource, then Backpack for Laravel, and Infyom Laravel generator are a great combo.

Today however, I will be testing out a package I recently found called [Laravel Aut](https://github.com/jeremykenedy/laravel-auth#installation-instructions)  which is opensource, and looks perfect for satisfying some of my main requirements.

Lets go ahead and set things up!

1. Using my [PHPStorm IDE,](https://www.jetbrains.com/phpstorm/) I will add a new mysql data source in the database tab.
2. Next, I will create a new schema called laravel-auth, and set the collation to utf8mb4\_general\_ci (so my users can insert fancy emojis if they like).
3. Now I will clone the project using git: git clone [https://github.com/jeremykenedy/laravel-auth.git](https://github.com/jeremykenedy/laravel-auth.git) laravel-auth
4. Once cloned, I next need to create the .env laravel configuration file to set up the database
  1. find change the following
    1. DB\_DATABASE\
    2. DB\_USERNAME
    3. DB\_PASSWORD
5. then run “composer upate”. This will run all third party dependencies and libraries.
6. Now, we need to publish laravelroles and 2 step authentication. This step will copy important migration files from the vendors folder into to the app, as well as database seeders, and assets.
7. Generate a unique app key – From the projects root folder run `php artisan key:generate`
8. Run database migrations – from the projects root folder run `php artisan migrate. This will set up all the database tables for the project.`
9. From the projects root folder run `composer dump-autoload`
10. From the projects root folder run `php artisan db:seed`
11. Compile the front end assets with [npm steps](https://github.com/jeremykenedy/laravel-auth#using-npm) or [yarn steps](https://github.com/jeremykenedy/laravel-auth#using-yarn).

# Set up a Virtual Host

With laravel-auth now installed, lets set up an Apache Virtual Host so we can view the website on our local machine.  For this, I use a nifty bash script called Virtualhost which I got from [RoverWire/virtualhost](https://github.com/RoverWire/virtualhost)

```
 sudo virtualhost create laravel-auth.localhost
```

This created a file for me in /etc/apache2/sites-available, enabled the virtual host, created an entry in /etc/hosts file, and then restarted apache.  A few small tweaks were needed however at this point.  Firstly, Laravel’s public folder is in /public/  so I had to edit /etc/apache2/sites-available/laravel-auth.localhost.conf to fix the document root.  I also noticed that the script created a folder for me in /var/www/laravel-authlocalhsot, so I deleted this and re-updated the laravel-auth.localhost.conf to point to the proper folder of where I cloned the repo (/var/www/laravel-auth/

I then refreshed the website – and oops – got a laravel error which complained that its log files were not writable. so I had to do a few more sys admin tasks:

```
sudo chown -R www-data:www-data

sudo find /var/www/laravel-auth -type f -exec chmod 644 {} \;

sudo find /var/www/laravel-auth -type d -exec chmod 755 {} \;

```

Since this is my local development machine however, and not a production environment, I am going to chown my project foler to my user instead of www-data

```
sudo chown -R $USER:www-data .

sudo find . -type d -exec chmod 775 {} \;
sudo find . -type f -exec chmod 664 {} \;
```

I am also going to need to give the webserver write permissions to storage, cache

```
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
```

Now we are ready – Lets navigate to http://laravel-auth.localhost/

But wait! We are NOT done. Further configuration is needed:

## ReCaptcha

Since we are deploying locally, edit the .env file, and set

```
ENABLE_RECAPTCHA=false
```

then do

```
composer dump-autoload
```

 

Wow! It’s beautiful!  With this scaffolding in place, I am now ready to add some API endpoints for my LSL Second Life Metaverse Scripts!

[![](https://b3dmultitech.com/wp-content/uploads/2022/05/laravel-auth-1.png)](https://b3dmultitech.com/creating-a-laravel-website-with-out-of-the-box-authentication-system/laravel-auth-2/)

The post [Creating a Laravel Website with out of the box authentication system](https://b3dmultitech.com/creating-a-laravel-website-with-out-of-the-box-authentication-system/) appeared first on [Paul Preibisch](https://b3dmultitech.com).