Apache Quickstart HOWTO

From openSUSE

(Redirected from Howto apache virtual hosts)


Geeko This document describes how to get your server up and running as fast as possible. It is not an extensive introduction into web servers, just a quick step-by-step reference.

Contents

General machine setup

Configure your network and make sure that all components are current, by running YaST Online Update regularly. Parts of the HTTP protocol depend on correct time. Configure machine as a NTP client, either with the YaST configuration module or by editing /etc/ntp.conf (just put a server name into it) and running,

# rcntp start
# chkconfig -a ntp

Installation of Apache packages

Install the package or the complete LAMP server pattern.

# zypper in apache2
# zypper in -t pattern lamp_server

Firewall

If you run a firewall, make sure to allow access to HTTP(s) ports if the server should be reachable from other machines. The supplied configurations are called apache2 and apache2-ssl. They can be enabled via YaST, by adding them to FW_CONFIGURATIONS_EXT in /etc/sysconfig/SuSEfirewall2 or issuing these commands,

# sysconf_addword /etc/sysconfig/SuSEfirewall2 FW_CONFIGURATIONS_EXT apache2
# sysconf_addword /etc/sysconfig/SuSEfirewall2 FW_CONFIGURATIONS_EXT apache2-ssl
# rcSuSEfirewall2 restart

Starting the server

Start the server and configure it to automatically start at boot time.

# rcapache2 start
# chkconfig -a apache2

Adding web pages

The default DocumentRoot is at /srv/www/htdocs, put the files there.


Apache Modules

Enable required Apache Modules by editing APACHE_MODULES in /etc/sysconfig/apache2. Modules can be enabled/disabled/listed with the commands below. Any such operation requires a restart of the service.

# a2enmod php5
# a2dismod perl
# a2enmod -l
# /etc/init.d/apache restart

Virtual Hosts

The directory for virtual host configurations is /etc/apache2/vhosts.d/. As you can see there are two sample configuration files - one with ssl; one without ssl. We use the template without ssl. Only files ending with ".conf" are automatically included to the apache configuration.

In the following instructions, please replace {DOMAINNAME} with an IP or an domain-name you want.

  • Plan your website infrastructure. It's helpful to use a directory (/srv/www/vhosts) including one subdirectory for each virtual host.
You have to decide which sort of virtual host you need, based on the following options:
  • Copy the sample configuration file vhost.template to {DOMAINNAME}.conf and create the subdirectory for this virtual host.
# cd /etc/apache2/vhosts.d
# cp vhost.template {DOMAINNAME}.conf
# mkdir -p /srv/www/vhosts/{DOMAINNAME}/
  • Now edit the copied configuration file and adjust the following as needed:
    • Change the document root for your virtual host: DocumentRoot /srv/www/vhosts/{DOMAINNAME}
    • You also need to change corresponding directory directive: <Directory "/srv/www/vhosts/{DOMAINNAME}">
    • <VirtualHost *:80> It is possible to replace the "*" with an IP addess and "80" with a non standard http port. See documentation.
  • Restart apache.
# /etc/init.d/apache2 restart

Custom configuration

Add/edit configuration for all virtual hosts to /etc/apache2/default-server.conf. Edit APACHE_CONF_INCLUDE_FILES in /etc/sysconfig/apache2 to include configurations from external files. To understand the hierarchy and layout of all include files, read the comments at the top of httpd.conf The old, single, 40K, monolithic configuration file is available in /usr/share/doc/packages/apache2/httpd-std.conf-prefork.


Troubleshooting

Read any error messages when you start the service. Reproduce what is not working and see how it is reflected in the logs. The log files can be monitored in a root shell,

# tail -F /var/log/apache2/*

If you suspect a bug, please report it.


See also


External Links

Passed QA check: Fsundermeyer 13:56, 15 June 2009 (UTC)