Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How can I run two instances of apache on the same system and start and stop them independently of each other. Any help or leads are appreciated.

share|improve this question

2 Answers 2

I think this might be what you are looking for

For reference of the content in the above link

1) Install Apache on your server

sudo apt-get install apache2
sudo apt-get install libapache2-mod-perl2
sudo apt-get install other-lib-mods-needed

2) Configure separate apache configurations for each instance you want to run

For ubuntu, this should be in /etc/apache2 Essentially for each instance you need to listen on a different port.

# httpd-proxy.conf
Listen 80
ErrorLog /var/log/httpd-proxy-error.log
LoadModule proxy_module                 libexec/apache22/
LoadModule proxy_http_module            libexec/apache22/

# httpd-perl.conf
Listen 81
ErrorLog /var/log/httpd-perl-error.log
LoadModule perl_module                  libexec/apache22/

# httpd-python.conf
Listen 82
ErrorLog /var/log/httpd-python-error.log
LoadModule python_module                libexec/apache22/

# httpd-php.conf
Listen 83
ErrorLog /var/log/httpd-php-error.log
LoadModule php5_module                        libexec/apache22/

In this example, there would be 4 different instances running, each processing a different module type, i.e. one for perl, one for python, etc.

Now, you 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' apache, whereas requests for your wordpress blog are passed to your 'php' apache instance. Let's edit 'httpd-proxy.conf' again:

# httpd-proxy.conf
NameVirtualHost *:80
<VirtualHost *:80>
 DocumentRoot /www/wordpress
 ProxyPass / http://localhost:83/
 ProxyPassReverse / http://localhost:83/
 [... additional directives here ... ]
<VirtualHost *:80>
 DocumentRoot /www/svn
 ProxyPass / http://localhost:82/
 ProxyPassReverse / http://localhost:82/
 [... additional directives here ... ]
# you get the idea ...  

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

 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/proxy-httpd.conf configtest
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/proxy-httpd.conf start
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/perl-httpd.conf configtest
 /usr/local/sbin/apachectl -f /usr/local/etc/apache22/perl-httpd.conf start
 # and so on ...

**3) Configure the init scripts to start apache with the approriate config file The linked resource has more detail on editing rc.conf file for this but touches specificly with dealing with ubuntu so I both of these sections I will highlight below.

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.

# /etc/rc.conf
apache22_profiles="proxy perl python php"

# the apache proxy instance

# the apache perl instance

# the apache python instance

# the apache php instance

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 apache instance manually, you can just edit '/etc/rc.conf' and >say, e.g. :

 # the apache php instance

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

 /usr/local/etc/rc.d/apache22 start php
 /usr/local/etc/rc.d/apache22 stop perl

3b) for ubuntu

I'm not sure this will be similar (and painless) as in the case of FreeBSD (see section on rc.conf above). The apache rc scripts installed with the apache port in FreeBSD have been aware of the possibility of different profiles for years now.

Recently, the ubuntu/debian init scripts (e.g. /etc/init.d/apache2) have been updated to support multiple instances of apache (e.g. multiple configurations, named /etc/apache2-$SUFFIX). Depending on the release of debian/ubuntu you're using you may be lucky ... or not.

The feature appeared in Debian in version 2.2.14-6 in Feb 2010:

In Ubuntu, the apache2 packages in Maverick (10.10) contain these patches:

However the Lucid (10.04, Long Term Support Release) apache2 apparently do not:

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

share|improve this answer
What a big fat mess. No offending to you, I just want to say that it's a pain in the S to do such stuff with linux. – Sliq Aug 15 '13 at 21:26
Not sure I see the second mentioned installation process as any in reference to the original reply... Why do we need the proxy? Is each individual configuration not sufficient to simply bind to distinct ports? – Alex.Barylski Feb 21 at 20:00

Thanks for your detailed answer but later I found this link The procedure shown in this very simple.

When we install Apache, there is a /usr/share/doc/apache2.2-common/README.multiple-instances file which you gives an idea of what exactly needs to be done to create an Apache instance.

Inside the same directory there is an examples directory which contains a script named setup-instance that we can use to create an Apache instance. So, to create another Apache instance all that needs to be done is:

sh /usr/share/doc/apache2.2-common/examples/setup-instance web-server1

where web-server1 is a suffix. That is, it appends “apache2-” by default to your instance name.

That will create a new directory /etc/apache-web-server1 which contains all config files. It would also create /etc/init.d/apache-web-server1 which you can use to start the new Apache instance.

share|improve this answer
On Ubuntu 14.04 LTS the doc directory is /usr/share/doc/apache2/ – Josip Rodin Jun 30 at 14:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.