Getting Started With Laravel On Windows Using Docker Desktop and WSL 2

By bhagwatchouhan
Getting Started With Laravel On Windows Using Docker Desktop and WSL 2

This tutorial provides all the steps required to create the first project in Laravel using Laravel Sail and Docker Desktop on Windows 10. Laravel Sail is a lightweight command-line interface that can be used to interact with Laravel's default Docker configuration. Laravel Sail is a built-in solution to run Laravel projects using Docker Desktop. You can also follow How To Install WSL 2 (Windows Subsystem for Linux) with Ubuntu On Windows 10, How To Install Docker Desktop On Windows 10, How To Change Docker Data Path On Windows 10, and How To Install Windows Terminal on Windows 10.

 

Notes: It's Bandwith Intensive operation for the first time, hence make sure that you are on a good internet connection and also followed How To Change Docker Data Path On Windows 10 to avoid filling your C drive. The Sail's application containers will be built on your machine for the first time.

 

Install Docker Desktop

 

Install Docker Desktop on your windows system to continue with this tutorial. You can follow How To Install Docker Desktop On Windows 10. Make sure that you have selected and installed the WSL update while installing Docker Desktop on Windows. Windows Subsystem for Linux 2 (WSL2) is required to run Linux binary executables natively on Windows 10. Also, Docker Desktop must be configured to use the WSL2 backend. It should be working fine if you have installed WSL 2 and Docker Desktop by following How To Install WSL 2 (Windows Subsystem for Linux) with Ubuntu On Windows 10 and How To Install Docker Desktop On Windows 10.

 

Create Laravel Project

 

Launch Windows Terminal and open a new WSL 2 session using Ubuntu 20.04 LTS as shown in Fig 1.

 

Install Laravel using Docker Desktop on Windows 10 - Launch WSL

Fig 1

 

Now create the Laravel project using the command as shown below.

 

curl -s https://laravel.build/helloworld | bash

 

It will start creating the Laravel project within the current directory i.e. %USERPROFILE% as shown in Fig 2. We can also change the directory to store the project files using the change directory command as shown below.

 

# Change the Directory to store project files
cd /mnt/<drive letter>/<projects directory>

# Example
cd /mnt/e/projects/php

 

Install Laravel using Docker Desktop on Windows 10 - Create Project

Fig 2

 

It will download all the applications and dependencies and shows a success message as shown in Fig 3.

 

Install Laravel using Docker Desktop on Windows 10 - Project Success

Fig 3

 

Launch Laravel Project

 

We can launch the newly installed Hello World project in Laravel using Sail using the commands as shown below.

 

cd helloworld

./vendor/bin/sail up

 

It will take some time for the first launch. The subsequent launches will be faster. On successfully launching the required service, the output should be similar to Fig 4.

 

Install Laravel using Docker Desktop on Windows 10 - Server Up

Fig 4

 

On the successful start of the application's Docker containers, We can access the application using the preferred web browser at: http://127.0.0.1. The default page should be similar to Fig 5.

 

Install Laravel using Docker Desktop on Windows 10 - Home Page

Fig 5

 

We can press Ctrl + C to exit and stop all the containers as shown in Fig 6.

 

Install Laravel using Docker Desktop on Windows 10 - Exit

Fig 6

 

We can use Microsoft's Visual Studio Code editor and their first-party extension for Remote Development to start coding the Laravel Project installed by us using Docker Desktop and WSL 2. You can also follow How To Install VSCode For PHP On Windows.

 

Summary

 

This tutorial provided the links to useful resources and the steps required to install and launch your first Laravel Application using Laravel Sail and Docker Desktop using WSL 2 on Windows 10.

share on :

Profile picture for user bhagwatchouhan
bhagwatchouhan