DEV Community

Cover image for Running Laravel 12 on WSL2 with PHP 8.2
Jonatan Jansson
Jonatan Jansson

Posted on

Running Laravel 12 on WSL2 with PHP 8.2

Usually I sit on my SER6 PRO running Fedora 41, and I love that — fast, clean, and full Linux. But I’ve had a stint of the cold lately and figured: why not cozy up in the living room with my partner for a day of Laravel?

So I fired up WSL2 on her Lenovo IdeaPad 3 (Ryzen 5 5500U, 8GB RAM, Windows 11) to get some work done on my Laravel-based aggregator project, T.E.A.L.

What followed was a mini side-quest of versioning and extension wrangling — here’s how I got Laravel 12 running on Ubuntu 22.04 via WSL2.


🚨 Laravel 12 Requires PHP 8.2+

By default, Ubuntu 22.04 ships with PHP 8.1, which is not sufficient for Laravel 12. Composer will fail with:

Cannot use laravel/laravel's latest version v12.0.3 as it requires php ^8.2
Enter fullscreen mode Exit fullscreen mode

🔧 Step 1: Add the PHP 8.2 Repository

We’ll use the widely trusted ondrej/php PPA to install PHP 8.2:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
Enter fullscreen mode Exit fullscreen mode

If you're on a locale that breaks add-apt-repository, use:

LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php
Enter fullscreen mode Exit fullscreen mode

🔧 Step 2: Install PHP 8.2 and Required Extensions

Laravel needs a handful of extensions. Install them all in one go:

sudo apt install php8.2 php8.2-cli php8.2-mbstring php8.2-xml php8.2-curl php8.2-mysql php8.2-zip php8.2-bcmath php8.2-tokenizer php8.2-common php8.2-readline php8.2-opcache unzip
Enter fullscreen mode Exit fullscreen mode

🔄 Step 3: Set PHP 8.2 as the Default

sudo update-alternatives --config php
Enter fullscreen mode Exit fullscreen mode

Choose the option corresponding to /usr/bin/php8.2.

Verify:

php -v
Enter fullscreen mode Exit fullscreen mode

🧩 Step 4: Enable Missing Extensions (like curl)

Even after installing php8.2-curl, I noticed Composer still complained that the extension wasn’t enabled. Here's how to fix that:

sudo phpenmod -v 8.2 curl
Enter fullscreen mode Exit fullscreen mode

Then check it’s active:

php -m | grep curl
Enter fullscreen mode Exit fullscreen mode

Now Composer should stop complaining about missing curl.


🚀 Step 5: Create the Laravel Project

Now you're ready to install Laravel:

composer create-project laravel/laravel .
Enter fullscreen mode Exit fullscreen mode

If you've already created the directory and it’s not empty, you can instead run:

composer install
Enter fullscreen mode Exit fullscreen mode

And finally:

php artisan serve
Enter fullscreen mode Exit fullscreen mode

Access your app via http://localhost:8000 from your browser.


✅ Summary

Running Laravel 12 on WSL2 takes a bit of setup, but once PHP 8.2 is installed and extensions are enabled, it’s smooth sailing. Whether you’re on bare metal Fedora or cozy in WSL2 on a borrowed machine, this flow gets Laravel 12 up and running like a charm.

Next up: actually building out T.E.A.L — a Laravel-powered aggregator that pulls and stores data from Steam, IMDb, and Goodreads.

Top comments (0)

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay