This Is A Bash Script To Automatically Create A Laravel Docker Project


Use this script to create a new laravel docker sail project with just one command. This script will prompt you to enter the name of the project and will also start the project for you.

  1. Create a new file called create_laravel.sh one level outside the project folder
  2. Copy and paste the code below and save the file
  3. Change the permission to allow to execute:
    $ chmod +x create-laravel.sh
  4. Run the script
    ./laravel.sh
  5. Done

create_laravel.sh

#!/bin/bash

clear

APPNAME_DEFAULT="api"
read -p "Enter The App you want to Create: [$APPNAME_DEFAULT/] " APPNAME
if [[ $APPNAME == "" ]]
then
    APPNAME=$APPNAME_DEFAULT
    set -e
fi

#https://stackoverflow.com/questions/59838/how-can-i-check-if-a-directory-exists-in-a-bash-shell-script
# check if directory exists
if [ -d "$APPNAME" ]; then
  echo "FATAL FERROR: $APPNAME ALREADY EXIST. Try Again."
  set -e
  exit
fi
echo "App does not exist. Creating APP: $APPNAME"

curl -s https://laravel.build/$APPNAME | bash

cd $APPNAME
./vendor/bin/sail up -d

# ALWAYS PUT THIS AT THE END OF THE SCRIPT
echo "Opening browser with localhost"
xdg-open http://localhost