With the release of Apache 2.2, the Apache group has improved upon an already outstanding service. If you're in the market for a new web server, or are interested in putting Apache 2.2 through its paces, it's very easy to create a simple Apache site on either Windows or Linux. Here's how it works
The installation of Apache 2.2 on Linux can be handled in approximate 73,624 different ways, give or take a few. That is to say there is a variety of different ways you can install Apache, some dependent on your preferred Linux distribution. For example, if you're a Red Hat or Fedora fan, RPM is your best choice. If you're using some other distribution, you may be able to use RPM, or your distribution may have its own package format.
If you're installing your Linux server from scratch, you can usually choose Apache as an installation option. If you have this option, take it, unless you need something unusual in your installation.
If you're using an existing server and don't want to reinstall the OS, or if you want to have the most granular control over how your Apache installation is configured, your best bet is to build Apache from source code. If you're somewhat new to Linux and the sound of this makes you nervous, it's actually a whole lot easier than it sounds. Better yet, this option works on any Linux distribution out there. It even works for Windows if you have an appropriate compiler installed.
For the example installation in this section, I'm going to build Apache 2.2 from source and install it on a Fedora Core 4 server. You won't see anything fancy in this build--just the basics will be included, but your Linux server will be serving web pages in just minutes!
Before you can compile Apache, you need the source, which is available for download from the Apache web site. As of this writing, the latest version of Apache available is 2.2.0. I've saved the file, named httpd-2.2.0.tar.gz to a folder named /usr/src/apache-2.2 on my server. I like to save installations in this location so I have them for the future.
The next few commands are entered from a command line. I've put them, in order, in Table A.
When you're done with the steps in Table A, browse to your new server. You should get a "It works!" message as shown in Figure A.
|Apache was successfully installed.|
Before you do too much, you should configure Apache to automatically start when your system boots. The steps to make this happen depend on which Linux distribution you're using. Please refer to your system docs for more information. Until you get that set straight, use the "start" command in the last part of Table A.
Table B lists the various modules available for your control during the ./configure portion of the instructions in Table A. I've indicated whether module is enabled by default or disabled by default, the module name, the configure directive you need to use to enable or disable the module and provided an explanation of the module and linked it to the official Apache documentation page. I gathered this information from the Apache documentation site and reformatted it to be easier to read and follow.
Installing Apache 2.0 on Windows
The Windows installation of Apache is substantially easier than installing Apache from source under Linux. While you can install Apache using source under Windows, how many Windows administrators do you know that actually do this? I don't know any either.
Note that this section is entitled "Apache 2.0 for Windows". The Apache group has yet to release a binary for the Apache 2.2 branch. While others have created such binaries, you're limited in support and, unless you want to build from source yourself, you're at the whim of the person that built the distribution. As such, this section is focused on Apache 2.0.
The Apache group provides a win32 executable version of their web server just for the purpose of easily installing under Windows. Before you get started, make sure that you don't have IIS installed on your server. If you continue with IIS installed, Apache will not be able to listen for requests on port 80. You can run Apache and IIS side-by-side if you want to run one of the products on a port other than 80 or if the two products listen to different IP addresses.
After you make sure IIS is removed from your Windows server, download the Apache Windows binary. As of this writing, you won't be able to download a Windows binary version of Apache 2.2 since it's not yet offered on the Apache web site, so download the latest version of Apache 2.0. As of this writing, the latest 2.0 release is 2.0.55. For this example, I've downloaded the file named apache_2.0.55-win32-x86-no_ssl.msi. As you can probably guess, this is a basic Apache build without SSL support, which will suffice perfectly for a simple Apache site.
After download, execute the MSI file and follow the on-screen instructions.
The first screen you get provides you with an introduction. Click the Next button to move on.
|The Windows installer introduction screen|
And, of course, there is the obligatory license screen. Accept the license and click the Next button to continue with the installation.
|The Apache license|
Next, provide the Apache installer with information about your server, including your network domain, the server name, the email address of a server administrator, and decide how you want to run the Apache web server service. Most, if not all, of this information will be filled in. Where possible, stick with the defaults. If you plan to run Apache only for testing, run "only for the Current User".
|All of this information is filled in for you.|
Now, choose your installation type. While a Typical installation is perfectly fine, I chose to perform a Custom installation so I could demonstrate your installation options.
|Choose your setup type.|
By default, everything on the custom screen is selected for installation and the server is installed to C:\Program Files\Apache Group. If you want to change the installation path, click the Change button and choose a new path.
|Choose your custom installation options.|
That's all there is to it! After the installation options screen, the installer does its job and installs Apache using the options you provided. When you're done, open a web browser on another system and point it to your new Apache server. You should get a test page that says "Seeing this instead of the website you expected?"
|The Apache installation was successful!|
Adding and modifying pages
Congratulations on getting your Linux- or Windows-based Apache server up and running! Now, I'll go over how you can add new and edit current pages on your site. After all, you probably don't want to keep the sample pages around for a production site!
As you start adding pages, you'll need a decent editor to make changes to the HTML files. You could use something like FrontPage, but if you want to keep things simple, you can just use a text editor. Under Linux, I usually use pico or nano for this purpose. For Windows, I've fallen in love with the open source Notepad++.
To add or edit pages on your site, you need to know the location of your document root, the folder in which all of your web pages are stored:
- Windows - C:\Program Files\Apache Group\Apache2\htdocs
- Linux - /usr/local/apache/htdocs
Make sure that you give any files you create an extension of .html so that Apache knows how to handle them. Apache is very dependent on the extension to determine what module should handle a file.
As an example, on my Windows system, I've created a file in the C:\Program Files\Apache Group\Apache2\htdocs folder named tr.html with the contents "This is a TechRepublic sample file." The result is shown in Figure H.
|This file took only seconds to create and add to my site.|
In this article, I won't be going too deeply into managing an Apache configuration file, but will provide you with some general tips. First off, Apache, under both Linux and Windows, is managed through the manipulation of the file named httpd.conf.
- Windows - C:\Program Files\Apache Group\Apache2\conf\httpd.conf
- Linux - /usr/local/apache/conf/httpd.conf
This is a long text file full of directives that tell Apache what to do. For example, on both servers, the httpd.conf file has a line that reads "Listen 80". This directive tells Apache to listen on port 80 for incoming requests. Going through the various directives is beyond the scope of this article (I will go over the possible options in a future article). However, after you make changes to the file, you need to restart the Apache service. To do this:
- Windows - Start | Control Panel | Administrative Tools | Services. Locate the Apache2 service and click the Restart button.
- Linux - Execute the command: /usr/local/apache/bin/apachectl restart
It's that simple
For a simple site, this is all you really need to know to get up and running! Once you get used to it, Apache is very easy to work with and provides an outstanding platform for robust web development and page serving. As you get into more advanced techniques, such as scripting languages and database access, you'll come to appreciate Apache's flexibility.