Apache

Apache is the common name for an open source web server used on Linux systems, written by the Apache Foundation. Since the Apache Foundation has produced a lot of projects, the web server is more correctly known as the "Apache web server" or httpd.

The Apache web server is one of the most popular web servers in current use (powering 69% of web sites according to a recent Netcraft survey).

= Web Site = Apache's web site is http://httpd.apache.org.

= Install apache = To install apache, find out your distro and proceed accordingly:

CentOS 4/5
yum install httpd php php-cli /etc/init.d/http start chkconfig httpd on
 * To install apache with php support, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, enter

Red Hat 4/5
yum install httpd php php-cli /etc/init.d/http start chkconfig httpd on
 * To install apache with php support, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, enter

Fedora 6 to 11
yum install httpd php php-cli /etc/init.d/http start chkconfig httpd on
 * To install apache with php support, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, enter

Debian and Ubuntu

 * Apache2 Configuration in Debian
 * Apache2 Installation and Configuration in Ubuntu

Slackware 9.x/10.x
To have Apache start automatically when you boot your system:
 * Make sure the apache-1.3.29 package is installed (or newer version)
 * Make /etc/rc.d/rc.httpd executable (chmod 755 /etc/rc.d/rc.httpd)

Fedora Core 1
To start apache, /etc/init.d/httpd start To start apache in the future after booting, enter chkconfig httpd on To allow others to connect to your web server (http) requests, you must open the www port (80) in the firewAll, so run redhat-config-securitylevel
 * open a console as root and enter

Red Hat's graphical configuration tool (redhat-config-httpd or "Start" &gt; System Settings &gt; Server Settings &gt; HTTP) provices a graphical, easy-to-use interface for configuring Apache.

SuSE
These descriptions have been successfully tested on SUSE 11.0 - 11.4 but should work same or similar on any version. yast -i apache2 apache2-mod-php5 /etc/init.d/http start chkconfig apache2 on
 * To install apache with php support, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, enter

Arch Linux
pacman -Sy apache /etc/rc.d/httpd start
 * To install apache, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, add httpd to the list of daemons in /etc/rc.conf

Gentoo Linux
emerge apache emerge mod_php /etc/init.d/apache2 start rc-update add apache2 default
 * To install apache with php support, open a console as root and enter
 * To start apache, enter
 * To make apache2 start in the future after booting, enter

= Setup =

Where are the files?
By default the files are here:

But files can be on very different locations, for example, if you rent a server in the internet from a hosting provider. To understand why it makes sense to use a different file structure, you need to understand name-based virtual hosting.

one-site configuration
If you will only be hosting one site with Apache, setup is particularly simple. In the httpd.conf (see above for its location): Test in any browser.
 * set the ServerName directive to your servername (which should be resolvable via DNS)
 * disable UserDir unless you want users to publish their own websites in their home directories
 * place your website in the Document Root (varies by distribution; see above).

name-based virtual hosts
Name-based virtual hosts allow you to have one apache configuration serving multiple sites with different content. For example, if www.foo.com and www.bar.org point to the same IP address, they can still deliver different content. Apache analyzes which server name is contained in the http 1.1 request and serves content accordingly based on the VirtualHost directive, e.g. in httpd.conf.

Let's look at an example NameVirtualHost *:80

 ServerName www.foo.com ServerAlias foo.com *.foo.com DocumentRoot /srv/www/htdocs 

 ServerName mail.foo.com DocumentRoot /srv/www/htdocs/mail 

 ServerName www.bar.org DocumentRoot /srv/www/htdocs/bar  This will deliver the content for www.bar.org from /srv/www/htdocs/bar and the content for foo.com from /srv/www/htdocs.

https
See Set up apache2 for https.

additional software
This wiki also describes how to set up apache2 for https. For different web-software you may also want to enable perl using mod_perl, or mysql.

Configuration directives

 * AllowOverRide
 * ServerName

= TroubleShooting =

VirtualHost overlap on port 80
Symptom: When starting apache2 you get _default_ VirtualHost overlap on port 80, the first has precedence Solution: Add the following line at the beginning of the configuration file: NameVirtualHost *:80

= See also =
 * apache2ctl
 * a2enmod
 * Securing Apache
 * Apache.org -- official website
 * Webmin -- a graphical configuration tool for Apache.