Category Archives: debian

easily creating name based virtual hosts in apache

Check if your /etc/apache2/ports.conf has following two lines

NameVirtualHost *:80
Listen 80

Create two directories in /var/www
# mkdir /var/www/{foo,bar}

These two directories in /var/www/ will serve as a document root for our two test sites foo.com and bar.com respectively

Create index.html file in each of these two directories and put some html code in it.
e.g.
I am foo.com
I am bar.com

Put entries in /etc/hosts
You need to also put 2 entries in your /etc/hosts file since we are testing it on localhost. If you are doing it on a server then make sure you have respective A records in DNS.
Open /etc/hosts in your favourite editor and put following two entries at the bottom of the file without disturbing original contents of file

127.0.0.4 foo.com foo
127.0.0.5 bar.com bar

Just make sure that above IPs are not already in use in same file …if any of them is in use, then for your entries you can
use any IP in 127.x.x.x range.

Create virtual hosts
Now create two files, “foo.com” and “bar.com” in /etc/apache2/sites-available/
Contents of foo.com

ServerName foo.com
ServerAlias http://www.foo.com
DocumentRoot /var/www/foo/


Similarly create bar.com with following content


ServerName bar.com
ServerAlias http://www.bar.com
DocumentRoot /var/www/bar/

Enable newly created sites
# a2ensite foo.com bar.com

Reload Apache
# service apache2 reload OR # /etc/init.d/apache2 reload

Open your browser and put “foo.com” in address bar .. you should be able to see the contents of /var/www/foo/index.html file
Repeat same step for “bar.com” as well to confirm that your setup is working

Enjoy!!

i want more space…

The default Debian installation puts lots of documentation with various locale on /usr. These files are not used most of the time but end up eating lot of disk space.

Debian provides localepurge and deborphan to remove unwanted files from hard disk and to retain disk space.

Installation
# aptitude install localepurge deborphan

Configuration of localepurge
# dpkg-reconfigure localepurge

Cleanup disk space
# localepurge

Following command finds unwanted and independent packages, which are no longer required and removes them
# deborphan

When packages are installed using online Debian repository, APT downloads them and stores all .deb files in /var/cache/apt/archives/. After the installation, generally these files are no more required. Following command cleans up these unwanted files and reclaims disk space.
# aptitude clean

be on time my friends… with ntp

It’s very important to keep your system clock aligned to the exact timezone you reside. Following commands help to keep it in sync.

First select appropriate timezone
# dpkg-reconfigure tzdata

Above command actually copies your zoneinfo file from /usr/share/zoneinfo/ to /etc/localtime
So you can manually copy the file from zoneinfo directory to /etc/localtime on non-debian systems.

Now install following package to sync your system clock with Time Servers using Network Time Protocol (NTP)

# aptitude install ntpdate
# aptitude install openntpd

The ntpdate OpenNTPD keeps on checking time periodically to keep system time in sync with time servers.

OpenNTPD is a secure NTP daemon developed by OpenBSD Developers. (Theo de Raadt you r0ck ;))
You can also install ntp – a local ntp daemon as an alternative to OpenNTPD.

Thanks poisonbit for pointing out that ntpdate is now unmaintained and NTP or OpenNTPD is preferred over it. Check out first comment.