Skip to content

Instantly share code, notes, and snippets.

@mirashif
Created October 25, 2025 16:13
Show Gist options
  • Select an option

  • Save mirashif/9ac06d68163c1ddcbce33b38030ee81e to your computer and use it in GitHub Desktop.

Select an option

Save mirashif/9ac06d68163c1ddcbce33b38030ee81e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Laravel Sail Application Quick Setup Script
set -e # Exit on any error
echo "πŸš€ Starting Laravel (Sail) Application Setup..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if required tools are installed
check_prerequisites() {
print_status "Checking prerequisites..."
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker Desktop first."
exit 1
fi
if ! command -v composer &> /dev/null; then
print_error "Composer is not installed. Please install Composer first."
exit 1
fi
print_success "Prerequisites check completed"
}
# Step 1: Environment Configuration
setup_environment() {
print_status "Setting up environment configuration..."
if [ ! -f .env ]; then
if [ -f .env.example ]; then
cp .env.example .env
print_success "Environment file created from .env.example"
else
print_error ".env.example file not found!"
exit 1
fi
else
print_warning ".env file already exists, skipping..."
fi
}
# Step 2: Install PHP Dependencies
install_php_dependencies() {
print_status "Installing PHP dependencies..."
composer install
print_success "PHP dependencies installed"
}
# Step 3: Start Application with Laravel Sail
start_sail() {
print_status "Starting Laravel Sail..."
# Start Sail in detached mode
./vendor/bin/sail up -d
print_success "Laravel Sail started"
# Wait a moment for services to be ready
print_status "Waiting for services to be ready..."
sleep 10
}
# Step 4: Install Node.js Dependencies
install_node_dependencies() {
print_status "Installing Node.js dependencies..."
./vendor/bin/sail pnpm install
print_success "Node.js dependencies installed"
}
# Step 5: Run Database Migrations
run_migrations() {
print_status "Running database migrations..."
./vendor/bin/sail artisan migrate
print_success "Database migrations completed"
# Ask if user wants to run seeders
read -p "Do you want to run database seeders? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_status "Running database seeders..."
./vendor/bin/sail artisan db:seed
print_success "Database seeders completed"
fi
}
# Step 6: Display access information
show_access_info() {
print_success "Setup completed successfully! πŸŽ‰"
echo
echo "Your application is now running:"
echo " πŸ“± Application: http://localhost"
echo " πŸ—„οΈ Database: localhost:5432 (PostgreSQL)"
echo " ⚑ Vite Dev Server: http://localhost:5173 (when running 'sail pnpm run dev')"
echo
echo "Useful commands:"
echo " πŸ›‘ Stop services: sail down"
echo " πŸ“Š View logs: sail logs"
echo " 🐚 Access container: sail shell"
echo " πŸ§ͺ Run tests: sail test"
echo
}
# Main execution
main() {
check_prerequisites
setup_environment
install_php_dependencies
start_sail
install_node_dependencies
run_migrations
show_access_info
}
# Run main function
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment