简体   繁体   中英

permission with volume docker and wordpress

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM