0

I run Linux Mint, with Apache2, PHP and MySQL. I've activated modules for Apache so that users' public_html can be used and that PHP-scripts can be run from them. I installed WordPress in my public_html (i.e. ~/public_html/wordpress), but it didn't work fully.

When I tried to change the background image or the header image, I got an error message that stated that a directory (either year/month or month/year) - where uploads are stored - could not be created.

Obviously my web server doesn't have permission to create directories - and probably not to create files - in public_html or its subdirectories (like some directories under ~/public_html/wordpress).

I'm therefore wondering what my options are here. Is there some module I must add or some config file I must fix, so that the web server can write? Or must I perhaps change the owner and/or group of public_html - and its subdirectories (is there a way to ensure that subdirectories belong to the same owner/group)? ...obviously without locking me out from making changes to my webpage. Suggestions, advice and best practices very welcome.

I know I probably would get less trouble if I installed WordPress as root under /var/www, but I would prefer to avoid that solution.

  • Have you checked logs? Also are you using vhosts? If you are using UserDir public_html in httpd.conf? Is your DocumentRoot correct? I don't see anywhere you explained your configuration. – Valentin Bajrami Aug 8 '13 at 10:11
  • I'm just running this "locally" as a test on my home computer, so no vhost or anything. I have not changed httpd.conf, just added a link to UserDir among used modules under /etc/apache2 and commented out the lines preventing php-script from executing from users' dirs. localhost, localhost/~myname and localhost/~myname/wordpress all return content... wordpress just can create directories and files under ~/public_html/wordpress. – Baard Kopperud Aug 8 '13 at 12:38
1

Obviously my web server doesn't have permission to create directories - and probably not to create files - in public_html or its subdirectories (like some directories under ~/public_html/wordpress).

This is indeed very likely to be the problem. However you don't have to lock yourself out of the directory: there are many options that allows you to keep the files in that directory and allow the web server to write to it:

  1. Put yourself in the www-data group: sudo gpasswd -a $(whoami) www-data, and then change the group of the public_html directory: sudo chown -R $(whoami):www-data ~/public_html. This way both you and the web server will share that directory.

  2. Using the sticky bit: this will allow the web server to write files to the directory while also carrying the group of the folder, allowing you to still access the uploads directory as your user: chmod g+rws,o+rwx ~/public_html/wordpress/wp-content.

  3. Use ACLs to specify advanced permissions to allow the server to write to the directory: setfacl -m u:www-data:rwx ~/public_html/wordpress/wp-content. If you go that route, I recommand reading the manual for the ACLs as they are quite powerful and there's a lot you can do with them.

Warning

Note however that none of the above solutions are really well suited for a production environment, as all of them will allow any user on the server that's allowed to run PHP code will also have web server permissions and thus could drop malicious files in your uploads directory. Make sure to only make the uploads directory writable, and also make sure to put a .htaccess that disallows any code execution from that uploads directory. For production servers, I recommend running PHP as the user's system user using suexec, php-fpm, or any other way to execute the PHP code outside of the web server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.