Skip to content

Instantly share code, notes, and snippets.

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

Setting Up Laravel Sail and Docker on Linux

Prerequisites

  1. A Linux distribution (e.g., Ubuntu)
  2. Docker
  3. Docker Compose

Step 1: Install Docker

  1. Update Your Package List:

    sudo apt update
  2. Install Docker:

    sudo apt install docker.io
  3. Start and Enable Docker:

    sudo systemctl start docker
    sudo systemctl enable docker
  4. Verify Docker Installation:

    docker --version

Step 2: Install Docker Compose

  1. Download Docker Compose:

    sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. Apply Executable Permissions:

    sudo chmod +x /usr/local/bin/docker-compose
  3. Verify Docker Compose Installation:

    docker-compose --version

Step 3: Install Laravel and Sail

  1. Install Composer:

    sudo apt update
    sudo apt install curl php-cli php-mbstring git unzip
    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
  2. Create a New Laravel Project:

    composer create-project laravel/laravel example-app
    cd example-app
  3. Install Laravel Sail:

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

    php artisan sail:install
  5. Start Docker Containers:

    ./vendor/bin/sail up

Step 4: Configure Laravel Environment

  1. Copy Environment File:

    cp .env.example .env
  2. Generate Application Key:

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

Step 5: 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 is running.
  • Docker Compose is properly installed.
  • The Linux environment is properly configured.

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

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