Apache

From LQWiki
(Redirected from APACHE)
Jump to navigation Jump to search

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
  • To start apache, enter
/etc/init.d/http start
  • To make apache2 start in the future after booting, enter
chkconfig httpd on

Red Hat 4/5

yum install httpd php php-cli
  • To start apache, enter
/etc/init.d/http start
  • To make apache2 start in the future after booting, enter
chkconfig httpd on

Fedora 6 to 11

yum install httpd php php-cli
  • To start apache, enter
/etc/init.d/http start
  • To make apache2 start in the future after booting, enter
chkconfig httpd on

Debian and 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

Red Hat's graphical configuration tool (redhat-config-httpd or "Start" > System Settings > Server Settings > 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
  • To start apache, enter
/etc/init.d/http start
  • To make apache2 start in the future after booting, enter
chkconfig apache2 on

Arch Linux

pacman -Sy apache
  • To start apache, enter
/etc/rc.d/httpd start
  • 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
  • To start apache, enter
/etc/init.d/apache2 start
  • To make apache2 start in the future after booting, enter
rc-update add apache2 default

Setup

Where are the files?

By default the files are here:

distro configuration files html files
(documentRoot)
Arch Linux /etc/httpd/conf/ /home/httpd/html/
CentOs 4/5 /etc/httpd/conf/httpd.conf /var/www/html
fedorA 1 /etc/httpd/conf/httpd.conf /var/www/html
fedorA 6-11 /etc/httpd/conf/httpd.conf /var/www/html
GenToo /etc/apache2/httpd.conf /var/www/localhost/htdocs/
Red Hat 4/5 /etc/httpd/conf/httpd.conf /var/www/html
SlackWare /etc/apache/httpd.conf /var/www/htdocs
SUSE /etc/apache2/httpd.conf /srv/www/htdocs
Ubuntu /etc/apache2/apache2.conf /var/www

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):

  • 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).

Test in any browser.

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

<VirtualHost *:80>
ServerName www.foo.com
ServerAlias foo.com *.foo.com
DocumentRoot /srv/www/htdocs
</VirtualHost>

<VirtualHost *:80>
ServerName mail.foo.com
DocumentRoot /srv/www/htdocs/mail
</VirtualHost>

<VirtualHost *:80>
ServerName www.bar.org
DocumentRoot /srv/www/htdocs/bar
</VirtualHost>

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

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