DEV Community

Paul Preibisch
Paul Preibisch

Posted on • Originally published at b3dmultitech.com on

Creating a Laravel Website with out of the box authentication system

Hi everyone, recently, I have been trying out several different Web Administration panel kits for my favorite PHP Platform, Laravel. 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 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, 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 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
    2. DB_DATABASE\
    3. DB_USERNAME
    4. 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 or yarn steps.

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

 sudo virtualhost create laravel-auth.localhost
Enter fullscreen mode Exit fullscreen mode

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 {} \;

Enter fullscreen mode Exit fullscreen mode

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 {} \;
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

then do

composer dump-autoload
Enter fullscreen mode Exit fullscreen mode

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!

The post Creating a Laravel Website with out of the box authentication system appeared first on Paul Preibisch.

Top comments (0)