#cli #deployment #composer #php #laravel

Creating a Deployment script to make the Deployment Easy

Table Of Content


  1. Step 1: Create deployment script
  2. Step 2: Update the script
  3. Step 3: Run on Deployment

Deployment in itself is a messy task, and it becomes a bit more of hectic if you need to run a bunch of commands every time you deploy.

The one of the best way is to create a deployment script and run it every time you deploy.

Step 1: Create deployment script

create a deploy.sh file in the root of your folder and make it executable. You can use the following commands.

touch deploy.sh
sudo chmod +x deploy.sh

Step 2: Update the script

# Turn on maintenance mode
php artisan down

# Pull the latest changes from the git repository
git reset --hard
git clean -df
git pull origin master

# Install/update composer dependecies
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

# Run database migrations
php artisan migrate --force

# Clear caches
php artisan cache:clear

# Clear expired password reset tokens
php artisan auth:clear-resets

# Clear and cache routes
php artisan route:clear
php artisan route:cache

# Clear and cache config
php artisan config:cache
php artisan config:clear

php artisan view:clear

# Install node modules
npm install

# Build assets using Laravel Mix
npm run prod

# Turn off maintenance mode
php artisan up

Step 3: Run on Deployment

Now every time you need to deploy. just run deploy.sh

./deploy.sh

Feel free to suggest any modification if you feel so.

Most Viewed Posts


Must Read


January 28, 2022

#AppImage #linux

How to Add AppImage Application to Menu in Ubuntu (Linux)

AppImages are the most easiest to run compared.The challenging task is to make the AppImage accessible globally through he system like an installed application (in the menu)

Reading time: less than a minute
How to Add Laravel Pint to VS Code Formatter
June 24, 2022

#code-quality #vscode #laravel-pint #laravel

How to Add Laravel Pint to VS Code Formatter

I have been using the unsatisfactory formatters from a long time. All of them have one thing but lack other. Laravel Pint is one who has it all, combining it with vscode is like proving you laravel project a super power.

Reading time: 2 minutes
March 24, 2021

#express js #node #node js #sequelize #mysql

How to create model association in Sequelize - express JS / Node JS

In the very initial days of my work in Node JS if faced this issue. Though Sequelize provide a great ORM for MySQL but the association within the models is a bit tricky.

Reading time: 2 minutes
December 14, 2021

#database #javascript #sequelize #npx

Sequelize CLI Commands

list of Sequelize CLI commands which comes handy, while working on a project.

Reading time: 1 minute
How to create a progressive web app (PWA) in laravel 5.* and above
July 07, 2019

#functionality #pwa #javascript #laravel

How to create a progressive web app (PWA) in laravel 5.* and above

The progressive web app is the new trend as well as the need for the present time. I hope before getting in the “HOW” part you know what is exactly a PWA

Reading time: 4 minutes
How to Add Laravel Pint to VS Code Formatter
June 24, 2022

#code-quality #vscode #laravel-pint #laravel

How to Add Laravel Pint to VS Code Formatter

I have been using the unsatisfactory formatters from a long time. All of them have one thing but lack other. Laravel Pint is one who has it all, combining it with vscode is like proving you laravel project a super power.

Reading time: 2 minutes
How to create a progressive web app (PWA) in laravel 5.* and above
July 07, 2019

#functionality #pwa #javascript #laravel

How to create a progressive web app (PWA) in laravel 5.* and above

The progressive web app is the new trend as well as the need for the present time. I hope before getting in the “HOW” part you know what is exactly a PWA

Reading time: 4 minutes
November 02, 2021

#laravel #tricks #eloquent

Approach to Handle Complex queries in laravel

I am familiar with the love of Eloquent among the laravel community but sometimes, sometimes its better to go for raw queries. Its saves you a lot of time and trouble.

Reading time: 1 minute
September 06, 2019

#cli #authentication #laravel

PHP artisan make:auth in laravel 6.0

As you may have known by now that laravel 6.0 has been out. Though it's expected to have a lot of changes in the major release but in 6.0 there are not that many changes.

Reading time: less than a minute
March 02, 2020

#hosting #deployment #laravel

Checklist for Production Deployment laravel Project

below are mentioned things to be taken care of at the time of deploying a laravel project to production.

Reading time: less than a minute
mohammed-samgan-khan

Hi, I am Samgan, I know the adds are bit annoying but i hope you understand. Talking about me, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialize in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.