Created
October 25, 2025 16:13
-
-
Save mirashif/9ac06d68163c1ddcbce33b38030ee81e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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