Setting up a new site on a local server under Apache2
I run Ubuntu on my desktop machine, and use it as a development environment in addition to all the other desktop tasks you would expect a normal computer to do. To that end it has Apache2, PHP5, and MySQL5 running on it, and sitting on http://mwdev is a version of my website identical to the one you see here - but running on my local machine and not on the web. Two days ago I decided it was time to create a new development site ready for a project I have in mind. Somehow, such a simple thing as creating a new site under Apache2 took until right now to set up, after tearing my hair out for two solid evenings wondering why the damn thing wouldn’t work.
To set up the site I went into the
/etc/Apache2/sites_enabled/myconfig file and duplicated the existing VirtualHost entry for my mwdev site, amending the DocumentRoot, Directory, and ServerName variables accordingly. That, in my mind, was ‘job done’. I restarted Apache2 with a quick terminal command:
/etc/init.d/apache2 restart, opened up Firefox and entered the new url … only to end up on Google. Rookie mistake number one - I’d forgotten to edit the hosts file. After an hour of confusion I remembered that Ubuntu, smart as it is, is not psychic. If you don’t tell it that a url actually points to the local machines server, it’s going to go looking for the URL on the internet. I berated myself for forgetting something so obvious, added the single line required in the
/etc/hosts file, restarted apache2, and refreshed my browser. Server Misconfiguration error. More data may be available in the error logs, so said the page. So I looked in the site error log and saw the following:
[Tue Dec 05 18:30:55 2006] [error] [client 127.0.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
Mod re-write?! But the directory was empty except for a simple ‘hello world’ html file. Why was it trying to do re-writes? So, I whacked in a .htaccess file that explicitly turned the ReWrite engine off. And got the next error:
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Warning: Unknown: Failed opening ‘/blahblah/’ for inclusion (include_path=’.:/usr/blahblah/’) in Unknown on line 0
From here I spent two long evenings trying to sort out what might be wrong. Why my mwdev site still worked fine, but the new one didn’t?
To cut a long story short, there wasn’t any problem with my config files. I’d commited rookie mistake number two by not checking the permissions on the new site folders. Now, I have no idea why Ubuntu set restrictive permissions on them by default, but it had. A quick
CHMOD 777 on the rootf.1 folder fixed everything. Two evenings of headache - ten seconds and a single command to fix. *sigh*
To clear up any potential mis-understanding, I mean the website root folder, and not Ubuntu’s root folder. As pointed out in the comments, it would be very bad indeed to chmod 777 the system’s root folder.