scriptNode

Web development with a focus on JavaScript RSS

Quickly Update DocumentRoot in Apache2

Intermediate Matt Hackett Published August 10th, 2008 by Matt Hackett

For today's Script Sunday I thought I'd take a go back in time a little and provide an old utility that I still to this day find useful. It's a script I wrote called ChangeLocalHost which alters the DocumentRoot in apache2. An example of its use would be:

./clh.php local-site.com/public_html/

Note: you must be root to run it

Given this command, the script will change DocumentRoot to local-site.com/public_html/ and restart apache2. I work on a lot of websites (developing most of them on my laptop running apache2) so I use this script constantly.

Here's the code:

You'll notice that the script is at least a year and a half old. Usually if code of mine is more than a year old, it's completely unusuable because my habits change pretty often. But I think I've finally gotten to that sweet spot where it's not total garbage, it just needs tweaking.

I was surprised that the code isn't too bad really. It's easily readable and well organized. There are many things that I wouldn't have done were I to write this again; for example, I stopped using type prefixes long ago (such as an array of users as $arr_users). I understand why I used to do this, but it's not necessary and only clutters up the code.

Anyway, I find this script useful and I thought someone else might too. Enjoy!

Read other articles tagged: , , , ,

Thoughts?

(required)

(not shared)

© 2010 scriptNode