Setting Up Laravel 11 on WSL with Ubuntu 24.04
Last update: 04-29-2024
Welcome!
This concise guide is here to help you start a new Laravel 11 project using Windows Subsystem for Linux (WSL) and Ubuntu 24.04.
Step One: Installing WSL
- Open the Windows Terminal as an administrator.
Run:
wsl --install
- You'll be prompted to restart your computer to complete the installation.
Step Two: Create an Ubuntu 24.04 Distro
- Since Laravel 11 requires PHP 8.3, and the default Ubuntu 22.04 in WSL points to PHP 8.1, we'll install Ubuntu 24.04.
- Open Windows Terminal
-
List the available distributions (including Ubuntu-24.04):
wsl -l --online
-
Install Ubuntu 24.04: by running
wsl --install -d Ubuntu-24.04
- Wait for the distro to be downloaded and installed, then set up your username and password when prompted.
Step Three: Install the Prerequisites on the New Distro
-
Log into your new Ubuntu 24.04 distro:
wsl -d Ubuntu-24.04
-
Update and upgrade your packages:
sudo apt update && sudo apt upgrade -y
-
Install PHP, the required PHP extensions and unzip:
sudo apt install php php-xml php-curl php-mbstring php-sqlite3 php-mysql unzip
- Install Composer by following these commands (Source):
wget https://getcomposer.org/download/2.7.4/composer.phar chmod +x composer.phar sudo mv composer.phar /usr/local/bin/composer
Step Four: Create the Laravel Project
-
Create a new Laravel project:
composer create-project laravel/laravel php-awesome
Step Five: Set up Visual Studio Code
- Install Visual Studio Code on your Windows machine if you haven't already. Download it here.
- Install the WSL extension in Visual Studio Code.
- Open the command palette by pressing
Ctrl+Shift+P
, find and choose "WSL: Connect to WSL using distro".
Step Six: Develop and serve your application
- Open the built-in terminal from the menu: Terminal → New Terminal.
-
Navigate to your project:
code php-awesome
-
To serve the Laravel application, run:
php artisan serve
That's it! You now have a running Laravel 11 project on your WSL-configured machine using Ubuntu 24.04. Happy coding!