Permissions Fix for public_html and Apache2 Userdir Module


Here is the script that can be used to fix the apache2 user to have access to a users public_html folder and make changes.  This issue arises sometimes when you use applications like WordPress that when adding plugins and/or themes will need to be able to modify or add files to the site.  If you get a prompt asking you to enter in the FTP information.  Put the following code into a script file, ie


sudo adduser $USER www-data
sudo chown -R www-data:www-data /home/$USER/public_html
sudo chmod -R 775 /home/$USER/public_html

After you save this file you then need to chmod +x the file so it becomes executable.  After this if you ever need to fix your permissions you can just run ./ and it will make sure you are added to the www-data apache group, then make sure the public_html folder has the proper user:group permissions, and lastly it will modify the public_html folders permissions so that user and group have write permissions.

This is how I implemented it on my Ubuntu server running Apache2.


Posted on

November 4, 2015

Submit a Comment

Your email address will not be published. Required fields are marked *