Using Apache

You will need to be able to use Apache on both your local machine and on the VMs. It's likely that these two environments will be different, since the VMs run Ubuntu and you're likely using OS X. For example, the OS user:group created by Apache in OS X is _www:_www; in Ubuntu, it's www-data:www-data.

In particular, the folks who maintain the package repositories for Debian Linux have created their own version of Apache that differs in configuration from the standard version you'll have installed on your Mac or Windows PC (or non-Debian Linux distribution, like Fedora). Since Ubuntu is a Debian-derived distribution, the VMs use Debian-style Apache.

Apache on the VMs (Ubuntu)

Usage

Usage first, since the configuration for the VM's should already be taken care of (see below for reference, though).

Debian-style Apache gives you several options for controlling the server. All of the following are essentially equivalent ways to run the indicated commands:
  • service apache2 (start | stop | reload | restart | status)
  • /etc/init.d/apache2 (start | stop | reload | restart | status)
  • apachectl (start | stop | reload | restart)
(Don't forget that you'll need to sudo these in practice!) The second is essentially the same as the first, since the service command points to the scripts in /etc/init.d/. The third is the only one of these options available on OS X, since that OS doesn't have init.d/ or do service commands.

The error logs are in /var/log/apache2/ in the form of a series of files error.log, error.log.1, etc.

Configuration

The Apache installation directory is /etc/apache2/. The main Apache configuration file is /etc/apache2/apache2.conf, but you typically won't touch this file after initial installation. Instead, further configuration is done through external files.

The configuration scheme used by Debian-style Apache is that potentially useful modules and configurations are stored in the set of /etc/apache2/*-available/ directories
  • sites-available/
  • conf-available/
  • mods-available/
To enable one of these available modules or configurations, the appropriate *-available/ file is symlinked into a corresponding set of /etc/apache2/*-enabled/ directories
  • sites-enabled/
  • conf-enabled/
  • mods-enabled/

which Apache loads on startup. Don't create these symlinks on your own - there are command-line tools to do it:

Element Action Command
module enable a2enmod <module_name>
disable a2dismod <module_name>
config file enable a2enconf <config_filename>
disable a2disconf <config_filename>
site file enable a2ensite <site_config_filename>
disable a2dissite <site_config_filename>
The "enable" commands create the symlinks, while the "disable" ones delete them.

Briefly, mods are modules used to add additional server functionality, conf are general configuration files to supplement apache2.conf, while sites are site-specific configuration files for situations where you serve multiple websites using a single installation of Apache (sometimes called virtual hosts).

At some point Debian-style Apache was updated to require configuration files to have a .conf extension. This happened between Ubuntu 14.04 and 16.04, for example. If you're having trouble enabling or loading a config file, this might be the reason.

If you find yourself messing with the configuration settings, a useful thing is the command apachectl configtest, which reviews the syntax of the configuration files for you to check for errors.

Apache on OS X

The following is taken from experience with OS X El Capitan, but it should be consistent for other versions.

Usage

The apachectl script is a wrapper around some launchctl commands that direct the server. The commands

$ apachectl (start | stop | restart)

do the obvious things. $ apachectl status exists, but the mod_status Apache module must be installed for it to work. When functional, it will refer you to http://localhost:80/server-status= to view your server status. You can also try

$ ps aux | grep httpd

to see if the Apache httpd daemon is running. There are typically multiple instances of httpd active at any given time, since Apache likes to keep a spare handy in case a connection request comes in. If httpd is an active process, then Apache is running.

The error log is /var/log/apache2/error_log.

Configuration

OS X uses the standard main configuration file for Apache, httpd.conf instead of Debian's apache2.conf. In this system, modules are enabled using Include commands in httpd.conf.

There are a couple of major differences in configuration style between Apache 2.2 and Apache 2.4. This is important if you're running OS X, since Yosemite and higher include Apache 2.4, while earlier versions came with Apache 2.2 or lower. If you upgraded from a pre-Yosemite version to Yosemite or later, you might find that you're running Apache 2.4 using leftover Apache 2.2 configuration files that weren't upgraded. This can cause problems.

Use apachectl -v to determine which version of Apache you're running.

Many of the modules changed between Apache 2.2 and 2.4. If you find yourself in conflict, you can go through the process of updating, disabling, and enabling altered modules manually, but probably a faster approach is to copy the httpd.conf file of one of the other developers who uses Apache 2.4, or at least their LoadModule block.

Access control syntax changed between Apache 2.2 and 2.4. Previously, the Allow/Deny Directives syntax controlled who could connect to the server (or to particular directories). With Apache 2.4 and later, this changed to a starkly different Require syntax. You shouldn't need to worry about this, since this type of configuration is already taken care of for the website. If it comes up, though, or if you're just curious, you can learn more with these links:

-- Main.jgriffith - 2016-02-24
Topic revision: r8 - 2017-01-11, JoelG
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback