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?
The solution
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*
Footnotes
-
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.
Entry Information
- Posted:
- Tue, 5th Dec 2006 at 19:12 UTC
- Filed under:
- Tags:
Comments
skip to comment formI just wanted to react to the "local server under apache2"-article.
Your solution is insane. There is a good reason why not everything has 777, it is because only the admin should have certain rights. It is Ubuntu's policy to seperate the every day use and the root-rights so in every day usage you cannot destroy sth by accident. (At least that's how I understand it.)
It would be much wiser to give 777 only to the files that are supposed to be used through apache, so the rest stays secure.
Perhaps I was not clear, when I CHMOD’d the root folder, of course I mean the site’s root folder, and not the ubuntu root folder (which really would be insane). I am well aware of how Linux security models work with regard to user privileges, and on a live server I'd have done a little additional research into CHMOD codes, but for a local testing machine CHMOD 777 did exactly what I needed it to do.
My main point was that when Ubuntu created the new site’s root folder, the permissions on it were so restrictive that my test site wouldn't run at all. The permissions on the contained files were all fine - the folder was not. The solution was to change permissions to be less restrictive - for my particular case, the 'grant everyone everything' 777 combo worked well and I'm perfectly happy with the security implications of that (because it's on a local machine and there's no one else who uses it anyway). It'd be nice to know what CHMOD you'd recommend using instead though.