5 reasons I moved from XAMPP to Docker for WordPress development
Tags: wordpress, docker, dockerenv, productivity
Published: 2023-05-10 14:43:51

At the moment I am writing this post, I have been working with WordPress for almost 8 years. Some of this time, as a freelancer, and back then 2015 I started to work using [XAMPP](https://www.apachefriends.org/) to set up my developer environment.

**XAMPP** is a free and open-source cross-platform web server, primarily used to locally develop web applications. Turns out, that despite the easy setup and installation of files, **XAMPP is limited in some aspects that Docker isn't**.

After developing and testing a project with XAMPP on your machine, it will have to be deployed in a real server at some point. While working with XAMPP you'll need to do a lot of work to ensure that PHP versions, extensions, and configuration are the same on your machine as in the server.

This process can be very frustrating and can **sometimes result in sites just not working as you expected**.

The other problem is that **XAMPP makes us lazy**, as it is very easy to install, it gives you zero knowledge of how a web server is actually configured. I advocate for everyone to set PHP, MySQL, and all stuff apart, at least once, to understand how things work, but this is a subject for other articles.

On time, it's very common to find in forums online questions like "How do I use PHP 7.4 in XAMPP?, "How can I run two different PHP versions?" and etc. But if you want to work in a more modern and straightforward way, with remote teams for example, the **right question should be "Is XAMPP the right tool?"**.

It was making this question that **I discovered Docker**. By definition, [Docker](https://www.docker.com/) is an open platform that enables developers and system administrators to create distributed applications. With it, you can upload the entire application, code, and configurations, and **the site will run exactly the same on the server** as it does on your development machine. It is the **end of the "it works on my machine" problem**.

Docker can handle lots of repetitive configuration tasks and is used throughout the development lifecycle for fast and easy application development. 

Below is **my current Docker WordPress environment**, with [WP-Cli](https://wp-cli.org/) and [phpMyAdmin](https://www.phpmyadmin.net/). The complete [repository available here](https://github.com/sarahcssiqueira/docker-wordpress).

```
//docker-compose.yml
version: '3.9'

services:

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE_NAME}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_RANDOM_ROOT_PASSWORD: 'root'
    volumes:
      - ../db:/var/lib/mysql
    
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    depends_on:
      - db
    ports:
      - "8080:80"
    environment:
      PMA_HOST: db
      PMA_USER: ${MYSQL_USER}
      PMA_PASSWORD: ${MYSQL_PASSWORD}

  wordpress:
    build: .
    restart: always
    depends_on:
      - db
    ports:
      - ${WORDPRESS_PORT}:80
    environment:
      PHP_EXTENSION_XDEBUG: 1
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE_NAME}
    volumes:
      - ../wp-core:/var/www/html/
      - ../plugins:/var/www/html/wp-content/plugins
      - ../themes:/var/www/html/wp-content/themes
      - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini

  wpcli:
    image: wordpress:cli
    depends_on:
      - wordpress
      - db
    volumes_from:
      - wordpress
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE_NAME}
    user: xfs
    entrypoint: wp
    command: --info
```


## Finally, the 5 reasons why I changed from XAMPP to Docker.



1. **Isolation:** Docker allows you to break your app down into separate microservices, each containing its own function. These services are independent and can be easily isolated from each other.

2. **Portability:** Developing inside containers brings independence from the OS (Mac, Windows, or Linux) you’re using and makes your apps portable. 

3. **Sharing:** You can package the environment with the application, pack the app and its dependencies, and transfer it to another machine(s) with different hardware and OS setup, and still, the containers guarantee you’re running the same services (versions, configurations, etc).

4. **Highly configurable:** You can configure containers with docker-compose files to meet your particular needs (e.g., I added phpMyAdmin and WP-CLI to my WP environment).

5. **Open source:** there is a lot of support in the community.

I am not saying that you must change the whole workflow you are used to, but I believe you really **should give Docker a try.**

Be free to [clone my environment](https://github.com/sarahcssiqueira/docker-wordpress), or even suggest improvements trough pull requests on Github, or in the comments below.