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.
I think this might be what you are looking for http://wiki.apache.org/httpd/RunningMultipleApacheInstances
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/mod_proxy.so LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so # httpd-perl.conf Listen 81 ErrorLog /var/log/httpd-perl-error.log LoadModule perl_module libexec/apache22/mod_perl.so # httpd-python.conf Listen 82 ErrorLog /var/log/httpd-python-error.log LoadModule python_module libexec/apache22/mod_python.so # httpd-php.conf Listen 83 ErrorLog /var/log/httpd-php-error.log LoadModule php5_module libexec/apache22/libphp5.so
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 ServerName blog.company.com ProxyPass / http://localhost:83/ ProxyPassReverse / http://localhost:83/ [... additional directives here ... ] </VirtualHost> <VirtualHost *:80> DocumentRoot /www/svn ServerName svn.company.com ProxyPass / http://localhost:82/ ProxyPassReverse / http://localhost:82/ [... additional directives here ... ] </VirtualHost> # 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 appropriate config file
The linked resource has more detail on editing rc.conf file for this but touches specifically 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_enable="YES" apache22_profiles="proxy perl python php" # the apache proxy instance apache22_proxy_configfile="/usr/local/etc/apache22/httpd-proxy.conf" apache22_proxy_enable="YES" # the apache perl instance apache22_perl_configfile="/usr/local/etc/apache22/httpd-perl.conf" apache22_perl_enable="YES" # the apache python instance apache22_python_configfile="/usr/local/etc/apache22/httpd-python.conf" apache22_python_enable="YES" # the apache php instance apache22_php_configfile="/usr/local/etc/apache22/httpd-php.conf" apache22_php_enable="YES"
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 apache22_php_configfile="/usr/local/etc/apache22/httpd-php.conf" apache22_php_enable="NO"
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 Ubuntu/Debian you're using you may be lucky ... or not.
The feature appeared in Debian in version 2.2.14-6 in Feb 2010: http://lists.alioth.debian.org/pipermail/pkg-apache-commits/2010-February/000295.html
In Ubuntu, the apache2 packages in Maverick (10.10) contain these patches: http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.2.16-1ubuntu3.1/changelog
However the Lucid (10.04, Long Term Support Release) apache2 apparently do not: http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.2.14-5ubuntu8.4/changelog
Documentation can be found in /usr/share/doc/apache2/README.multiple-instances
Thanks for your detailed answer but later I found this link http://someofmylearnings.wordpress.com/2011/07/02/multiple-apache2-instances-on-ubuntu/ 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
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.