skip to Main Content

I’ve created a docker-composer.yml file to run a container for wordpress mysql and phpmyadmin. It starts well bt i have a permission problem. All my files have www-data:www-data for user and group and when i want to create a new theme in wp-content i have a permission denied. Im in ubuntu 18.04.

here is my docker-compose.yml file :

version: '3'

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
     MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password 
    networks:
      - wpsite
  # WordPress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
     - '8000:80'
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:

i tried to change to “chown -Rf myname:myname .” so there i can create a file but upload for files in wordpress doesn’t work now. So i wonder how to set properly permissons with a docker mounted volume in ubuntu.

2

Answers


  1. One solution for this would be to add your own user myname to the www-data group

    sudo usermod -aG www-data myname
    

    and make sure the www-data group has write privileges on all files/directories and execute privileges on directories.

    Another solution would be to let your own user own all files (myname:www-data as owner) and directories and make sure www-data group has appropriate read/write privileges so the WordPress container’s webserver can use the group privileges to read/write files.

    Off-topic: also make sure to have a

    define('FS_METHOD', 'direct');
    

    line in your wp-config.php.

    Login or Signup to reply.
  2. I just add user: 1000:1000 to container, and everything works fine. Got idea from this tutorial

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search