Install WordPress running on Caddy Server using Docker Compose
ServerVirtual Private ServerWordpress

Install WordPress running on Caddy Server using Docker Compose

After a long time setting up WordPress on OpenLiteSpeed ​​Server using Docker Compose, recently I have gradually moved all the WordPress websites I am managing to operate on Caddy Server.

That’s the reason for today’s article: instructions on how to install WordPress + MariaDB running on Caddy Server using Docker Compose.

I. Preparation requirements

To follow the steps in the article, you need to prepare the system as follows:

  • VPS installs Linux operating system: CentOS / Debian / Ubuntu. You can also install on Windows / MacOS / Raspberry Pi, as long as the operating system supports Docker.
  • VPS has Docker and Docker Compose installed. See instructions here.
  • VPS has Caddy installed as web server. See instructions here.

II. Install WordPress

Create a new folder called wordpress, then create a file compose.yml in this folder

mkdir ~/wordpress
cd ~/wordpress
nano compose.yml
Code language: Bash (bash)

Enter the following Content

services:
  wordpress:
    image: wordpress:fpm-alpine
    container_name: wordpress
    restart: always
    depends_on:
      - db
    volumes:
      - ./html:/var/www/html
      - ./custom.ini:/usr/local/etc/php/conf.d/custom.ini
    env_file: .env

  db:
    image: mariadb:10.11.6-jammy
    restart: always
    volumes:
      - ./mysql:/var/lib/mysql
    env_file: .env
Code language: YAML (yaml)

Create additional .env file

nano .envCode language: CSS (css)

And enter the following content, and should change the content of the parameters after the comma. = for optimal security.

## MYSQL ##
MYSQL_USER=siteuser
MYSQL_PASSWORD=sitepassword
MYSQL_DATABASE=wordpress
MYSQL_ROOT_PASSWORD=rootpasswordCode language: Shell Session (shell)

Activate WordPress

docker compose up -dCode language: Nginx (nginx)

III. Configure Caddy as Reverse Proxy

The instructions in this section only apply if you install Caddy using Docker following the instructions here.

1. Connect Caddy to the same network as WordPress

Check what the current network of the WordPress container is using the command

docker container inspect wordpressCode language: Nginx (nginx)

In the Networks section at the bottom, you will see the network name. wordpress_default

            "Networks": {
                "wordpress_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": (
                        "wordpress",
                        "336a69c38146"
                    ),
                    "MacAddress": "02:42:ac:1a:00:03",
                    "NetworkID": "8a7f38c640194a8fe70dc0922f4120ee4c2d72a352ec63a3fb412da4e41c441a",
                    "EndpointID": "27a946ef2774f455b70c3b062053aa93f30c12519af1f4b939a360c951e56899",
                    "Gateway": "172.26.0.1",
                    "IPAddress": "172.26.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DriverOpts": null,
                    "DNSNames": (
                        "wordpress",
                        "336a69c38146"
                    )
                }
            }
        }
    }
)Code language: JavaScript (javascript)

Edit file compose.yml of Caddy, add the following at the end of the file. The purpose is to connect the caddy container to the same network as the wordpress container

networks:
  default:
    name: wordpress_default
    external: trueCode language: YAML (yaml)

3. Declare volumes

In addition, you need to edit the volumes section in the file. compose.ymladd the following line

  - ../wordpress/html:/var/www/htmlCode language: JavaScript (javascript)

File compose.yml after editing will look like this

services:
  caddy:
    image: caddy:2.7.6-alpine
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./caddy_data:/data
      - ./caddy_config:/config
      - ../wordpress/html:/var/www/html

networks:
  default:
    name: wordpress_default
    external: trueCode language: YAML (yaml)

3. Update Caddyfile

Add the following to Caddyfile, replacing domain.com into your domain name.

domain.com {
	root * /var/www/html
	encode zstd gzip

	# Serve WordPress PHP files through php-fpm:
	php_fastcgi wordpress:9000

	# Enable the static file server:
	file_server {
		precompressed gzip
	}
	header / {
		X-Frame-Options "SAMEORIGIN"
		X-Content-Type-Options "nosniff"
	}

}Code language: PHP (php)

4. Restart Caddy

Restart Caddy with the following command

docker compose up -d --force-recreateCode language: Nginx (nginx)

If all goes well, you should be able to access the address. https://domain.com to install WordPress.

That’s it. Happy installation!

If my article provides useful information and knowledge to you, don’t hesitate to invite me for a beer to have more motivation to share more. Thank you!

Comment Policy: We truly value your comments and appreciate the time you take to share your thoughts and feedback with us.

Note: Comments that are identified as spam or purely promotional will be removed.

To enhance your commenting experience, consider creating a Gravatar account. By adding an avatar and using the same e-mail here, your comments will feature a unique and recognizable avatar, making it easier for other members to identify you.

Please use a valid e-mail address so you can receive notifications when your comments receive replies.

Related posts

Install Caddy Server – Modern, easy-to-use Web Server

Mark Lee

Manage WordPress with WP-CLI command line

Mark Lee

LCMP Minimal : Debian – Caddy – MariaDB – PHP for markknow.com

Mark Lee

2 comments

PrivateProxies September 19, 2024 at 9:25 am

Good post. I study something tougher on different blogs everyday. It’s going to all the time be stimulating to read content material from different writers and follow somewhat one thing from their store. I’d prefer to make use of some with the content on my weblog whether or not you don’t mind. Natually I’ll offer you a hyperlink on your net blog. Thanks for sharing.

Reply
Mark Lee September 23, 2024 at 1:42 am

Thank you for your kind words! I’m glad you found the post stimulating. It’s true—diving into content from various writers can be both enlightening and inspiring. As for using some of the material on your own weblog, that sounds like a great idea! Just remember to give credit where it’s due and provide a link back to the original source—it’s a respectful way to acknowledge the work of others.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More