Previous Section  < Day Day Up >  Next Section

Recipe 22.6. Setting Up a Simple Public Web Server

22.6.1 Problem

You want to build a simple public web server for a single domain, serving up static HTML pages.

22.6.2 Solution

After installing Apache 2.0, confirm that the location of your web site directory in httpd.conf is set correctly and that the directory exists:

DocumentRoot    /var/www/bratgrrl

Copy your web pages to your DocumentRoot directory (in this case /var/www/bratgrrl). Then start up Apache:

# apachectl start

Configure DNS to point to your web server, and you're done.

22.6.3 Discussion

To run a public web server, you need a registered domain name and a static IP address for your web server. It can be a public, routable IP, or a private IP behind a NAT gateway. Yes, you can play fun DNS tricks on a dial-up account with a dynamically assigned IP using services such as dyndns.org, if your terms of service allow you to run servers and if you just want to run a pretend web site as a learning exercise. Don't do this for a serious web site.

Hosts on your LAN can access your web site by either IP address or hostname:

http://windbag

http://192.168.1.5

This is good way to test connectivity and to preview your web pages.

If you installed Apache from packages, look in /etc/init.d for the startup script. It probably has one of the following names.

# /etc/init.d/apache2 

# /etc/init.d/httpd

# /etc/init.d/httpd2

Typically these are simple start/stop/restart/reload/force-reload scripts that verify file locations and call apachectl. (Be aware that many distributions rename apachectl as apache2ctl.)

Be sure that your init script calls apachectl, and not the httpd binary. The Apache maintainers recommend starting and stopping Apache with apachectl only:

As of Apache 2 it is recommended to use only the apachectl script for (re-)starting or stopping the server.

22.6.4 See Also

    Previous Section  < Day Day Up >  Next Section