0

I've recently switched to linux and am trying to set up LEMP myself, which I've managed for the most part, however I've now run into permission problems Ì can't fix. A Local WordPress site cant upload any files.

My Setup

  • php-fpm run as my user
  • nginx run as user nginx
  • Site stored at /home//Websites/example.com

This is for local development only.

/home/my-user drwxr-xr-x
/home/my-user/Websites drwxrwxr-x
/home/my-user/Websites/example.com drwxrwxr-x
/home/my-user/Wbsites/example.com/wp-content drwxrwxr-x

All owned by my-user:my-user

Other than uploads the site is working.


EDIT: The problem would appear to be coming from SELinux. Still not yet sure what to enable in order to fix uploads.

2 Answers 2

1

The issue is not related to filesystem permissions, but it seems to be selinux which blocks the write access to the upload folder.

First set selinux to permissive mode. To do this run as root:

setenforce 0

Then check if the command has been applied correctly by running below which return Permissive:

getenforce

It should now be possible to upload a file to the local upload folder. Once you've completed this check the selinux log for errors. The log file is located in /var/log/audit/audit.log.

Most likely the security context of you're upload folder is wrong. Check the output of:

ls --context

You need to make sure that you have right security context in the upload folder. The folder should have the context httpd_sys_rw_content_t to allow the web server writing to that directory.

2
  • You're right about the context. I added it earlier to my Websites folder to avoid having to set the context for each website's specific folders. Is that dangerous to do even if it's for local development only?
    – Shane
    Commented Mar 30, 2018 at 18:23
  • Being dangerous or not depends on your security requirements. A good approach would be to set the context httpd_sys_content_t for the entire folder and then add the httpd_sys_rw_content_t for the folders which need it based entries in the audit.log file.
    – Philippe
    Commented Mar 30, 2018 at 19:38
0

Try setting the upload dir to 777, then upload a file. Then you'll see what user is creating the files.

When you have seen that, you can chown the dir to that user and set appropriate permissions.

On my LAMP system the whole wordpress tree is owned by www-data:www-data.

When I have set that, I can also update/install wordpress plugins.

1
  • Setting it to 777 did not help, so I tried temporarily disabling SELinux and uploads started working. Seems like permissions are not the problem then.
    – Shane
    Commented Mar 30, 2018 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .