Apache2

Basics

Apache is the most widely used HTTP server on Linux systems and serves web pages that have been requested by clients using the HTTP protocol. The Apache server is modular meaning the core of the server only provides the basic functions of a HTTP server. A number of modules are available to extend functionality and allow interaction with database engines and scripting languages such as; MySQL, PHP, Python and Perl.

Installation

Apache2 packages are available for most major distributions and can be installed using your distributions package manager.

apt-get (Debian based):

sudo apt-get install apache2

yum (Red Hat Based):

yum install httpd

If you have a distribution other than the ones covered please check their documentation on how to install packages. If your distribution does not provide a package you can find the source at http://httpd.apache.org/download.cgi

Configuration

Debian / Ubuntu

NOTE: Some of these commands may require that you proceed them with a 'sudo'. If you are having trouble with one of the commands, please simply add a 'sudo' to the start of it ('cd /var/www' becomes 'sudo cd /var/www').

Your main directory for configuration is going to be ”/etc/apache2”.

Open up a terminal and enter:

cd /etc/apache2/sites-avaliable

In this directory you should see a file called “default” or “example.com”. We want to copy this file to your server name. So, run the following in a terminal:

cp default server.com

Where “server.com” is the name of your server.

Now open up this new file using:

nano server.com

And make the following changes:

      ServerAdmin my@email.com
      ServerName server.com
      ServerAlias www.server.com
      DocumentRoot /var/www/server.com

Obviously, where “server.com” and “my@email.com” is you would put your server and personal email address. The “ServerAdmin” line is on line 2. You will probably have to add the “ServerName” and “ServerAlias” lines right after “ServerAdmin”. The “DocumentRoot” line is line 3.

After you have finished making the changes look at the other lines and see everything looks alright. Save this file.

We now need to make a symbolic link between this file and a file in “sites-enabled”. That way anything that is in /etc/apache2/sites-avaliable/server.com” is also in ”/etc/apache2/sites-enabled/server.com”. In your terminal enter the following:

cd /etc/apache2/sites-enabled ln -s /etc/apache2/sites-available/myexample.com

Your main directory for the HTML files is going to be ”/var/www”. We just need to create a directory here for your server. In your terminal run:

mkdir /var/www/server.com

Again, where server.com is you should put your server.

Change directory to this and make a index.html file.

cd /var/www/server.com nano index.html

In the index.html just enter something like “test” and save. This directory (”/var/www/server.com”) is where you will be placing all your HTML files once apache2 is set up.

Lastly, restart the apache2 server by entering:

/etc/init.d/apache2 restart

Go to www.server.com in your web browser and make sure you see the test “index.html” file you made.

Virtual Hosts

Modules

Userdir

The mod_userdir module provides user-specific directories on the server. The location of the directories can be customised although the default is /home/<user>/public_html

For example http://www.servergeeks.org/~bob would return /home/bob/public_html/index.html

The userdir module can be enabled on Debian based systems by using the a2enmod command:

sudo a2enmod userdir

PHP5

Before reading this section please see PHP for installation and configuration details.

Once PHP5 is installed the corresponding Apache module should already be enabled. After installation of the PHP5 packages you may need to restart Apache in order for the changes to take effect:

sudo /etc/init.d/apache2 restart  # for Debian-based systems
sudo /etc/init.d/httpd restart  # for Red Hat-based systems

To verify the PHP5 module is active on a Debian based system you can run the a2enmod command:

sudo a2enmod php5

This should return something similar to “This module is already enabled!” otherwise it will enable the module.

MySQL

Before reading this section please see MySQL for installation and configuration details.

 
web/apache.txt · Last modified: 2009/01/13 03:26 by zombie_gaz
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki