Skip to content

Instantly share code, notes, and snippets.

@tooinfinity
Created June 3, 2024 14:30
Show Gist options
  • Save tooinfinity/6a18ffc4da38f0155e4fb0e657f776bc to your computer and use it in GitHub Desktop.
Save tooinfinity/6a18ffc4da38f0155e4fb0e657f776bc to your computer and use it in GitHub Desktop.
Setting Up Laravel Sail and Docker on macOS

Setting Up Laravel Sail and Docker on macOS

Prerequisites

  1. macOS
  2. Docker Desktop

Step 1: Install Docker Desktop

  1. Download Docker Desktop: Download Docker Desktop from Docker's official website and install it.

  2. Run Docker Desktop: Open Docker Desktop and ensure it is running.

  3. Verify Docker Installation: Open Terminal and run the following command to verify the installation:

    docker --version

Step 2: Install Laravel and Sail

  1. Install Homebrew: If Homebrew is not already installed, install it by running the following command in Terminal:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install PHP: Use Homebrew to install PHP:

    brew install php
  3. Install Composer: If Composer is not already installed, run the following commands:

    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
  4. Create a New Laravel Project: Create a new Laravel project using Composer:

    composer create-project laravel/laravel example-app
    cd example-app
  5. Install Laravel Sail: Require Laravel Sail as a development dependency:

    composer require laravel/sail --dev
  6. Publish Sail's Docker Configuration: Publish Sail's Docker configuration:

    php artisan sail:install
  7. Start Docker Containers: Start the Docker containers:

    ./vendor/bin/sail up

Step 3: Configure Laravel Environment

  1. Copy Environment File: Copy the .env.example file to .env:

    cp .env.example .env
  2. Generate Application Key: Generate a new application key:

    ./vendor/bin/sail artisan key:generate
  3. Update Environment Variables: Update the .env file with the necessary database configuration if needed.

Step 4: Access Laravel Application

  1. Open Browser: Open your browser and navigate to http://localhost. You should see the Laravel welcome page.

Additional Commands

  • Stop Docker Containers:

    ./vendor/bin/sail down
  • Run Artisan Commands: To run other Artisan commands, prefix them with Sail:

    ./vendor/bin/sail artisan migrate

Troubleshooting

If you encounter any issues, ensure:

  • Docker Desktop is running.
  • The macOS environment is properly configured.

By following these steps, you should have a fully functional Laravel Sail and Docker environment set up on your macOS machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment