Apache Web Server Tutorial
Page content

Installing Apache

The easiest way to install Apache is by using the binary package available for your operating system. This ensures that everything is set up correctly for your operating system. Linux will find the Apache binaries in their system repositories. Choose the Apache package and any modules you need from the list. Common modules include PHP, Perl and other server side scripting languages. If you are going to be using MySQL, you can select those packages, also. Click the “Apply” button and everything is installed for you.

Windows users can download the Windows binaries from the Apache website, or they can install EasyPHP which will set up Apache, MySQL and PHP in one package.

There are binaries available on the Apache website for other operating systems, such as Solaris and Netware as well as the source code if you want to build your own.

Unix/Linux Configuration

When the installation process is finished, Unix/Linux users should automatically stop the Apache service from running as the root user. As the root user, stop the Apache service with the command:

/etc/init.d/apache2 stop

Create a new user and group with the command:

groupadd apache

useradd -c “Apache” -g apache -p passwd1 apache

And then edit the /etc/apache2/envvars file and change the following two lines to cause Apache to run as the new user:

export APACHE_RUN_USER=apache

export APACHE_RUN_GROUP=apache

Apache sets the default document root as /var/www/html. You can leave this alone and change the ownership to the new Apache user, or you can create a new directory for the new document root. If you create a new directory, you have a few more commands to run.

Create a new configuration file in /etch/apache2/sites-available with the command:

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/your_site

Then open the your_site configuration file in any text editor. You will need to change the DocumentRoot directive under the <VirtualHost *:80> section to reflect your new document root.

Disable the default site with the command:

a2dissite default

Enable the new site with the command:

a2ensite your_site

Restart the Apache service with the command:

/etc/init.d/apache2 restart

Windows Configuration

The configuration steps for Windows users are a bit different. Stop the service through the Control Panel. Go to Administration Tools -> Service and double click the “Apache2” service. Stop the service before making the configuration changes.

The httpd.conf configuration file can be accessed through Start->Programs->Apache HTTP Server->Configure Apache Server -> Edit the Apache httpd.conf Configuration File. Here you will make changes to the document root, the server name and the administrator’s email address. The default document root location for the Windows OS is C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. You can change this to any folder by changing the DocumentRoot directive in the httpd.conf file.

Restart the Apache2 service once you are finished making the changes.

The .htaccess File

The .htaccess file can be used to make changes to the main configuration on a directory level. For example, if you have a certain portion of your web site that is only available to registered users, you would add an .htaccess file to that directory. The changes to the configuration will only apply to the directory the file resides in and any subdirectories. The .htaccess file directives are beyond the scope of this Apache web server tutorial, but you can find more information on the Apache Web Site.