Thursday, August 14, 2008

Self Hosted: Getting Started

This is the first post in a series of posts I'm planning about self hosting: the act of hosting your own web server.

Self hosting requires a computer and an Internet connection that's on most of the time, some software (webserver and probably a database and other stuff), an account with one of the dynamic address service providers (such as No-IP and DynDNS), and last but not least: lots of free time.

In each of the following posts in this series, I'll present a specific type of website: a plain static website, Foxmarks bookmarks server (WebDAV), Gallery2 (multi-site), WordPress, Gitweb, and a CUPS proxy site.

I'm no webmaster - my experience in web hosting is limited to what I've done in the past year and half, which isn't much. Nevertheless, it's work that begs to be documented. Please don't be shy: corrections and suggestions are welcome!

I'll start with a plain static website, so as to demonstrate the steps needed to install it. I'm using Apache2 as my webserver - the default on a Debian system (if it's not installed, just type aptitude install apache2 as root).
  1. create a directory (or a symlink to a directory): /var/www/plain
  2. create a file /var/www/plain/index.html:
    <html><body>Hello World!</body></html>
  3. create a new configuration file /etc/apache2/sites-available/plain with the following contents:
    <VirtualHost *:80>
    ServerName example.no-ip.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/plain
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log vhost_combined
    </VirtualHost>
    (I've marked in red a fictitious No-IP domain and webmaster e-mail address - please replace with your own stuff).

  4. enable the new website:
    a2ensite plain
  5. reload the webserver:
    /etc/init.d/apache2 reload
A few notes are in order:
  1. the new site should be accessible at http://example.no-ip.com (fake! fake! fake!)
  2. the new site can be disabled with the following sequence:
    a2dissite plain
    /etc/init.d/apache2 reload
  3. Virtual Hosts: other similar sites with different server names can be similarly installed by modifying the ServerName property. The webserver will serve web pages according to the server name used in the URL being accessed - all from the same IP address.

  4. if you're getting the following message every time the server is reloaded or restarted:
    Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
    just add the following line to /etc/apache2/httpd.conf
    ServerName 127.0.0.1
  5. SECURITY: better safe than sorry...

It's your serve(r) now.

No comments:

Post a Comment