TL;DR: you don't need WAMP, or Apache or Nginx in your development environment. And it's not even about docker, just standard installation with protips. 😎
Chocolatey to the rescue
Yes. Because the first thing that significantly changes between Windows and Linux or macOS is the package manager, they have apt, yum, yaourt, homebrew... Windows has nothing by default (but not for long, the future looks bright!).
But here comes Chocolatey. Yes, it's a package manager. Not official, it does not contain all the software you want. But well, it provides already a lot!
For instance, you can install PHP, but also phpMyAdmin and MariaDB (which replace MySQL).
To install Chocolatey, just follow the getting started, or run this command in a terminal (launched in mode administrator).
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Installing PHP
Actual installation
Now you have Chocolatey, we can install PHP. Run this in a terminal in administrator mode (right click on terminal / open as administrator):
choco install php
You probably need to restart your terminal now.
Using PHP directly
You may ask why not installing a webserver like Apache or Nginx as well, the short answer is: you don't need one.
To run your project, use in the terminal the following command:
php -S localhost:1337
-
php -S
will start the PHP server (for development only) -
localhost:1337
represents the host and the port to listen on, if you want to expose the server you will probably need to use0.0.0.0:1337
- The server points to the current directory by default, use the option
-t
to specify a folder
You access your website on http://localhost:1337! ✨
If you're using a router (a single entry point like many frameworks nowadays), you can also specify one:
php -S localhost:1337 index.php
Bonus track: install composer
Composer is the package manager of PHP. And guess what, it's also available in choco!
In a terminal as administrator:
choco install composer
Installing MariaDB
Just like PHP. It is super-super-easy, open a terminal in administrator (or use wsudo 😎) and type:
choco install mariadb
You're all set. MariaDB is now available on your computer.
Installing phpMyAdmin
Installation
MariaDB will work with PHP as a replacement for MySQL perfectly. You can also use any MySQL client for that. For example, you can use PHPStorm internal client or MySQL Workbench!
But most of us are used to a very specific client (which is incredibly simple to use): phpMyAdmin.
Let's install it, it's just like the 2 previous tools!
choco install phpmyadmin
# Do not forget to run it as administrator
Configuration
phpMyAdmin requires some PHP extensions to be enabled before it works. This is documented in the readme of the package.
Go in the install directory of PHP (for me it's C:\Tools\php...
), you can find it with the command php --ini
. And copy/paste php.ini.development
to php.ini
.
Now edit this file and add (or uncomment) the following lines:
extension=mysqli
extension=openssl
Running phpMyAdmin
You're all set. Just run the phpMyAdmin command (it runs a php server for you!), in your terminal type the following:
phpmyadmin
And that's all folks! You have setup a complete workspace to build an application in PHP that uses MariaDB with phpMyAdmin client for MySQL! ✨
You can now access phpmyadmin in your browser on http://localhost:3333.
Ok, and why not WAMP?
WAMP is old. Outdated. For example, you can't even get the very last version of PHP with WAMP.
But it also adds a webserver (apache), the default configuration is not bad to learn PHP, but when it comes to run modern applications... Well, it becomes a pain to configure properly.
The method I explain here is easy but also has a serious advantage: you understand what you're doing (when WAMP is a complete package with a complex overhead).
Hope you like it. 👋
Top comments (4)
You are right that you don't need wamp, but it helps you set up your development environment very easy.
I'm doing a lot of different projects and setting up localhosts is much easier than running a php process in every folder with different ports.
About wamp being not able to run the last version of php, that is just plain wrong. sourceforge.net/projects/wampserve... Last version is php 8.0.6, which is released on the sixth of may.
I do agree with you that a developer should take time to learn how to set up a server just to get to know what are al the parts involved getting a website running.
After you done that exercise a few times use the tool that lets you focus on the part of making a website that you really want to dive into.
My bad the wall website was not up to date ! :)
For the rest, it seems really quite easier to me to avoid running multiple projects with the setup I suggest.
Besides there may be an issue: you can't install many versions of PHP with chocolatey. At this state of things I'd recommend to use wsl and docker.
You don't have to install php versions through chocolatey. Wamp provides them as addons.
It is good to have the same environment than the server, which is what docker is good at. But then you will have to learn everything about virtualisation too to avoid all the pitfalls.
With wsl you have to manage a separate OS, it is docker without the virtualisation. Another OS can be a big step for some people.
If you don't like wamp, that is fine. It would be nice to keep to the facts, the maintainers work hard to provide us with a easy configurable package and as up to date options as possible.
Wsl is great, but that's not what it is about here. It's standard windows stuff, but as you do not use the lamp package on Linux... I suggest to not do it on windows as well :).