r/PHP • u/arhimedosin • Dec 17 '25
WSL2 development environment for PHP projects with little to no fuss
PHP is great, but setting up a truly functional development environment is a pain. There are so many moving parts I sometimes feel I'm wasting more time on the environment than on coding.
I remember using XAMPP back in the day - when it was still the go-to solution. Somebody should tell them that PHP 8.3 was released. And PHP 8.4. Even 8.5. Get with the program...
So I started reading about a WSL development environment which seems to hit the right marks:
- An environment that matches the production one closely. This prevents surprises when I release my code.
- Full freedom to set up what I need, when I need it. Sometimes too much freedom.
- A virtual machine sandbox that is separate from my main system. I don't have to worry about stuff escaping the virtual machine and deleting my games... I mean my totally-legit, work-related stuff.
- I can pick my preferred Linux distribution, which makes it a breeze to change versions for each component. No more uninstalls and reinstalls every time I'm switching projects.
But that freedom thing I mentioned above is the one that worries me. A WSL recipe with Ansible provides the fix. It sets everything up: PHP, Apache, MariaDB, Git, Composer, PhpMyAdmin. Then I can start coding, maybe add some vhosts along the way.
The big part of the setup is covered in this article.
What do you guys use for your development envoronments?
72
u/manu144x Dec 17 '25
I'm simply using docker with WSL and it's all going great ever since.
12
u/TorbenKoehn Dec 17 '25
Way to demand something that is free, open source and can be freely contributed to by anyone. Why don't you patch it?
You need Docker or Podman. Work with containers. That's the only way to get
a) exactly the environment you have in prod (in the best case it's the same container)
b) unlimited amounts of test spaces that don't pollute anything else
To easily set it up you can use tools like Docker Compose, Skaffold etc. It's really simple and doesn't just "pre-configure some stuff of which some you need and some you don't". You can extend it with exactly what you need at any time.
12
u/emiliosh Dec 17 '25
Learn to use Docker it will open a new world to you.
30
u/alphex Dec 17 '25
DDEV
7
u/JazzlikeGanache6448 Dec 17 '25
Yes you do. WSL is not a traditional VM with a fully isolated disk, so inside WSL you can access Windows files /mnt/c and mess up stuff.
12
u/Supportic Dec 17 '25 edited Dec 17 '25
WSL is your virtualized Linux machine on windows. Linux is arguably better suited for development but it doesn't mean you install x different WSL environments.
Docker is what you are looking for. Containerized environments with dependencies you really need, without polluting the host and dependency hassle. Containers can talk to each other in a custom network.
You install WSL and Docker Desktop on Windows. The docker socket gets mounted into WSL and is ready to use. Define your compose + Dockerfiles and you are ready to go.
3
u/menotyoutoo Dec 17 '25
As other has mentioned, docker with WSL. I usually use this as the LAMP stack for our generalized stuff https://github.com/sprintcube/docker-compose-lamp (WordPress, various legacy sites in god knows what frameworks, or no frameworks). We have to run local dev environments with various version of PHP / MySQL for different client sites so docker lets us do that easy.
For Laravel sites I'll use Sail.
3
u/mindprocessor Dec 17 '25
in windows i use podman and podman desktop, needs wsl2.
3
u/drNovikov Dec 17 '25
Try DDEV
3
u/ItsBugsy Dec 18 '25
DDEV is excellent.
https://ddev.com
DDEV in 10 Minutes on Windows:
https://youtu.be/nKxZ5YNucd4?si=ToxamgLBsXz43bsc
7
u/SativaNL Dec 17 '25
DDEV
Only thing you need
2
u/shyevsa Dec 17 '25
I use either Vagrant or Docker.
it solve a lot of "it run on my machine" problem.
because everyone pretty much has the same setup.
and it can mimic the production setup as close as possible.
it also flexible because I can run multiple php without doing the alias magic.
2
u/Salty-Departure-8076 Dec 17 '25
Wsl, docker, it's all you need 🫡
7
u/Own-Perspective4821 Dec 17 '25
It’s kind of funny, people who are trying to figure out Windows development are still jumping through any kind of hoops to avoid using docker containers for development.
And it’s always the ex-XAMPP guys… can we PLEASE forget about XAMPP already? It’s 2025
2
u/MichaelW_Dev Dec 17 '25
Laravel Herd all the way for me. Takes the fuss out of it all. It's not just for Laravel so don't be fooled by the name, but if you are using it, then it's brilliant with it. It's available on Windows and Mac. I do have the pro version which is paid but there is a free version with less functionality and is fine if you're happy to do other bits outside of it.
1
u/dangoodspeed Dec 17 '25
I still use MAMP Pro as my go-to and it's working great. They have a Windows version too, though it's behind with the PHP versions. You can choose up to 8.5 for the Mac, only 8.3 currently on Windows. Still better than XAMPP!
1
u/ngg990 Dec 17 '25
Development environments are like candies, there are a lot of colors and flavors. So WSL is basically a way to install a Linux virtual machine. You can use phpenv to have different php versions installed "locally" (in the virtual machine) - other devs goes fully by docker... I normally use a combo of phpenv to manage different php versions, then per project a docker file with the closest "prod" setup. If you are using Mac, you will have almost the same tooling, using windows native alternatives is also possible but you maybe need to switch your mind between MSDoS/PowerShell and Unix command line útiles and syntax Wich normally is annoying.
1
u/dominikzogg Dec 17 '25
Feel free to take my development setup as a foundation https://github.com/chubbyphp/docker
php-85 branch does not built yet (swoole is not ready yet, but php-84 branch should be fine.
1
u/Deji69 Dec 17 '25
I do use Docker a lot in production, but honestly for local development I much prefer to just use Laragon most of the time.
It allows me to work on the multiple projects I'm usually working on at once with domains rather than IP addresses, which sometimes conflict (all using localhost) and other times are different based on the order you start them. Creating a new local dev site is as simple as creating a folder and putting shit in it. Version switching and configurations is simple and easy, I can run many local sites using the same redis instance, DB instance, etc. without a big footprint on my system and have them available pretty much always, at once. Yes, the PHP version will be shared, but I'm keeping all my shit updated.
I don't need my local environment to match a production one. I'm old school and like my code to not be so fragile it only runs on one specific machine setup lol. And many of my apps are designed to just help me out with shit on my local system. Writing and maintaining compose scripts and dockerfiles and typing docker commands would just add needless friction for most of my workflows.
I think the problem I have with anyone answering this is assuming a single purpose. Not everyone may mean the same thing when they say 'PHP development' or 'PHP projects'. What are they? Pet projects? Hobby projects? Your own suite of local apps? Freelance projects? Or open source projects? Projects for enterprise? Collaborating? There's no one solution, it depends how you want and need to work.
Also PHPMyAdmin, eugh... are people still using that? I thought it was only ever being propped up by shared hosting sites that don't allow access with something like HeidiSQL or DataGrip.
1
u/abstraction_lord Dec 17 '25
Ubuntu (ez setup) for dev envs, debian/alpine in prod, the similar experience makes me (feel at least) more efficient/fluid overall. Im no longer into gaming, so no windows required (although some great improvements are being made for gaming in linux). I'm also heavily into anti vendor-lock "politics", so Apple/Mac is a no-go for me
1
u/sensitiveCube Dec 17 '25
I moved to Linux.
1
u/harbzali Dec 17 '25
WSL2 with Docker Desktop integration works smoothly for PHP. Keep your files in the Linux filesystem for better performance. Use VS Code Remote-WSL extension for seamless editing. Ansible provisioning is solid for reproducible setups across team members.
1
u/Prakor Dec 17 '25
Use docker with WSL, Ansible is a one off and you cannot work on projects that relies on different php/node versions that way.
If you want something quick and practical, use DDEV. It comes with all the bells and whistles attached and you can have as many different setups as you want.
Ansible is good to provision WSL itself though, as if it was a linux box and you want to maintain a recipe to restore you system in case you need to.
1
u/Ariquitaun Dec 17 '25
https://phpdocker.io
1
u/Anxious-Insurance-91 Dec 17 '25
I used php in WSL2
It's nice to be honest but compared to using linux as an OS you do get some hickups
Now if you use docker you will probably need to add wsl2
I could also sugest to use a virtual box with ubuntu on it
1
u/HyperDanon Dec 17 '25
My recommended approach would be to be cautious about taking random dependencies. Things that break when moving between the os are things that depend on something: locale, fs, custom extensions, os-specific things. Try to minimize those and you can run it anywhere. That's totally doable if you're not hill-billying anything you can put your hands on.
1
u/tom_earhart Dec 17 '25
Well yeah WSL has been the go to for some time now and not just for PHP.
1
u/inchereddit Dec 18 '25
This is nothing more than an advertisement trying to disguise itself as a post.
1
u/sachingkk Dec 18 '25
I just use WSL. It takes some time to figure things out initially, but once done, it works without any issue.
Here is the thing I use
By the way, my virtual host domain has .wsldev extension for all the domains
For some old projects, I also run laragon. I have domain extension for this as .locdev
Hope this helps.
1
u/Mugen0815 Dec 18 '25
I simply use docker under WSL with VSCode. When I need local SSL, I add DDEV.
1
u/kanine69 Dec 18 '25
I've been using WSL 2 with a roll your own docker-compose and Dockerfile for my needs. Lately doing a lot more with Antigravity and it is much happier with this setup than messing about in windows folders.
With sensible volume mappings it was pretty easy removing all the windows file references.
1
u/luctus_lupus Dec 18 '25
just use DDEV, it's great
1
u/SunTurbulent856 Dec 18 '25
On my computer Docker is incredibly slow on Windows, much better on Linux or at least on WSL2
1
u/InfinriDev Dec 18 '25
I just simply use Ubuntu. You can easily install any environment you want without the IP headaches
1
u/TCB13sQuotes Dec 18 '25
No it isn't, and you don't need WSL2 nor containers: https://laragon.org/
Why bother with all the overhead if you don't require anything Linux specific? Just stop making things more complex than what need to be. You can also just download nginx and PHP from their websites and run it on Windows.
1
u/psihius Oct 21 '26
Trust me, in the end the easiest way is to just install Linux and work in it :)
1
u/breich Dec 17 '25
My team works on a local dev environment very similar to what you're talking about. We prepped a VM with a vanilla install of Ubuntu, cloned a repo with our dev environment scripts into it, and exported it out for sharing with the team. When somebody needs a new VM they import the image, give git their keys, pull latest on that repo, and run an install script. In about three minutes they're ready to code.
We haven't gone to Docker primarily because the app we maintain is old and not suited at this point for containerization. We'll make that move once we can realistically make it in prod, too.
1
u/RiWo Dec 17 '25
What's with the problem of:
* download php windows binary from https://windows.php.net/download/
* put the binary into PATH
* then you could run php in the terminal without problem
0
u/Rude_Vegetable_3332 Dec 17 '25
I’ve switched to ddev in traditional mode.
It offers the best of both worlds: the native Windows experience with Docker, without the limitations of WSL. Plus, I can easily drag and drop files without having to go through WSL’s shared folders, which were always a bottleneck for me. The result is a simpler, faster, and less cumbersome workflow.
0
u/Designer_Distinct Dec 17 '25
Check out this which i'm using since past 2-3 years: https://github.com/kodersaeed/wsl_tools
-5
u/mauriciocap Dec 17 '25
Your problem is Micro$oft 😂 To make things worse you demand from volunteers in FREE open source projects to foot the bill for Micro$oft monopolistic theft, almost every laptop buyer is forced to pay for they sh.t even if we install linux as soon as we leave the store.
-5
u/arhimedosin Dec 17 '25
The point is not:" which one is better between Docker and WSL."
The idea is if you want to have a development environment on Windows, then use WSL and a real Linux inside it. And get familiar with PHP, Apache, mariadb, git, nodejs, etc.
In the end we all are eating white bread from programming, so it must be important to know how things are working together.
This is not a post about Docker versus WSL 😀
1
u/[deleted] Dec 17 '25
[removed] — view removed comment