Installation Script

Creating an installation script for your Laravel application can automate tedious setup tasks like environment configuration, dependency installation, and database migration. Depending on your needs, you can create a simple bash script (for Linux/macOS) or a custom Artisan command (to distribute with your application). 

Method 1: Bash Installation Script (Linux/macOS)
A bash script is ideal for setting up a freshly cloned repository on a new server or local environment. 
  1. Create the file: In your project root, create a file named install.sh.
  2. Add the script logic:
    bash
    #!/bin/bash
    # install.sh
    
    echo "Starting Laravel Installation..."
    
    # 1. Install PHP dependencies
    composer install --no-interaction --prefer-dist --optimize-autoloader
    
    # 2. Setup Environment File
    if [ ! -f .env ]; then
        cp .env.example .env
        echo ".env file created from .env.example"
    fi
    
    # 3. Generate Application Key
    php artisan key:generate
    
    # 4. Install Frontend Dependencies
    npm install
    npm run build
    
    # 5. Run Database Migrations
    php artisan migrate --force
    
    # 6. Set Permissions
    chmod -R 775 storage bootstrap/cache
    chown -R www-data:www-data storage bootstrap/cache
    
    echo "Installation Complete!"
    
  3. Make it executable: Run chmod +x install.sh in your terminal.
  4. Run it: Execute with ./install.sh. 

Method 2: Custom Artisan Command (Recommended for Distribution)
If you are building a product for others, a custom Artisan command like php artisan app:install provides a more integrated experience. 
  1. Generate the command:
    bash
    php artisan make:command InstallApplication
    
  2. Configure the command: Open app/Console/Commands/InstallApplication.php and define the logic:
    • Signature: protected $signature = 'app:install';
    • Logic: Use Artisan::call() to run setup tasks.
    php
    public function handle()
    {
        $this->info('Installing Application...');
    
        $this->call('key:generate');
        $this->call('migrate', ['--force' => true]);
        $this->call('db:seed');
        $this->call('storage:link');
    
        $this->info('Application installed successfully!');
    }
    
     

Key Components of a Laravel Installer
To ensure your script is robust, it should handle the following: 

Advanced Options
Advanced Options

Revision #1
Created 14 December 2025 14:53:21 by AI Channel
Updated 14 December 2025 14:54:50 by AI Channel