Uh oh!
There was an error while loading. Please reload this page.
Make already existing files owned by current user - #474
Conversation
tianon
commented
Feb 28, 2020
We used to do this, and it was reverted intentionally (#74) because it causes massive issues for folks who are doing things like local development of WordPress themes / plugins. Now that we can run as an arbitrary user, perhaps that can be reconsidered (and we'd then instead recommend that development users run as their own UID instead, thus avoiding the problem). |
Thank you @tianon for looking at my PR. From what I see, the PR you mentioned (#74) actually ensures that files in the The goal of this PR is to make sure that existing files in Having the Plus I think that the rule of checking whether the If needed I can expose more the issues that I encountered when I have the |
michaelperrin
commented
Mar 4, 2020
Just as a side note, I would add that changing the file permissions inside the container changes them also on the host, which can make file manipulation on the host harder to manage. |
freechelmi
commented
Mar 16, 2020
Thanks @michaelperrin does this fix the "installing plugin failed : cannot write to directory " issue that I face when running 5-fpm ? |
michaelperrin
commented
Mar 16, 2020
@freechelmi Just to be sure, do you install plugins via WP-CLI or the web interface? And which folders do you share between the host and the container? In either case, that should fix the issue. I can make the test for you if you wish. |
freechelmi
commented
Mar 17, 2020
@michaelperrin : Yes Web interface , and we mount wp-content , see our dc |
thomasplevy
commented
Mar 31, 2020
hey @michaelperrin I've been struggling with this particular issue for a really really long time. I develop a WordPress plugin and I really need a solid docker solution so that I can start reliably adding e2e tests into my testing workflows. I'd like to try this solution out but I can't figure out how to run your image locally to see if this works. Any recommendations on how I can try this PR out to see if it helps my situation? |
matzeeable
commented
Mar 31, 2020
Hi @thomasplevy ! Just stumpled over your comment as I have subscribed this thread - waiting for a solution, too. I have workaround'd this - I think it is not a workaround, more a possible solution: Put an additional script after you run your WordPress container, as you can see here: It allows you to run E2E tests without any problem in your CI: https://gitlab.com/devowlio/wp-reactjs-starter/-/jobs/492094866 Perhaps you are interested in our open source boilerplate: WP React Starter |
thomasplevy
commented
Mar 31, 2020
@matzeeable oh man thank you so much. This is a really simple and elegant solution! |
shahariaazam
commented
May 8, 2020
Is there any update of this PR? Is it going to be accepted or not. This is causing few questions on SO. |
lucastercas
commented
May 18, 2020
To any one going through the same problem, create a new image for production, but dont FROM wordpress:5.4.1-apache
COPY --chown=www-data:www-data ./src /usr/src/wordpress/wp-content/themes/foo_theme
EXPOSE 80 443This way, when the However, if doing things this way, you volumes:
- wordress:/var/www/htmlIf you do this, your plugin wont update, because it will use the version that is on the volume. |
This PR makes all already existing files in the
/var/www/htmldirectory owned by thewww-datauser instead ofroot.Issue description
It is a problem that has been mentioned several times here on GitHub (see #436 and #358) and on StackOverflow.
The problem happens for example when sharing a folder into the wp-content WordPress folder, like in this Docker Compose example:
Running these commands:
Will result in a list like:
The wp-content (which has been created by Docker when sharing the volumes) folder belongs to the
rootuser instead of thewww-datauser.Why the issue is happening
Docker creates the shared folder before WordPress is installed into the
/var/www/htmlfolder.The
docker-entrypoint.shscript is executed after and checks whether the/var/www/htmlfolder already exists, and if so, fixes user ownership of it:The test is not relevant anymore. Since PHP 7.x, the Docker images create a
/var/www/htmlfolder that already belongs towww-data, meaning that the condition will never be met. You can check this by running this:Result:
Same command for PHP 5.6:
Result:
Changes made
The following changes were made:
/var/www/htmlroot ownership.