0

I'm using localhost to develop some web pages (LAMP stack, Lubuntu desktop, trusty 14.04).

Each time I create a new folder inside /var/www/html, read privileges seem to be set to owner only by default. This is resulting in a blank white page when I go to localhost/folder-name in my browser.

How can I change things so that the default read privilege is anyone for my localhost projects? I'd like to avoid having to change folder permissions each time I create a new folder.

Flimzy
  • 380

1 Answers1

2

If it's just you creating the websites and no other user needs access to it you can just change the apache config to run the webserver as your user.

in the terminal change the permissions of /var/www/html to your user

sudo chown -R username:username /var/www/html

Then change your apache envvars

sudo nano /etc/apache2/envvars

And change the lines to your user.

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

Restart apache and everything should work correctly without having to mess around with folder permissions.

sudo service apache2 restart

Alternative

You can set the permissions using a crontab, just type crontab -e into the terminal and add this line to the bottom

* * * * * chmod -R 755 /var/www/
FortuneCookie101
  • 325
  • 3
  • 15
  • Thanks for this @FortuneCookie101. Is there an alternative? The reason I ask is because I may have more users than just myself accessing it going forward – henrywright Jan 26 '15 at 17:47
  • @henrywright You could setup a crontab to set the permissions /var/www every minute, I've updated my answer. – FortuneCookie101 Jan 26 '15 at 18:31
  • @henrywright Take a look at the answer for this question it also may help http://stackoverflow.com/questions/580584/setting-default-permissions-for-newly-created-files-and-sub-directories-under-a – FortuneCookie101 Jan 26 '15 at 22:03
  • thanks. So in my case, would that be sudo chmod g+rwxs /var/www/html? I'm not entirely sure – henrywright Jan 26 '15 at 23:22
  • @henrywright yes that's correct, you may need to apply it to existing files first, sudo chmod -R g+rwxs /var/www/html and everything should work – FortuneCookie101 Jan 27 '15 at 09:44
  • Out of interest, does the -R mean the changes will be applied recursively? And I take it g+rwxs are the privileges? Do you know where I could look for more information on them? Thanks again – henrywright Jan 27 '15 at 10:33
  • @henrywright yes, that's correct. http://linuxcommand.org/lts0070.php explains permissions in a bit more detail and http://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work explains umask (g+rwxs etc) – FortuneCookie101 Jan 27 '15 at 14:05