The World Wide Web is probably the primary reason of the Internet's explosive growth as a popular communications medium. So why not add to the wealth by running your own webserver? The most popular webserver by far is Apache, which already comes with many Linux distributions.
Chances are that you already have Apache installed, so you may skip the downloading process. Of course, downloading and compiling a new Apache gives you the advantage of knowing how to do it. The process is quite simple, even the configuration.
This document is in alpha status, so let me know if it works for you so I can update its status. That way I'll know if it works.
Should you choose to remove any existing Apache, try typing rpm -e apache, if you're using Red Hat (or maybe another RPM-based distribution).
In Debian, use the apt-get remove apache command.
Let me know how to remove the default Apache package for other distributions so I may include them here. I don't want to look ignorant for a long time.
Apache is available all around the world in many FTP sites. There's a mirror list at the Apache website. As of now, Apache is at version 1.3.9, and at the rate it constantly develops, this document will probably fall behind when a new release comes out.
You can find a list of where you can download Apache at http://www.apache.org/dyn/closer.cgi. The filename for the file you're looking for goes something like "apache_1.3.9.tar.gz".
You have downloaded Apache. If it's not already, put it in /usr/local/src/ and untar (tar -zxvf <apache_1.3.9.tar.gz>) it. It should extract to some directory called "apache-1.3.9" or similar, depending on what version number you've downloaded. Now move into the apache directory by typing cd apache-1.1.9 (or whatever version you've got).
Basically you can get Apache compiled by typing ./configure ; make in the Apache directory. make install will install it to /usr/local/apache by default. In /usr/local/apache/ there will be many subdirectories containing various files that you might want to tinker with.
At the least, you should make a symbolic link from /usr/sbin/httpd to /usr/local/apache/bin/httpd (assuming you installed Apache to the default location). Or, you can add /usr/local/apache/bin/ to root or user paths from ~root/.bashrc and /etc/profile, respectively.
Since you've now got Apache installed and ready to go, it's time to configure it. Move on down to /usr/local/etc/httpd/conf/ and copy all the "*.conf.default" files to their "*.conf" selves. That means you would copy httpd.conf.default to httpd.conf, srm.conf.default to srm.conf, and access.conf.default to access.conf. Those are all the files that you need to copy. Edit "httpd.conf" with your favorite text editor and uncomment the ServerName line. Put in your hostname or IP address in place of the fake one in the commented line, which probably changes each time you log on. For ServerAdmin, put in your e-mail address so that people visiting your webserver can e-mail you about any problems that arise. What you fill in is pretty straightforward.
Reading the comments and examples in the *.conf files for Apache will help you if you need to do any "advanced" tasks such as virtual domains or extra MIME types (if you don't know what these are, don't worry about them yet).
If you're using Red Hat Linux, you should have the configuration files in /etc/httpd/conf/, if you had Apache installed already.
On SuSE 5.2, 5.3 and 6.0 the config files for Apache are located in /etc/httpd/. Thanks to Uwe Hermann (firstname.lastname@example.org) for this information.
Thomas Smith writes, "On my Debian 2.1 system, the configuration files are in /etc/apache, and are httpd.conf, srm.conf, mime.types, and cron.conf. I would guess that not all of these are essential, but they are the default. The default directory for web pages is /var/www/."
For other distributions, I'm not sure. Please let me know if you can provide this information. You'll probably want to look in the /etc/ directory in the meantime.
Many people need to run multiple web servers on one machine instead of one webserver per Linux machine. First you'll have to get a hostname assigned to the webserver, which can be a subdomain (jgo.local.net if you're on the local.net domain) or a whole new domain registered through InterNIC (such as dummy.com).
Once you get past all the domain registration stuff and you've got many hostnames assigned to the same IP address, or if the machine is running under multiple IP addresses and multiple hostnames, you're ready to set up for virtual hosts.
Start out by editing /usr/local/apache/conf/httpd.conf. If you have Red Hat Linux with Apache installed already, the file is /etc/httpd/conf/httpd.conf. You'll see an example shown, looking like this:
# VirtualHost: Allows the daemon to respond to requests for more than one # server address, if your server machine is configured to accept IP packets # for multiple addresses. This can be accomplished with the ifconfig # alias flag, or through kernel patches like VIF. # Any httpd.conf or srm.conf directive may go into a VirtualHost command. # See alto the BindAddress entry. #<VirtualHost host.some_domain.com> #ServerAdmin email@example.com_domain.com #DocumentRoot /www/docs/host.some_domain.com #ServerName host.some_domain.com #ErrorLog logs/host.some_domain.com-error_log #TransferLog logs/host.some_domain.com-access_log #<VirtualHost>
That's commented out because your machine most probably does not own the hostname host.some_domain.com and therefore won't accept requests for it.
The basic way that this works is when someone requests a page on, say, jgo.local.net, it won't go to squeeze.local.net, the original hostname of the machine. Although jgo.local.net is an alias for squeeze.local.net, somebody asking for http://jgo.local.net won't get the front page to http://squeeze.local.net because it's specified in httpd.conf to serve out /home/jgo/index.html when a request for jgo.local.net is given through HTTP. When a request for 188.8.131.52 is given, however, it won't serve out /home/jgo/index.html because only the requests for http://jgo.local.net will give the web surfer /home/jgo/index.html. Some older browsers don't support virtual hosts, such as MS Internet Explorer 2.0, which came with early versions of Windows 95.
You can assign as many virtual hosts to your machine as you want, especially if the machine is a top-level domain such as local.net. That way you can assign the hostnames jgo.local.net, something.local.net, one.local.net, two.local.net, three.local.net, and anything else you might be able to think of as a hostname. Just keep in mind that you should make sure the server can handle the load of all those domains.
To add subdomains, you need to have an understanding of BIND, the nameserver. Your domain must be registered with InterNIC, and the nameserver is in charge of getting subdomains set up. It sounds complicated, but it makes a whole lot more sense once you figure it out.
My observations about the setup of /etc/hosts is that each hostname has to be part of a higher-level domain; for example, if I wanted to name my machine neophobia, I'd either have to make the higher-level domain "localdomain" or "dyn.ml.org". Here's what each entry would look like:
127.0.0.1 localhost localhost.localdomain
0.0.0.0 neophobia neophobia.dyn.ml.org
People with dynamic IP addresses (most dialup PPP users) can just use the IP address "0.0.0.0" to represent their Internet IP. So, this is what my hosts file looks like:
127.0.0.1 localhost localhost.localdomain 0.0.0.0 neophobia neophobia.dyn.ml.org
After you're done with all that you wanted to do, try to start httpd by typing httpd as root. It is common and normal for you to have some errors, so feel free to e-mail me concerning any other errors that come up after you execute the httpd binary.
When you have httpd already running, the error message it gives will be bind: Address already in use, httpd: could not bind to port 80 or something similar. To fix this, do killall httpd and then httpd to restart it. Make sure you bind it to the correct hostname/IP address (read the paragraphs above).
By default you'll have to edit the HTML files in /usr/local/apache/htdocs/. The directory for CGI scripts is in /usr/local/apache/cgi-bin/.
On a default Red Hat installation you'll probably find what you need to edit in /home/httpd/html/, along with some directories. The CGI-bin will be in /home/httpd/cgi-bin/.
The htdocs-directory (DocumentRoot) is /usr/local/httpd/htdocs/ on SuSE 5.2, 5.3, and 6.0, according to Uwe Hermann (firstname.lastname@example.org).
Let me know of the filesystem layout for other distributions. I don't have immediate access to other distributions.
There are more complex things you can do with Apache, and here I only cover the basics. There are special modules that come with Apache which I have little experience with, but I just want to let you know that they're available. Read the INSTALL file for instructions on this.
Questions, comments, and/or suggestions? You can e-mail me at joshuago at users dot sourceforge dot net.
Copyright © 1997-1999 Joshua Go (joshuago at users dot sourceforge dot net). All rights reserved. Permission to use, distribute, and copy this document is hereby granted. You may modify this document as long as credit to me is given.