Back to Menu

# Install Laravel on Ubuntu on Windows 11 Using Docker

Install Laravel on Ubuntu on Windows 11 Using Docker

A step-by-step guide to installing Laravel on Windows 11 using Ubuntu (WSL) + Docker, setting up Laravel, configuring the database ports, and running your project locally.

3 min read
#docker#windows#ubuntu

Table of Contents

Install Laravel on Ubuntu on Windows 11 Using Docker

Cover


PROCESS

1. Install WSL (Ubuntu)

  • Run PowerShell as Administrator, then:
Terminal window
wsl --install

Follow the prompts to install Ubuntu.


2. Update Ubuntu Packages

Terminal window
sudo apt update && sudo apt upgrade -y

3. Install PHP 8.2 (or any version you need)

Run the following commands:

Terminal window
sudo apt update
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2-cli php8.2-common php8.2-mbstring php8.2-xml php8.2-bcmath php8.2-curl php8.2-mysql php8.2-zip php8.2-readline php8.2-gd php8.2-intl php8.2-tokenizer php8.2-soap

4. Download & Install Docker for Windows


5. Configure Docker

  • Open Docker Desktop
  • Go to Settings → Resources → WSL Integration
  • ✅ Turn on Ubuntu

Cover


6. Test Docker via Ubuntu Command Line:

To Check if Docker is installed correctly, run:

Terminal window
docker --version

To test Docker by creating a cxample image (for testing only), run:

Terminal window
docker pull hello-world

Cover

A new 'hello world' image has been created inside of your Docker image



If you get permission denied, run:

Terminal window
docker login -u yourDockerUsername

Then Generate a New Personal Access Token at: https://app.docker.com/settingsPersonal Access TokensGenerate New Token, then re-run the login if needed.



After Re-login and Generating, add user to Docker group:

Terminal window
sudo usermod -aG docker $USER

Then re-open Ubuntu Command Line, and test again, via:

Terminal window
docker pull hello-world

7. Create Main Laravel Projects Directory

In Ubuntu Command Line, go to your home directory:

Terminal window
cd ~

Create a MAIN FOLDER for your Laravel projects:

Terminal window
mkdir LaravelProjects

Why this folder? LaravelProjects will serve as your main workspace for all Laravel projects, so everything stays organized in one place. You can name it anything or skip this step, but using one dedicated folder is recommended.



To go inside of the LaravelProjects directory, run:

Terminal window
cd LaravelProjects

8. Create a Laravel Project

Terminal window
composer create-project laravel/laravel firstwebsite

To go inside of the project folder, run:

Terminal window
cd firstwebsite

Command Line Tips:

  • To go back: cd ..
  • To list directories: ls -d */ or type ls

9. Install Laravel Sail

Terminal window
composer require laravel/sail --dev

Next: After the following installation, run:

Terminal window
php artisan sail:install

10. Open Project in VS Code

Terminal window
code .

Trust the folder when prompted.


BUT, Before running our Laravel project in Docker, we need to configure the .env file and set up the database.

11. Configure .env File

Edit your .env:

Terminal window
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=firstwebsite
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3308

use 3308 (or any, not 3306) for FORWARD_DB_PORT to avoids conflict with the host’s MySQL when using Docker.


12. Run Migrations

Terminal window
./vendor/bin/sail artisan migrate

13. Verify Database Using GUI

Use DBeaver or MySQL Workbench with the following settings:

Host: 127.0.0.1
Port: 3308
User: sail
Password: password

Cover

If checking the database fails, run the command ./vendor/bin/sail up -d inside your Laravel project, then check again.


14. Run Laravel Sail

Terminal window
# to start laravel server
./vendor/bin/sail up -d
# or to stop laravel server
./vendor/bin/sail down
# or to verify if running
./vendor/bin/sail ps

Cover


15. Access Laravel in Browser

Make sure it’s running:

Terminal window
./vendor/bin/sail up -d

Then open:

Cover


DONE!

Cover

Done! Laravel is now running inside Docker with Ubuntu on WINDOWS 11.

Comments & Reactions

(click to open)

Related posts