Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix file permissions on wp-content with official wordpress image for docker-compose

Tags:

People also ask

How do I fix file and folder permissions in WordPress?

Fix File and Folder Permissions in WordPress Using FTPOnce connected go to the root folder of your WordPress site. After that select all folders in root directory and then right click to select 'File Permissions'. This will bring up the file permissions dialog box. Now you need to enter 755 in the numeric value field.

What permissions should wp content have?

Generally, WordPress directory and folder permissions should be set to 755, and most file permissions need to be set to 644. These are also the file permissions that WordPress recommends you set for your site.

How do I change file system permissions in WordPress?

Double-click your WordPress folder and find the index. php file. Right-click the file and, once again, select Change Permissions. Set the Permission value to 644 and click OK.


Problem


I'm setting up a Wordpress local environment with docker-compose and the official wordpress image from the docker repository.

I am on windows.

The problem is that I have some premissions issues on the wp-content, and I am not able to upload files from my Wordpress admin panel. wordpress error unable to create directory

What I've already done


I checked then the file permissions inside the container, and this was the output:

file permissions in the wordpress container

As you can see, the owner of my wp-content is root instead of www-data.

The immediate solution is to open the container's bash and give
chown -R www-data:www-data /var/www/html/wp-content/

This of course works, but I don't want to do this process every time I start a new wordpress project. To achieve this I've created a Dockerfile like this:

FROM wordpress:5.1.1  # install dos2unix (fix problem between CRLF and LF) RUN apt-get update RUN apt-get install -y dos2unix  # increase upload limit RUN touch /usr/local/etc/php/conf.d/uploads.ini \     && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini  # fix permissions issues COPY entrypoint.sh / RUN dos2unix /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] 

And my entrypoint.sh looks like this:

#!/bin/bash echo Fixing permissions... chown -R www-data:www-data /var/www/html/wp-content/ 

But then I realized that I was overriding the ENTRYPOINT of the original wordpress image, and the container exited always with code 0.

Then I tried with CMD instead of ENTRYPOINT, and I changed my Dockerfile like this:

FROM wordpress:5.1.1  # increase upload limit RUN touch /usr/local/etc/php/conf.d/uploads.ini \     && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini  CMD chown -R www-data:www-data /var/www/html/wpcontent/ 

But I receive always the error that the file or folder doesn't exists.

I've tried to use CMD also like this:
CMD ["chown", "-R", "www-data:www-data", "/var/www/html/wp-content/"]
but without success.

Question


There is a way to run a command after the original ENTRYPOINT?
Do you know otherwise a better way to solve this problem?