Sunday, August 31, 2008

Fedora 8 Quickie Apache Web Server Setup (Part I)

Note: Make sure to check the conventions I use before going through the tutorial.

The Apache is default web server bundled in Fedora and other Linux distribution. There's a number of popular runner-up web server such as lighttpd and litespeed but by and large the de-facto web server of choice is Apache.

For this quickie Apache Web Server tutorial, we'll setup the following configuration:
- Home Page for Local users
- Basic User Authentication
- Running CGI Scripts
- Virtual Hosting

Installation Apache web server packages:

# yum install -y httpd httpd-tools
# rpm -q httpd httpd-tools

Test Apache web server:

# firefox http://localhost &
or
# firefox http://www.exampledns.com &
# cd /var/www/html
# echo "Hello world! I'm test driving Apache!" > index.html
# firefox http://localhost &
or
# firefox http://www.exampledns.com &

Note: The http://www.exampledns.com refers to the local DNS domain we've setup here for testing local networking. If you have not setup any, use http://localhost only.

Home Page for Local users

Step 1: Log in as root user, make a backup of httpd.conf and then edit httpd.conf and modify the UserDir parameter, save and exit. Then restart the httpd server.

# cd /etc/httpd/conf
# cp httpd.conf httpd.conf-original
# nano httpd.conf

Find the following line:
UserDir disable
Change it to:
UserDir public_html

# service httpd restart

Step 2: Log in as local user (ie. 'gene') and create the public_html subdirectory. And then change the default permissions:

$ mkdir public_html
$ chmod 711 /home/gene
$ chmod 755 /home/gene/public_html
$ cd public_html
$ echo "This is the homepage of user gene!" > index.html
$ firefox http://localhost/~gene
or
$ firefox http://www.exampledns.com/~gene

Basic User Authentication

Note: In this case, we'll set a password for the home page of local user 'gene'

Step 1: As root, edit the /etc/httpd/conf/httpd.conf file, add parameters for authentication and then restart httpd server:

# cd /etc/httpd/conf/
# nano httpd.conf

<Directory /home/gene/public_html >
AllowOverride AuthConfig

</Directory>

# service httpd restart

Step 2: As root, set the password authentication for the local user (ie. gene).

# cd /etc/httpd/conf
# htpasswd -mc webpasswd gene
# chgrp apache webpasswd
# chmod 640 webpasswd

Step 3: Create the .htaccess config file in the directory where the web page is located.

$ cd /home/gene/public_html
$ nano .htaccess

AuthName "Secret Web Page"
AuthType Basic
AuthUserFile /etc/httpd/conf/webpasswd
require valid-user

Step 4: Test the web page.

$ firefox http://localhost/~gene
or
$ firefox http://www.exampledns.com/~gene

Due to limited space here, this Fedora 8 Quickie Apache Web Server Setup will come in various installment. Refer to the next post setting up CGI and Virtual Hosting.

Thursday, August 28, 2008

Fedora 8 Quickie DNS Setup Tutorial

Note: Make sure to check the conventions I use before going through the tutorial.

Since a working DNS is necessarily for most of the Linux stuff I need to setup, I reckon this should be my first blog on Linux. For those following this quickie tutorial, note that DNS setup although straight-forward is still moderately complex. This post is meant as companion text for other more comprehensive DNS tutorial. Also, that while I try to step through all the commands, I won't be able able to display the output of these commands. On some part of this tutorial, you'd have to feel your way through the setup.

That said, let happiness begin!

The Domain Name System (DNS) is way for you to associate cryptic IP address into a more human-friendly domain name. To have a valid and usable Internet DNS, you need to register your domain and host it somewhere. In our case, we'll only setup one that is sufficient for testing other network configuration. For this setup, we'll create exampledns.com domain.

Step 1: Install all the necessary packages.

# yum -y install bind bind-utils bind-chroot
# rpm -q bind bind-utils bind-chroot

Note: The yum utility will automatically resolve and install all the dependency packages (you need Internet connection). Use 'rpm' command to quickly verify if the packages was successfully installed on your system.

Step 2: Make a backup of /etc/named.conf configuration file. Edit /etc/named.conf and add the settings below for exampledns.com domain name.

# cp /etc/named.conf /etc/named.conf-original
# cd /etc/
# vi named.conf


options {
listen-on port 53 { 127.0.0.1; 192.168.0.2; };
directory "/var/named";
allow-query { localhost; 192.168.0.0/24; };
allow-transfer { localhost; 192.168.0.0/24; };
recursion yes;
};

zone "exampledns.com" IN {
type master;

file "exampledns.db";

};

zone "0.168.192.IN-ADDR.ARPA." IN {
type master;
file "exampledns.reverse";
};


Step 3: Create the zone file for your exampledns.com domain.

# cd /var/named/chroot/var/named
# vi exampladns.db


$TTL 1D
@ IN SOA ns.exampledns.com. root.exampledns.com. (


001 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum

@ IN NS ns.exampledns.com.
ns.exampledns.com. IN A 192.168.0.2
exampledns.com. IN A 192.168.0.2

www IN A 192.168.0.2
ftp IN A 192.168.0.2
mail IN A 192.168.0.2

pop IN CNAME mail
imap IN CNAME mail


Note: Carefully take note of the dot or period in ns.exampledns.com. and root.exampledns.com. lines. If it's a fully qualified domain, make sure to put a dot at the end. Or just simply copy and paste the configuration file.

# service named start

Step 6: Create the a reverse DNS.

# cd /var/named/chroot/var/named
# vi exampladns.reverse

$TTL 1H
@ SOA ns.exampledns.com. root..exampledns.com. (
2;
3H;
1H;
1W;
1H; )

NS ns.example.com.
2 PTR exampledns.com.

# service named restart

Note: If everything went well, you should see the following display

Starting named: [ OK ]

If you encounter any problems (ie. syntax errors, etc), the best place to start troubleshooting is the /var/log/messages.

Step 7: Since this is only local domain for testing networking setup, you need to point your resolver back to your local machine. Edit /etc/resolv.conf file and insert the following settings on the first line of the file.

nameserver 192.168.0.2

Step 8: Test your local DNS setup.

$ dig any exampledns.com (testing the information on your exampledns.com domain)
$ dig mx exampledns.com (testing MX record for mail server setup later on)
$ dig -x 192.168.0.2 (test reverse lookup for DNS)
$ ping ftp.exampledns.com (testing domain using ping)

For setting up local DNS for testing, this ought to do it. Also, this Fedora 8 Quickie DNS Setup Tutorial is meant to compliment the more detailed DNS howto found here.

Happy hacking!

Monday, August 25, 2008

Conventions

When stepping through the quickie tutorial, here are the conventions and assumptions I used:

  • These quickie tutorial are targeted for Linux users that is cross between a newbie and intermediate users. A working knowledge of Linux is assume ie. proficiency in editor of your choice, basic permissions, or navigate through Linux files system.
  • I use vi editor but but note that vi is not newbie-friendly editor, if your fairly new in Linux editors using nano might be more appropriate for you.
  • Before going through the tutorial, I assumed that you've already read through some of the more detailed, theoretical and in-depth articles/howtos on the subject.
  • Lines that are prefix with # denotes administrative commands that needs to be run on the console as root user.
  • Lines that are prefix with $ are regular commands and can be run on the console as regular/local user.
  • Bold and italics letters means that you need to insert these in a file or create the file with these contents.
  • I assume that your local IP address on eth0 (network card) is 192.168.0.2 and that you have an Internet connection for downloading packages (unless you've setup your own yum repo which I've also tackled in other post).
  • While I try to step through all the commands, I won't be able able to display the output of these commands. On some part of the tutorial, you'll have to feel your way through the setup.
Happy Hacking!

Hullo World!

Hullo world! This is my first post!