Archive

Archive for March, 2009

Easy Apache VirtualHost config

March 15th, 2009 1 comment

Like most of the word I use Apache to serve up both my live and test websites.

The downside to having a box for development though is the constant config of apache to host these sites, most of which require absolute links (e.g. ‘/css/style.css’) to function.

The Apache snippet below sets up dynamic sub-domains which can be changed without reloading Apache every time you add, remove or update anything something. Simply drop your sites inside /var/www whenever you want a new subdomain. Alternatively you can symlink if they are hosted elsewhere on the box.

Its pretty easy to install, simply paste the below in your /etc/apache2/apache.conf file…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Easy virtual host config
# See http://hash-bang.net/2009/03/easy-apache-virtualhosteasy-apache-virtualhost/
<VirtualHost *>
DocumentRoot /var/www/
ServerAdmin admin@localhost
Options +FollowSymLinks -Indexes
LogLevel debug
ServerAlias localhost
ServerName localhost
RewriteEngine  on
RewriteLogLevel 3
RewriteCond    %{HTTP_HOST}  ^localhost
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^www.*
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^(.*)\.localhost
RewriteRule    ^(.*)$        /%1/$1 [L]
</VirtualHost>

Now add your servers to the /etc/hosts file:

127.0.0.1      server.localhost

Now any directory you place in the /var/www directory automatically becomes a subdomain. You can now visit http:///server.localhost as a fully fledged webhost.

If you want to use another name than the rather boring ‘localhost’ simply replace the text in both text pastes above.

If only there were a way of removing that /etc/hosts hack it would mean zero config from then on. If anyone has any ideas do let me know. The addition to the hosts file seems to need applying if you are working from the same box the Apache server resides on. If you arn’t and the box is a local dedicated server its not needed at all and domains can be added and removed as necessary.

Categories: HowTo's Tags: , ,

Trash with Bash

March 4th, 2009 6 comments

One of the regrettably unavoidable aspects of the Unix shell like environments is the impedance between what a user says and what a user means. While this is present in all computing environments the sheer power of Unix based command lines make a potential mistake catastrophic.

Who amongst us has not at some point done something like:

> rm * .tmp

or

> rm *>tmp

The former makes the mistake of a space between the dot and the ‘tmp’ part and the latter the accidental holding down of the shift key while pressing the intended full stop.

While searching for an alternative for the I-have-done-this-too-many-times-and-now-its-embarrassing approach of nuking everything with the ‘rm’ command its time i did something about it.

Inserting the following in your ~/.bashrc file will remap the ‘rm’ command to a slightly safer move-to-trash like behavior. Its not comprehensive but it has saved my life on more than one occasion.

?Download .bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
# Trash support by Matt Carter <m@ttcarter.com
# Source and information: http://hash-bang.net/2009/03/trash-with-bash
function trash() {
	if [ -d "$HOME/.trashcan/$1" ]; then
		# Already exists in bin - remove
		rm -r "$HOME/.trashcan/$1"
	fi
	mv --target-directory=$HOME/.trashcan/ -- "$@"
}
alias "rm=trash"
alias "emptytrash=/bin/rm -rf $HOME/.trashcan/* $HOME/.trashcan/.??*"
alias 'rm!=/bin/rm -r'
mkdir ~/.trashcan 2>/dev/null

Now the command ‘rm’ moves files into ~/.trashcan. You can also use the command ‘rm!’ when you really mean delete immediately and the utility command ‘emptytrash’ to clean everything out.

Categories: HowTo's Tags: ,