Apache Httpd Server

Posted on  by admin
Skip to end of metadataGo to start of metadata

Jul 01, 2020 Majority of web servers around the world use Apache or Apache HTTP Server software. It is quite fast, secure and can be customized easily for different environments by using extensions and modules. Apache runs smoothly on both Windows and Linux web servers. Unlike Ubuntu, which installs Apache as apache2, these flavors of Linux install the Apache service as httpd. On the plus side, both do make use of systemd and the systemctl command. The Apache HTTP Server, colloquially called Apache, is a Web server application notable for playing a key role in the initial growth of the World Wide Web. Originally based on the NCSA HTTPd server, development of Apache began in early 1995 after work on the NCSA code stalled.

This is a Recipe for configuring multiple https instances. While writing this recipe I've noticed that there are other pages in this wiki that also deal with this subject, either tangently or in more direct ways:

Welcome to Apache.com! We are your complete Apache web server and server management resource. Whether you are an advanced expert or a complete novice, we have tips and information to help you! The Apache HTTP Server, httpd, is an open source web server developed by the Apache Software Foundation. If you are upgrading from a previous release of Red Hat Enterprise Linux, you will need to update the httpd service configuration accordingly.

  • ExtendingPrivilegeSeparation – run several httpd instances behind a reverse proxy, use high ports for the backend instances to improve security
  • DifferentUserIDsUsingReverseProxy – run several https instances behind a reverse proxy, run each instance under an different unprivileged user

Some of the ideas in this recipe have already been advanced in these other wiki pages. However, the focus of this recipe is more on the operating system support (FreeBSD, Ubuntu) for this type of set up. The operating system usually provides facilities, such as rc(8) in BSD systems, or init(5) in Linux and other SysV systems, that help admins in launching processes after sucessfully booting the system.

This recipe, therefore complements those already in the wiki, and provides a step-by-step guide to configure such a setup in a BSD system (FreeBSD) and in a SysV-like system (Ubuntu). Hopefully it can be easily translated to other linux or *BSD flavours.

Note: The Ubuntu section is still a work in progress.


The Goal

Or: why do we need to run multiple apache instances in one host?

Although you can certainly have a single installation of Apache httpd, running a single instance, and still have different virtual hosts that can be accessed separately, sometimes following this easy path can lead you to a heavy and bloated web server.

If your virtual hosts have different requirements (e.g. mod_perl for one virtual host, mod_python for another, and maybe mod_php for a third virtual host), then your apache instance is almost surely a RAM eater. Remember that httpd will instantly spawn new child processes of the same instance as needed ... if your perl web app is being frequently accessed, why spawn several instances of an httpd process that is also loaded with mod_python, mod_php and an assortment of other modules that, at least from the standpoint of the perl web app, are useless?

The answer to this, is simple: have separate lighter configurations for your mod_perl, mod_python and mod_php apps, listening on different ports (e.g. 81, 82, 83), and have a reverse proxy instance of Apache with virtual hosts configured to pass requests to the corresponding apache instances.

In this recipe, I'll briefly explain how to do something along these lines:
Example: running different web applications listening in different ports, and using a reverse proxy that forwards incoming requests (e.g. blog.company.com, svn.company.com, www.company.com) to the corresponding https instances.


How do we configure apache so that we're able to start/stop/restart individual instances?

Because apache allows you to load modules dynamically, most of the time, a single installation of apache can serve the needs of multiple instances, and every instance may be configured to run different sets of modules. As an example, you can run a very lightweight proxy module, a mod_perl instance to run your perl web applications, a mod_python instance with DAV to run Subversion, a separate instance running PHP, etc, all from a single local installation of Apache. Unless you have a requirement for a custom built instance (e.g. tweaking compile options differently for different instances), you don't really need to compile and install httpd to different places (prefixes), as many online guides suggest.

In FreeBSD, a clever port maintainer had set up a number of rc scripts that simplify the task of launching all configured instances after booting the system. So if you're using FreeBSD as your server OS, then you're lucky, as the configuration is painless.

In this recipe, therefore, I'll proceed to explain the FreeBSD approach first, and then I'll try to figure out how to do something similar in Linux (Ubuntu).

The FreeBSD approach

1. Install the www/apache22 port

As root, do:

This will fetch the sources for Apache (currently 2.2.17), extract them, and run configure, make and finally install apache-22 on your system. As mentioned before, note that only one local installation is required to run multiple instances of apache. Also note that if you configure the port (make config) to enable mod_perl, mod_python (or any other dynamically loaded module that does not come with the standard apache distribution), then the FreeBSD ports system will 'Do The Right Thing(TM)' and will fetch, extract, configure, make and install the code for the corresponding modules. Easy, huh?

Note also, that there are other alternative ports in FreeBSD that will install different flavours of Apache https:

  • www/apache22-event-mpm
  • www/apache22-peruser-mpm
  • www/apache22-worker-mpm
  • etc.

Choose the port that best fits your needs, and proceed to the next step.

2. Create your apache configurations

In FreeBSD, the configuration files for the recently installed port live in '/usr/local/etc/apache22'. There you will find a sample 'httpd.conf' file. This file may include directives found in other conf files located in a directory called 'extra', at the same location. Please read them, and familiarize yourself with their contents. If you've configured Apache before, you'll find your way around easily.

Now, let's create a number of separate apache configurations. Essentially this means creating different httpd.conf files, for example:

Now edit these files, and tweak the different configurations according to your needs, e.g.

Now, we also need to configure the virtual hosts in the proxy instance, so that whenever a request comes for the Subversion DAV server, it is passed onto your 'python-dav' httpd instance, whereas requests for your wordpress blog are passed to your 'php' instance. Let's edit 'httpd-proxy.conf' again:

Apache Http Server Project

So we're finished with the configuration, and now we need to launch all the instances of httpd, and test that everything is working as expected. Of course you can do this using 'apachectl', e.g.

Apache redirect https to https

But for production operation, it is safer to rely on the FreeBSD rc scripts. These will make sure that the instances are launched at boot time. Our last stop in this FreeBSD recipe, is therefore:

3. Edit /etc/rc.conf

The '/etc/rc.conf' in FreeBSD is the master file containing the system configuration information. This file is read after booting the kernel, and serves to launch services, daemons, set up network interfaces, etc. For our recipe we will be enabling the apache server, listing the available instances (profiles), their configuration files, and telling FreeBSD which of these need to be run (enabled) after booting the system.

When these profiles are configured in /etc/rc.conf, and enabled, they will be started after successfully booting the system. If you want to declare a profile but you only want to start the corresponding httpd instance manually, you can just edit '/etc/rc.conf' and say, e.g. :

Later, you can start/stop any httpd instance manually using just the profile name (proxy, perl, python, php), like this:

Doing it in Ubuntu or Debian

1. Install the apache2 package

In Ubuntu, you need to install not only the apache2 package, but also, the corresponding libapache2-* packages for the modules you need in your apache instances.

2. Create your apache configurations

In Ubuntu, the configuration files for your recently installed webserver are under '/etc/apache2'.
[writing in progress ...]

There is some Debian/Ubuntu specific information in /usr/share/doc/apache2/README.Debian.gz after installation.

3. Configure the system to launch the apache instances after boot

The Ubuntu/Debian init scripts (e.g. /etc/init.d/apache2) have been updated to support multiple instances of (e.g. multiple configurations, named /etc/apache2-$SUFFIX).

Documentation can be found in /usr/share/doc/apache2/README.multiple-instances

Apache is one of the most popular web servers in the FOSS world. First, I strongly recommend that you install the apache server on an external drive width swapfile, especially if you need to use mysql. If you do not have the external drive and the swapfile installed, please look first below. You can copy text, and width right mouse click copy the contents to your PuTTY terminal.


Installing apache with opkg is very simple:

or alternatively install it to the external drive: (see below)

In case you manually mounted the hard drive, restart the drive, to make necessary links:


Apache Http Server Has Stopped Working

Edit /etc/apache/httpd.conf to change the configuration according to your needs.

Sometimes you need to uncomment a line (=remove the # character at the beginning of the line) to activate the respective config option.

Search for “Listen” and replace with your router's IP address and a port different then 80, because 80 is most likely already used by the OpenWrt GUI (LuCI).

Search for “ServerName” and do the same:

ServerName YourServer:81

where YourServer is FQDN of your server name like www.something99.com

Connect to in your browser to see if your configuration works.Place your web server shared documents under /usr/share/htdocs.

External drive and the swapfile install

Since the Apache HTTP Server is quite a big memory hog, we recommend to use it only in conjunction with additional storage. Please follow these guides to get that started:


Configuring Apache and PHP5

To install PHP see →php


Search for “doc_root” and “extension=gd.so”. Do not specify the doc_root, and uncomment the extension=gd.so.

Configure Apache again:

NOTE: This is a rather unsafe configuration. If you use this, you are putting yourself at risk. (http://insecurety.net/?p=912)

Search for the portion of Your Apache configuration file which has the ScriptAlias section. Add the line from below immediately after the ScriptAlias line for “cgi-bin”. Make sure that the line goes before the closing </IfModule> for that <IfModule alias_module> section.

ScriptAlias /php/ “/usr/bin/”

Search for the “AddType” comment block, and add the AddType line below. You can find the AddType lines in the <IfModule mime_module> section. Add the following line just before the closing </IfModule> for that section.

Add this line to the end of that file:

Action application/x-httpd-php “/php/php-cgi”

Search for this section:

<Directory “/usr/share/cgi-bin”> AllowOverride None Options None Order allow,deny Allow from all </Directory>

Add the following lines immediately after the section you just found.

<Directory “/usr/bin”> AllowOverride None Options none Order allow,deny Allow from all </Directory>

NOTE: The /usr/bin directory contains far more than just php-cgi. On a public server it could be wise to move php-cgi to its own directory and then configure Apache to use that separate directory instead!

Configuring the default Index Page

Apache Httpd Server

Search for “DirectoryIndex index.html” and change to:

Restart the Apache Web Server

Test PHP

Apache Http Server Uninstall

Create /usr/share/htdocs/index.php with the following content:

Open your browser and access the file

When apache accept TCP connection, but not send respon. In log is:[notice] child pid 19745 exit signal Segmentation fault (11)

It's necessary to set lower debug level: LogLevel error

Normally apache will not start on boot, I believe its deliberate so that it wont conflict with the default (uHTTPd) web-server, you will need to add a file to '/etc/init.d/', probably naming it apache and setting it for execution (chmod +x), the file itself is rather simple :

#!/bin/sh /etc/rc.common# Example script# Copyright (C) 2007 OpenWrt.orgSTART=60STOP=15start() { echo launch apache # commands to launch application apachectl start}restart() { echo re-start apache # commands to launch application apachectl restart}stop() { echo stop apache # commands to kill application apachectl stop}

once in place, you can issue the command '/etc/init.d/apache enable' to spawn the server @ boot

Apache Httpd Server
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies