0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

最新!Dockerで簡単WordPress環境構築!

Last updated at Posted at 2025-04-09

概要

Docker上にWordPress環境を簡単に構築します。

環境

macOS Sequoia 15.3.1
Docker version 27.5.1
Docker Compose version v2.32.4-desktop.1
nginx 1.27
PHP 8.3
MariaDB 10.11
WordPress 6.7

構成

.
├── README.md
├── environments
│   ├── development
│   │   └── docker-compose.yml
│   └── docker
│       └── nginx
│           └── default.conf
└── web
    ├── index.php
    ├── license.txt
    ├── readme.html
    ├── wp-activate.php
    ├── wp-admin
    ├── wp-blog-header.php
    ├── wp-comments-post.php
    ├── wp-config-docker.php
    ├── wp-config-sample.php
    ├── wp-config.php
    ├── wp-content
    ├── wp-cron.php
    ├── wp-includes
    ├── wp-links-opml.php
    ├── wp-load.php
    ├── wp-login.php
    ├── wp-mail.php
    ├── wp-settings.php
    ├── wp-signup.php
    ├── wp-trackback.php
    └── xmlrpc.php

※ 表示の関係でwp-admin, wp-content, wp-includesの中身は割愛しています。

手順

1. docker-compose.yml作成

docker-compose.yml
services:
  php:
    image: wordpress:6.7-php8.3-fpm
    container_name: wordpress
    restart: always
    volumes:
      - ./../../web:/var/www/html
    environment:
      WORDPRESS_DB_HOST: mariadb
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppass
    depends_on:
      - mariadb

  nginx:
    image: nginx:1.27
    container_name: nginx
    ports:
      - "8080:80"
    volumes:
      - ./../../web:/var/www/html
      - ../docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:cached
    depends_on:
      - php

  mariadb:
    image: mariadb:10.11
    container_name: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: wppass
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

2. nginx設定ファイル

docker/nginx/default.conf
server {
    listen 80;
    server_name localhost;

    root /var/www/html;
    index index.php index.html;

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

    location ~ \.php$ {
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }
}

3. Docker起動

docker-compose.ymlがあるディレクトリにて以下を実行しましょう。

cd environments/development
docker compose up

4. 確認

http://localhost:8080 にアクセスして確認してみましょう。

http://localhost:8080/wp-admin/install.php にリダイレクトされてWordPressの初期設定画面が表示されます。

スクリーンショット 2025-04-09 17.59.53.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?