Using the following docker compose file I can make a working wordpress site on AWS. Unfortunately I can not add, update or delete plugins. If I change all file permissions in the wordpress directory to 777 everything works. The the new files created are owned by user: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin Simply changing wordpress files to user: www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin does not fix the problem. Any Ideas on how to make this work? thanks. ``` version: "3" services: nginx: image: nginx:latest ports: - 80:80 - 443:443 volumes: - ./wordpress:/var/www/wordpress - ./websites:/var/www/websites - ./nginx-config/default.conf:/etc/nginx/conf.d/default.conf mysql: image: mysql:latest environment: MYSQL_DATABASE: wpdb MYSQL_USER: wpuser MYSQL_PASSWORD: secret MYSQL_ROOT_PASSWORD: secret volumes: - ./dbdata:/var/lib/mysql php-fpm: image: bitnami/php-fpm:latest volumes: - ./wordpress:/var/www/wordpress ```
The issue with file permissions and ownership likely stems from the fact that the user and group under which the PHP-FPM service runs (daemon) do not have the correct permissions to modify the files in the WordPress directory. One solution is to ensure that both the Nginx and PHP-FPM services use the same user and group, typically `www-data`, which is the default for many web server configurations. This can be done by creating a custom Dockerfile for the PHP-FPM service to change the user and group to `www-data`. Here's how you can modify your setup: 1. **Create a custom Dockerfile for PHP-FPM:** ```Dockerfile # Dockerfile FROM bitnami/php-fpm:latest # Change the user to www-data USER root RUN usermod -u 33 www-data && groupmod -g 33 www-data RUN chown -R www-data:www-data /var/www/wordpress USER www-data ``` 2. **Update your `docker-compose.yml` to use the custom PHP-FPM image:** ```yaml version: "3" services: nginx: image: nginx:latest ports: - 80:80 - 443:443 volumes: - ./wordpress:/var/www/wordpress - ./websites:/var/www/websites - ./nginx-config/default.conf:/etc/nginx/conf.d/default.conf mysql: image: mysql:latest environment: MYSQL_DATABASE: wpdb MYSQL_USER: wpuser MYSQL_PASSWORD: secret MYSQL_ROOT_PASSWORD: secret volumes: - ./dbdata:/var/lib/mysql php-fpm: build: context: . dockerfile: Dockerfile volumes: - ./wordpress:/var/www/wordpress ``` 3. **Build and run the Docker containers:** ```sh docker-compose up --build ``` This setup ensures that the `www-data` user has the appropriate ownership and permissions on the WordPress files, allowing the application to add, update, and delete plugins without requiring overly permissive file permissions (like 777).