#cli #deployment #composer #php #laravel

Creating a Deployment script to make the Deployment Easy

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.

mohammed-samgan-khan

Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.