Good content takes time and effort to come up with.

Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.







Laravel App Deployment Checks


12th May 2021 3 mins read
Share On     Share On WhatsApp     Share On LinkedIn


Most of the time you forget to do a few changes after Laravel Production deployment. I have tried my best to cover them through this article.


Prerequisites


Hope you guys might have deployed your application in AWS / Digital Ocean / Linode / Google Cloud or similar services. If not you can check the following articles


LEMP Stack Installation


LAMP Stack Installation


Server Security Configurations


Basic Server Security For Ubuntu Server


NGINX Security Best Practices


Laravel Application Settings


1 - Changes in .env file


  1 - Application Settings

APP_NAME='Your Product Name'
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com


  2 - Database Settings

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=database_username
DB_PASSWORD=database_password


3 - Websocket (Optional - Enable if you want to broadcast notifications)

BROADCAST_DRIVER=pusher


4 - Queues (Optional - if you're not using Queues)

QUEUE_CONNECTION=database


5 - Sessions driver & time expiration (Optional - as default settings already set)

SESSION_DRIVER=file
SESSION_LIFETIME=120


6 - Redis database Settings (Optional - If you are using Redis for Caching)


7 - AWS Settings (AWS Keys for )


8 - Pusher Settings


9 - Payment Settings (Like Stripe, RazorPay, PayPal)


10 - Google Analytics / Recaptcha / Google Map Keys



2 - Optimizing Composer's autoloader


Composer Installation

Without any dev dependencies - This will boost the speed and won't install unnecessary development packages

composer install --optimize-autoloader --no-dev   


Composer DumpAutoloading

With dev dependencies - Usually for the final check of how your dev dependencies are performing. Usually in testing servers.

composer dump-autoload --optimize


Composer Update

NOTE - NEVER UPDATE IN PRODUCTION. Make sure to keep the backup of composer.json & composer.lock files. Unless you want the minor versions of your project to be update make sure not to update the composer packages.

composer update --optimize-autoloader

3 - Optimize the cache of your application


#Application Cache
php artisan config:cache

#Optimizing Route Loading
php artisan route:cache

#Compile and cache Blade templates
php artisan view:cache

#Events cache
php artisan event:cache


Instead of running all the cache commands one by one you can make a custom cache command and run it once. I have written an article on the same - Laravel Custom Command To Cache Your Applications
You can cache your Static assets too using - Cache Static File Using NGINX

4 - Compiling assets


WebpacMix settings compilation

npm run production

OR

Manually add the minified versions of CSS & Javascript files


Make sure to protect your assets like CSS / Js / Images from others accessing from their website - Cache Static Files With NGINX

5 - Laravel task scheduler (Optional)


* * * * * cd /project_path && php artisan schedule:run >> /dev/null 2>&1


You can learn more on - Laravel Cronjobs Usage & Settings
Automate Repeating Tasks In Linux Server With Cronjobs

6 - Supervisor Settings


If you are using Supervisor for running your Queue Scheduling the don't forget to set up from here - Supervisor For Laravel Queue Scheduling


7 - Create a symbolic link from public/storage to storage/app/public


php artisan storage:link

8 - Installing SSL certificates


You can read more on installing SSL certificates in CPanel or VPS servers with the following articles


Free SSL Certificate For CPanel


Free SSL Certificate With Lets Encrypt/Certbot In Linux (Single / Multiple Domains)


9 - Database security


If you have set up your server with SSH key access then don't use PHPMyAdmin or any other browser-based clients in your server.


Use SSH Key database login with Sequel Ace or MySQL Workbench kind of client which supports SSH key login to your database.


Securely Connect Server MYSQL DB From Sequel Pro / MYSQL Workbench


SSH Usage In Sequel Ace

SSH Usage In Sequel Ace





Author Image
AUTHOR

Channaveer Hakari

I am a full-stack developer working at WifiDabba India Pvt Ltd. I started this blog so that I can share my knowledge and enhance my skills with constant learning.

Never stop learning. If you stop learning, you stop growing