Apache Web Serving Basics

Learn how to use the world's most popular Web server. By Chris DiBona

This is the first of two segments on the basics of serving Web content under Linux. The most popular Web server in the world is Apache. It's free, configurable, and secure. It runs on almost every platform, but it's most at home on Linux and FreeBSD.

This article makes some assumptions about your installation, namely that you're using Red Hat or a Red Hat derivative such as Mandrake. Here's how you find out if you had the foresight to install Apache:

Become root by typing su and entering your root password.

Type /etc/init.d/httpd start to start the Web server.

If you get a message that says bash: /etc/init.d/httpd: No such file or directory, you do not have Apache installed. Install it.

Chris DiBona is the director of special projects for OSDN. DiBona has posted a frequently asked questions list on the Web.

Install Apache

If you're running Red Hat 7.3, simply place disk two of your installation media into your CD-ROM drive. Red Hat automatically detects when you insert a disk.

You should be able to go to the directory where the Apache package lies by typing cd /mnt/cdrom/RedHat/RPMS.

Then install the package by typing rpm -Uvh apache-1.3.23-11.i386.rpm.

Save yourself some time later. Type rpm -Uvh php-4.1.2-7.i386.rpm and then try to start Apache again using /etc/init.d/httpd start.

If you're successful, you'll see Starting httpd: [ OK ].

Apache is now running on your system. If you launch a Web browser and try to bring up "http://localhost," you'll see a status message. To get started immediately, you can edit that default page, or you can edit your personal page. Suppose your user name (the name you log in with) is, like mine, "chris." Go to your home directory and create and add permissions to a directory using the following commands:

mkdir public_html

chmod 755 public_html

These commands make it so that you can put HTML files in a directory and have them accessible when someone visits your machine with the following URL:

http://localhost/~chris

If you're on a network, or if you have a static IP, you would be able to address that machine using a fully qualified domain name or IP address. For instance, if your IP address is 192.168.0.2, you can access that machine from any other machine by typing in that domain name. Note that some cable modem and DSL providers will make it impossible to access servers from outside your home often, so don't expect to be able to access your home from the coffee shop down the street. The domain to access the default Apache installation is http://198.168.0.2.

To access the data in your public_html directory, you would visit "http://192.168.0.2/~chris" with "chris" being replaced by your user name. The default installation accessed by 192.168.0.2 can be found in the /var/www directory.

Make your first webpage by creating a file called index.html in the public_html directory and put the text "hello world" inside it. You'll find that when you visit the ~chris homepage you'll see "hello world" on your browser.

Next week we'll touch on the basics of webpage creation using the PHP Web scripting language.

Copyright © 2003 TechTV Inc. All rights reserved. Use of Techtv.com is subject to certain terms and conditions. We respect your privacy.

From Screensavers

Home | Site Map | Splash Page