InfoWorld how-to's

How to install Apache on Linux

An easy step-by-step guide to setting up an Apache Web server on Fedora, CentOS, or Ubuntu

InfoWorld how-to's

Show More
1 2 3 4 5 Page 5
Page 5 of 5

Apache on Linux: Beyond the basics
What we've laid out above is an extremely simple example of an Apache configuration. While most installations will require only minimal modifications to the default configurations, there are a few details to know beyond the basics.

You may recall that we also installed PHP in the initial steps. Because of this, PHP has already been configured for use with Apache. You can test this by creating a file in the document root called test.php and typing in the following PHP code:


Save the file, then open your browser and access http://<server ip address>/test.php. You should get a listing of all the PHP environment variables, modules, and versions. This means that PHP is installed and functional.

An important Apache configuration element to know is the <Directory> statement. This allows you to configure specific permissions on directories shared by Apache. For instance, within our VirtualHost directive example, we might add the following:

<Directory /var/www/test>
    AllowOverride All
    Order deny,allow
    Deny from all
    Allow from 192.168.

This directory statement accomplishes a few goals. First and foremost, AllowOverride All permits the use of .htaccess files within the directory /var/www/test to modify the server's behavior. Through .htaccess files, you can control access to the directory or implement any number of other configuration tweaks without modifying the virtual host configuration file itself. This can be very handy, they allow you to make configuration changes for the virtual host without reloading the server. The downside is that configuration errors within an .htaccess file can cause immediate problems.

(Note that the AllowOverride is subject to several different qualifiers that can grant specific override directives to the .htaccess file. The use of All here allows all of them. You can find a list with descriptions at the Apache Software Foundation.)

Secondly, we have Order deny, allow, and a few Deny and Allow statements. As configured above, the Web server would deny access to any client with an IP address outside the range, or through It's a handy way to deny access to specific IP ranges or to ensure that only internal clients can access that particular resource.

Once you're comfortable with the basics, you can move on to other advanced configuration elements. For instance, it's relatively simple to password-protect a site or directory using .htaccess files. To do this, you need to create a file named .htaccess in the document root of the virtual host (or Apache server) and add these lines:

AuthUserFile /etc/httpd/webpasswds
AuthName "My Web Auth"
AuthType basic
<Limit GET POST>

Then create the password file. On Fedora or CentOS:

htpasswd -c /etc/httpd/webpasswds myuser

On Ubuntu:

sudo htpasswd -c /etc/apache2/webpasswds myuser

Make sure you have set AllowOverride All, or at least AllowOverride Limit, in your configuration file as noted above. After you've done this and reloaded the server, users will be presented with a login dialog box before they can access the website. You can add more usernames and passwords using the same htpasswd command, though you don't need to use the -c flag if you're just adding more users.

To infinity and beyond
With any luck, you've just succeeded in getting Apache up and running on a modern Linux server. There's much more to know about the Apache Web server, and the best way to learn is to experiment with different configurations. You'll want to bookmark Apache's documentation for the version you're running.

It's unwise to put sensitive information on any Web server until you're comfortable that the configuration is proper. It's too easy to make configuration errors that expose information inadvertently. If you're just starting out with Apache and Linux, take the time to research and educate yourself first, and perhaps find someone more knowledgeable to verify your configurations before placing your server into production.

This article, "How to install Apache on Linux," was originally published at Follow the latest developments in applications and Web application development at Get a digest of the key stories each day in the InfoWorld Daily newsletter. For the latest business technology news, follow InfoWorld on Twitter.

Copyright © 2013 IDG Communications, Inc.

1 2 3 4 5 Page 5
Page 5 of 5