www-data group issue with wordpress file permissions
Hi, So I installed wordpress on lamp running on ubuntu 18.04.
Wordpress wasn't able to write so I did the following:
added my user to data group
sudo usermod -a -G www-data myusername
then
sudo chown -R www-data:www-data /var/www/example.com/public_html
Now wordpress can write files but I can write to this directory using sftp though I can write using ssh
Can someone please help me with this, I wasted so much time trying to find a solution on google but to no avail.
Thanks
1 Reply
You write:
Wordpress wasn't able to write so I did the following:
added my user to data group
sudo usermod -a -G www-data myusernamethen
sudo chown -R www-data:www-data /var/www/example.com/public_html
This was like using a sledge hammer to repair fine jewelry! As you found out…
What you should have done is:
sudo chown www-data:sftp /var/www/example.com…
sudo chmod g+w /var/www/example.com…
on the VERY FEW directories that require write access by the web server and sftp (usually those that can receive uploads). sftp above represents the group for sftp.
You should consult the Wordpress docs and find out exactly which directories under /var/www/example.com/… need to writable by www-data and whatever the sftp user/group is and do the above ONLY on those.
Lastly, you should be using correct terminology. "Wordpress" is not a 'thing' on a Linux system…it's a PHP application that runs under the auspices of a web server. The 'thing' is the web server (Apache in your case). Apache has user/group www-data.
-- sw