How to setup dev PHP/MariaDB (MySQL) environment on Windows
Tags: php, windows, webdev, beginners
Published: 2021-05-06 09:48:52

---
title: How to setup dev PHP/MariaDB (MySQL) environment on Windows
published: true
description: WAMP is an old tool and Linux has no LAMP for a reason: installing PHP with MySQL and so on should not be a pain. And with the new tooling on Windows... Well, it's actually super easy to install all the tooling for web development with PHP by yourself.
tags: PHP, Windows, webdev, beginners
//cover_image: https://direct_url_to_image.jpg
---

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. :sunglasses:

# 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](https://devblogs.microsoft.com/commandline/windows-package-manager-preview/)!).

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](https://community.chocolatey.org/packages/php), but also [phpMyAdmin](https://community.chocolatey.org/packages/phpmyadmin) and [MariaDB](https://community.chocolatey.org/packages/mariadb) (which replace MySQL).

To install Chocolatey, just follow the [getting started](https://chocolatey.org/install), 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
```

1. `php -S` will start the PHP server (for development only)
2. `localhost:1337` represents the host and the port to listen on, if you want to expose the server you will probably need to use `0.0.0.0:1337`
3. 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](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](https://getcomposer.org/) is the package manager of PHP. And guess what, it's also available [in choco](https://community.chocolatey.org/packages/composer)!

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](https://community.chocolatey.org/packages/wsudo) :sunglasses:) 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](https://github.com/Nek-/choco-phpmyadmin#php-configuration).

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! :sparkles: 

You can now access phpmyadmin in your browser on [http://localhost:3333](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. 👋