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
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.
