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

  1. Open the Windows Terminal as an administrator.
  2. Run:

    wsl --install
  3. You'll be prompted to restart your computer to complete the installation.

Step Two: Create an Ubuntu 24.04 Distro

  1. 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.
  2. Open Windows Terminal
  3. List the available distributions (including Ubuntu-24.04):

    wsl -l --online
  4. Install Ubuntu 24.04: by running

    wsl --install -d Ubuntu-24.04
  5. 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

  1. Log into your new Ubuntu 24.04 distro:

    wsl -d Ubuntu-24.04
  2. Update and upgrade your packages:

    sudo apt update && sudo apt upgrade -y
  3. Install PHP, the required PHP extensions and unzip:

    sudo apt install php php-xml php-curl php-mbstring php-sqlite3 php-mysql unzip
  4. 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

  1. Create a new Laravel project:

    composer create-project laravel/laravel php-awesome

Step Five: Set up Visual Studio Code

  1. Install Visual Studio Code on your Windows machine if you haven't already. Download it here.
  2. Install the WSL extension in Visual Studio Code.
  3. 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

  1. Open the built-in terminal from the menu: Terminal → New Terminal.
  2. Navigate to your project:

    code php-awesome
  3. 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!

StocksComparison.com ad
 

1 Comments

Add a new comment: