Home > other >  Set a path for the Wordpress files for Wordpress docker image
Set a path for the Wordpress files for Wordpress docker image

Time:01-23

I'm using the following docker-compose file to run multiple wordpress files on different domains using caddy.

version: '3.1'

services:

  wordpress:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp/wordpress:/var/www/html/testwp/wordpress

  wordpress2:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db2
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp2/wordpress:/var/www/html/testwp2/wordpress

  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./caddy/sites:/var/www/html
      - ./caddy/caddy_data:/data

  db:
    image: mariadb
    container_name: database
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

  db2:
    image: mariadb
    container_name: database2
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db2:/var/lib/mysql

volumes:
  db:
  db2:

With this caddy file:

testwp.domain.nl {
        root * /var/www/html/testwp/wordpress
        php_fastcgi wordpress:9000
        file_server
}

testwp2.domain.nl {
        root * /var/www/html/testwp2/wordpress
        php_fastcgi wordpress2:9000
        file_server
}

This works, I get 2 wordpress installs, but I need to manually add the wordpress install files (wget https://wordpress.org/latest.tar.gz) to ./caddy/sites/testwp/wordpress and ./caddy/sites/testwp2/wordpress. This is because the wordpress docker image puts the files in (inside the container) in /var/www/html and if I don't put the files in /var/www/html/testwp/wordpress inside the container, I get a 404 on index.php. This is probably because php-fpm needs to access index.php on the exact same path as caddy? Not entirely sure...

Is there a way to ask the wordpress docker container to put the files in another folder than /var/www/html?

CodePudding user response:

Ok, this combination works, one can set the root for php_fastcgi in the caddy file like this:

testwp.domain.nl {
        root * /var/www/html/testwp/wordpress
        php_fastcgi wordpress:9000 {
            root /var/www/html
                }
        file_server
}

testwp2.domain.nl {
        root * /var/www/html/testwp2/wordpress
        php_fastcgi wordpress2:9000 {
            root /var/www/html
                }
        file_server
}

And then this works, no more double Wordpress files!

version: '3.1'

services:

  wordpress:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp/wordpress:/var/www/html

  wordpress2:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db2
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp2/wordpress:/var/www/html

  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./caddy/sites:/var/www/html
      - ./caddy/caddy_data:/data

  db:
    image: mariadb
    container_name: database
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

  db2:
    image: mariadb
    container_name: database2
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db2:/var/lib/mysql                                               

CodePudding user response:

Ok, this combination works, one can set the root for php_fastcgi in the caddy file like this:

testwp.domain.nl {
        root * /var/www/html/testwp/wordpress
        php_fastcgi wordpress:9000 {
            root /var/www/html
                }
        file_server
}

testwp2.domain.nl {
        root * /var/www/html/testwp2/wordpress
        php_fastcgi wordpress2:9000 {
            root /var/www/html
                }
        file_server
}

And then this works, no more double Wordpress files!

version: '3.1'

services:

  wordpress:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp/wordpress:/var/www/html

  wordpress2:
    depends_on:
      - db
    image: wordpress:6.1-php8.1-fpm-alpine
    restart: always
    environment:
      WORDPRESS_DB_HOST: db2
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - ./caddy/sites/testwp2/wordpress:/var/www/html

  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./caddy/sites:/var/www/html
      - ./caddy/caddy_data:/data

  db:
    image: mariadb
    container_name: database
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

  db2:
    image: mariadb
    container_name: database2
    restart: always
    environment:
      MARIADB_DATABASE: exampledb
      MARIADB_USER: exampleuser
      MARIADB_PASSWORD: examplepass
      MARIADB_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db2:/var/lib/mysql

volumes:
  db:
  db2:

Hooray!

  • Related