Wednesday, January 21, 2026

Install WordPress Using Docker

 

In this blog, we are going to configure WordPress using Docker in a containerized environment. We will use Docker and Docker Compose to set up WordPress along with Nginx, PHP, and a MySQL database. By the end of this guide, you will have a fully functional WordPress site running inside Docker containers.


Step 1: Install Docker and Docker Compose

  • sudo apt update && sudo apt install -y docker.io
  • sudo systemctl enable --now docker
  • sudo usermod -aG docker $USER
  • sudo apt  install docker-compose -y


Step 2: Download WordPress and Configure Database Credentials

  • Via Web Browser: https://wordpress.org/download/
  • Via Command Line: wget https://wordpress.org/latest.zip


Step 3: Create Docker Configuration Files for WordPress

a) docker-compose.yml – to define and manage services

version: '3.9'

services:

  nginx:
    image: nginx:stable-alpine
    ports:
      - 80:80
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./wordpress:/var/www/html/:delegated
    depends_on:
      - php
      - mysql
   
  mysql:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: wp
      MYSQL_USER: wp
      MYSQL_PASSWORD: secret
    volumes:
      - mysql_data_vol:/var/lib/mysql

  php:
    build:
      context: .
      dockerfile: php.dockerfile
    volumes:
      - ./wordpress:/var/www/html/:delegated

volumes:
  mysql_data_vol:

 

b) php.dockerfile – to build the PHP environment

FROM php:8.2-fpm

RUN docker-php-ext-install mysqli

RUN docker-php-ext-install pdo

RUN docker-php-ext-install pdo_mysql

RUN docker-php-ext-enable pdo_mysql


c) nginx/default.conf – to configure the Nginx web server

upstream php {
    server unix:/tmp/php-cgi.socket;
    server php:9000;
}

server {
        listen 80;
        server_name wordpress-docker.test;
        root /var/www/html;
        index index.php index.html;

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

        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
        }  
}


Step 4: Inside the WordPress directory, copy the wp-config-sample.php file to wp-config.php and update the MySQL database credentials accordingly.


Step 5: Run the Docker Containers

  • docker-compose config
  • docker-compose up


Step 6: Complete WordPress Setup via Web Browser

http://server-ip/


Step 7: Clean Up the Installation

  • docker ps -a
  • docker stop container-id
  • docker rm container-id
  • docker rmi image-id


No comments:

Post a Comment

testing