2

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 2

1

I just add user: 1000:1000 to container, and everything works fine. Got idea from this tutorial

0

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.

3
  • i've added my user to www-data group but i still have this error. it was well added i checked with "grep ^www-data /etc/group" and the return is www-data:x:33:myname
    – yoyojs
    Mar 10, 2020 at 13:24
  • That's strange. Did you restart your shell after adding the user to the group? Usually, if the group has read/write access it should work fine.
    – Damocles
    Mar 10, 2020 at 13:30
  • Would you please share which one of two solutions you offered is preferrable and why?
    – devellopah
    Jan 6, 2022 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.