Current Location: Home> Latest Articles> Deploying a Plugin-Ready PHP Environment with Docker Compose

Deploying a Plugin-Ready PHP Environment with Docker Compose

M66 2025-07-12

Building a Plugin-Ready PHP Development Environment

In modern web development, plugins play a crucial role in extending PHP application functionality. Using containerized deployment, developers can build scalable and flexible environments quickly. This guide demonstrates how to use Docker Compose with Nginx and MariaDB to set up a PHP development environment that supports plugin extension.

Installing Docker and Docker Compose

Start by ensuring Docker and Docker Compose are installed on your system. After installation, verify with the following commands:

docker --version
docker-compose --version

Writing the Docker Compose Configuration

Create a docker-compose.yml file in your project’s root directory with the following content:

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html
    ports:
      - 8080:80
    links:
      - db

  db:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: secret

This configuration defines two services: the PHP application (web) and the MariaDB database (db). Nginx will expose the PHP application to the browser.

Creating the PHP Image Dockerfile

Create a Dockerfile in the root directory with the following content:

FROM php:7.4-fpm
RUN docker-php-ext-install pdo_mysql

This image uses PHP 7.4 and includes the pdo_mysql extension. You can modify it to install other PHP extensions as needed.

Setting Up the Nginx Virtual Host

Create a configuration file named default.conf in your project directory with this content:

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    root /var/www/html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        include fastcgi_params;
        fastcgi_pass web:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

This configuration routes all requests to the PHP interpreter provided by the web service and sets /var/www/html as the document root.

Launching the PHP Environment

In the root of your project, run the following command to start the containers:

docker-compose up -d

This command builds and runs the containers as defined in the docker-compose.yml file.

Connecting to the MariaDB Database

You can use any database management tool such as DBeaver, Navicat, or phpMyAdmin. The connection information is as follows:

Host: localhost
Port: 3306
Username: root
Password: secret

Developing and Deploying Your PHP Application

Place your PHP files inside the /var/www/html directory. The Nginx server will serve and parse them accordingly. This environment supports plugin development, API building, and database integration.

Conclusion

Combining Docker Compose with Nginx and MariaDB offers an efficient way to set up a development-ready PHP environment that supports plugin extensions. By defining key configuration files and services, developers can spin up isolated, customizable environments quickly. This setup is particularly valuable for fast iteration, plugin testing, and collaborative team development workflows.

The configuration is highly adaptable and can be further extended to meet project-specific needs for larger applications or production-like testing environments.