How can I make my public directory writable by nginx and user? [closed]

I have my WordPress site newly hosted on a small Linux box with Nginx. Nginx runs as the user www-data just like apache, so I have the entire public_html directory owned by www-data so that WordPress can upload media files, install new plugins, etc.

My question is how can I setup the public_html directory so that a user logged in via SFTP can upload or edit files? I tried doing

chown -R myUserName:www-data public_html 

but that didn't work.


One thing is setting the owner and group - but you need to define whether or not the user and/or group can write.

This will do what you are asking

find /path/to/public_html -type d -exec chmod 775 {} \;
find /path/to/public_html -type f -exec chmod 664 {} \;

However, you don't want your webserver to be able to write to everything on a Wordpress installation.

You want to figure out exactly what directories you need to be writable by reading the Wordpress hardening guide

If you do not do this, rest assured that your site will be hacked at some point. Not necessarily defaced or changed, but attackers often just use a little space on your site to store a phishing page - which can be a pain to fix.