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!
- Using my PHPStorm IDE, I will add a new mysql data source in the database tab.
- 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).
- Now I will clone the project using git: git clone https://github.com/jeremykenedy/laravel-auth.git laravel-auth
- Once cloned, I next need to create the .env laravel configuration file to set up the database
- find change the following
- DB_DATABASE\
- DB_USERNAME
- DB_PASSWORD
- then run “composer upate”. This will run all third party dependencies and libraries.
- 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.
- Generate a unique app key – From the projects root folder run
php artisan key:generate
- Run database migrations – from the projects root folder run
php artisan migrate. This will set up all the database tables for the project.
- From the projects root folder run
composer dump-autoload
- From the projects root folder run
php artisan db:seed
- 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
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!
The post Creating a Laravel Website with out of the box authentication system appeared first on Paul Preibisch.
Top comments (0)