====== Install Apache2 (and run multiple instances of it) ====== As stated earlier, we'll try to deploy Apache in such manner that it will be possible to run **multiple instances** of it, each with a different configuration. <WRAP info round 50%> Sorry, but this page is currently a bit of a mess as I'm struggling to get a working configuration. It will get cleaned up as soon as I get time to sort it all out :-\ </WRAP> ----- ===== Remove the Existing Apache Installation ===== ----- In case you have a previous install of Apache, you can wipe it off your system using the following commands: Let's check if you have Apache installed: <code> sudo apachectl -V </code> The answer will clearly indicater whether your system HAS Apache installed or not, if necessary remove it using: <code> sudo apt-get --purge remove apache2* </code> <wrap important>Use the next command **ONLY IF YOU ARE READY TO LOOSE YOUR CURRENT APACHE CONFIGURATION!**</wrap>\\ To make sure all the configs are gone, do: <code> sudo rm -fr /etc/apache2 </code> === In Case You Installed from Sources ==== You should then stop the service: <code> sudo service apache2 stop </code> Then refer to the [[packages:amp:apache#Places of Interest Regarding Apache|Places of Interest Regarding Apache]] chapter on this page and remove all relevant files...\\ A wise move would be to **backup** some of those files/directories before removing them. Specially an existing /etc/apache2 should be preserved: <code> sudo cp -a /etc/apache2 /etc/apache2.bak sudo rm -rf /etc/apache2 sudo rm -rf /etc/init.d/apache2 sudo rm -rf /usr/sbin/a2* sudo rm -rf /usr/sbin/apache* </code> In case of a previous source install, it might be wise to also check: <code> /usr/lib/apache2 </code> ----- ===== Install Latest Apache (updating it from sources) ===== We'll need to compile apache from sources in order to make sure the required options for compatibility with Phpfarm are met. Note that this method also enables you to recompile apache, in a Linux Mint Debian compatible manner, with your own selection of options in case you need a specific configuration. We first install the necessary packages: <code> sudo apt-get install build-essential apache2 libpcre3-dev </code> On LMDE UP7 this will get the apache 2.4.6 version installed. ==== libapr Messed Up ==== At a cetain point, if you get lost (re)installing apache and even a complete wipe off and re-install brings you an error of type: <code> sudo service apache2 restart [FAIL] Restarting web server: apache2 failed! [warn] The apache2 configtest failed. ... (warning). Output of config test was: /usr/sbin/apache2: symbol lookup error: /usr/sbin/apache2: undefined symbol: apr_os_uuid_get Action 'configtest' failed. The Apache error log may have more information. </code> You might have reached a point where symlinks in// /usr/lib/// might have got messed up.\\ In my case the solution was to re-create the symlinks. The messsed up situation was: <code> cd /usr/lib ls -la libapr* -rw-r--r-- 1 root root 1547872 Dec 30 03:45 libapr-1.a -rwxr-xr-x 1 root root 821 Dec 30 03:45 libapr-1.la lrwxrwxrwx 1 root root 17 Dec 30 03:45 libapr-1.so -> libapr-1.so.0.4.8 lrwxrwxrwx 1 root root 17 Dec 30 15:28 libapr-1.so.0 -> libapr-1.so.0.5.0 -rw-r--r-- 1 root root 189736 Jul 5 00:08 libapr-1.so.0.4.8 -rwxr-xr-x 1 root root 969932 Dec 30 03:37 libapr-1.so.0.5.0 -rw-r--r-- 1 root root 1051208 Dec 30 03:45 libaprutil-1.a -rwxr-xr-x 1 root root 891 Dec 30 03:45 libaprutil-1.la lrwxrwxrwx 1 root root 21 Dec 30 03:45 libaprutil-1.so -> libaprutil-1.so.0.5.2 lrwxrwxrwx 1 root root 21 Dec 30 15:28 libaprutil-1.so.0 -> libaprutil-1.so.0.5.3 -rw-r--r-- 1 root root 168576 May 5 2013 libaprutil-1.so.0.5.2 -rwxr-xr-x 1 root root 653071 Dec 30 03:37 libaprutil-1.so.0.5.3 </code> Noticed that the libapr-1.so and libapr-1.so.0 symlink to different files?\\ Same for libaprutil-1.so and libaprutil-1.so.0... I first tried to re-symlink to the "higher" versions (0.5.0 and 0.5.3), but it failed.\\ Re-symlinking to the "lower" versions (0.4.8 and 0.5.2) did the trick: <code> cd /usr/lib ln -sf libapr-1.so.0.4.8 libapr-1.so ln -sf libapr-1.so.0.4.8 libapr-1.so.0 ln -sf libaprutil-1.so.0.5.2 libaprutil-1.so ln -sf libaprutil-1.so.0.5.2 libaprutil-1.so.0 ls -la libapr* -rw-r--r-- 1 root root 1547872 Dec 30 03:45 libapr-1.a -rwxr-xr-x 1 root root 821 Dec 30 03:45 libapr-1.la lrwxrwxrwx 1 root root 17 Dec 30 15:56 libapr-1.so -> libapr-1.so.0.4.8 lrwxrwxrwx 1 root root 17 Dec 30 15:56 libapr-1.so.0 -> libapr-1.so.0.4.8 -rw-r--r-- 1 root root 189736 Jul 5 00:08 libapr-1.so.0.4.8 -rwxr-xr-x 1 root root 969932 Dec 30 03:37 libapr-1.so.0.5.0 -rw-r--r-- 1 root root 1051208 Dec 30 03:45 libaprutil-1.a -rwxr-xr-x 1 root root 891 Dec 30 03:45 libaprutil-1.la lrwxrwxrwx 1 root root 21 Dec 30 15:56 libaprutil-1.so -> libaprutil-1.so.0.5.2 lrwxrwxrwx 1 root root 21 Dec 30 15:57 libaprutil-1.so.0 -> libaprutil-1.so.0.5.2 -rw-r--r-- 1 root root 168576 May 5 2013 libaprutil-1.so.0.5.2 -rwxr-xr-x 1 root root 653071 Dec 30 03:37 libaprutil-1.so.0.5.3 </code> At that point restarting the apache service DID work again: <code> service apache2 restart [....] Restarting web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message . ok </code> <WRAP important> After a restart or issuing an apt-get instruction, it seems the symlink problem reappears... </WRAP> ==== Install apache suEXEC ==== suEXEC can be a bit fiddly in that the document root (the parent folder for all web content) is generally set at compile-time. This has led to numerous guides giving instructions for retrieving the Apache source and reconfiguring and recompiling the suEXEC module to set /home as the document root instead of /var/www. Fortunately for us, Debian provides a custom suEXEC package, apache2-suexec-custom, which has been modified to permit post-compilation reconfiguration by way of a simple configuration file. <code> sudo apt-get install apache2-suexec-custom </code> The default configuration file for apache2-suexec-custom is **/etc/apache2/suexec/www-data**. The first line of the file can be changed to use a non-default document root. ==== Install mod_fcgid ==== <code> sudo apt-get install libapache2-mod-fcgid sudo a2enmod rewrite sudo a2enmod suexec sudo a2enmod include sudo a2enmod fcgid sudo service apache2 restart </code> Please consult the [[packages:amp:php#create php execution script|Phpfarm setup information]] for further configuration. ==== Differences With Fresh Install === Missing files: <code> /etc/apache2/conf-available/javascript-common.conf /etc/apache2/conf-available/php-fcgidsetup.conf /etc/apache2/mods-available/dnssd.conf /etc/apache2/mods-available/dnssd.load /etc/apache2/mods-available/fcgid.conf /etc/apache2/mods-available/fcgid.load /etc/apache2/mods-enabled/actions.conf /etc/apache2/mods-enabled/actions.load /etc/apache2/mods-enabled/dnsdd.conf /etc/apache2/mods-enabled/dnsdd.load /etc/apache2/mods-enabled/fcgid.conf /etc/apache2/mods-enabled/fcgid.load /etc/apache2/mods-enabled/include.load /etc/apache2/mods-enabled/rewrite.load /etc/apache2/mods-enabled/suexec.load </code> All custom domains <code> /etc/apache2/sites-available/*domain*.conf /etc/apache2/sites-enabled/*domain*.conf </code> /etc/apache2/conf-available/serve-cgi-bin.conf <code> 10: + <IfModule mod_fcgid.c> Define ENALBLE_USR_LIB_CGI_BIN </IfModule> </code> /etc/apache2/sites-available/000-default.conf <code> 30: + <Directory "/var/www"> AddHandler php-cgi .php Action php-cgi /cgi-bin-php/php-cgi-5.3.25 <FilesMatch "\.php$"> SetHandler php-cgi </FilesMatch> </Directory> </code> /etc/apache2/apache2.conf <code> 70: + ServerName "localhost" 167: - AllowOverride None + AllowOverride All </code> ----- ===== Download the latest version ===== We need to download the latest version from [[http://httpd.apache.org/download.cgi]]\\ [[http://apache.cu.be//httpd/httpd-2.4.7.tar.gz]] for example being the latest stable as of this writing. To play it safe, you could verify that the downloaded package hasn't been modified using the checksum available next to the download link you've used **before configuring and making**: <code> sha1sum httpd-2.4.7.tar.gz | grep ‘9a73783b0f75226fb2afdcadd30ccba77ba05149′ </code> If a line is returned, the file is OK, we can proceed, else, download from another mirror. <code> sudo mkdir /opt/apache cd /opt/apache sudo wget http://apache.cu.be//httpd/httpd-2.2.26.tar.gz sudo tar xzf httpd-2.2.26.tar.gz </code> Finally gave up on trying to go for 2.4.7 and fell back to 2.2.26. <wrap todo>More on this to come...</wrap> ==== Build apache2 ==== === APR library (version 4.4.7) === The Apache Portable Runtime is required to build the latest apache2, you'll need to have the latest **apr** and **apr-util** libraries available in the //srclib// directory to be able to compile. These are readily available in the 2.2.26 package but not in the 2.4.7 one. What you have to do is to go to [[http://apr.apache.org/download.cgi]] and download the latest apr and apr-util libraries, then put the files in you apache's installer directory under /path/to/apache/installer/srclib/, and extract them. Finally you need to change the extracted directories names, removing the version number: <code> cd /opt/apache/httpd-2.2.26/srclib sudo wget http://apache.cu.be//apr/apr-1.5.0.tar.gz sudo wget http://apache.cu.be//apr/apr-util-1.5.3.tar.gz sudo tar xfz apr-1.5.0.tar.gz sudo tar xfz apr-util-1.5.3.tar.gz sudo mv apr-1.5.0 apr sudo mv apr-util-1.5.3 apr-util </code> === Go make apache2 === We're now ready for compilation, the following commands will build apache2 with the debian layout and with program name apache2.\\ Some options are specifically crafted to suit our [[packages:amp:php|Phpfarm installation]]. The important options regarding Phpfarm are: * enable-so * enable-suexec * enable-suexec-caller=daemon – You can change this according to which user your apache runs under <code> cd /opt/apache/httpd-2.2.26 sudo ./configure --with-pcre=/usr --with-included-apr --enable-layout=Debian --enable-mods-shared=all --enable-so --enable-mod-rewrite --enable-suexec --with-suexec-caller=daemon --with-program-name=apache2 --enable-logio --disable-actions --disable-authn-file --disable-authn-default --disable-authz-groupfile --disable-authz-host --disable-authz-user --disable-authz-default --disable-auth-basic --disable-include --disable-filter --disable-env --disable-setenvif --disable-mime --disable-status --disable-autoindex --disable-asis --disable-negotiation --disable-dir --disable-userdir --disable-alias --enable-unixd ; sudo make sudo make install </code> ==== Modify /usr/sbin/apachectl file ==== We need to point the envvars to// /etc/apache2/envvars//. To do so, find and replace the path in// /usr/sbin/apachectl// to **/etc/apache2/envvars**. <code> sudo nano /usr/sbin/apachectl -------------------- CTRL-w > envvars (will locate the pointer on the first occurence) change (twice: for me lines 48 & 49) /usr/sbin/envvars to /etc/apache2/envvars CTRL-x > Y -------------------- </code> Once you finish editing and save it. Copy this file to// /etc/init.d/apache2//. This will be the new **/etc/init.d/apache2** script. <code> sudo cp /etc/init.d/apache2 /opt/apache/httpd-2.4.7/etc-init.d-apache2.back sudo cp /usr/sbin/apachectl /etc/init.d/apache2 </code> ==== SSLMutex Issue ==== If you use SSL or have mod_ssl enabled, you will need to specify the SSLMutex directory to avoid Apache2 startup problems. The easiest way to do this **create ssl.conf file in the /etc/apache2/conf.d** directory. The content of the file is below: <code> sudo nano /etc/apache2/conf.d/ssl.conf -------------------- <IfModule mod_ssl.c> SSLMutex file:/etc/apache2/logs/ssl_mutex </IfModule> -------------------- </code> === Reported startup errors === Update from apache 2.2 to 2.4 has a few configuration changes, they can be [[httpd.apache.org/docs/current/upgrading.html|found on this page]], trying to restart the deamon sent a few errors as follow: **Include must have an absolute path**\\ Edit /etc/apache2/apache2.conf\\ I had to modify /etc/apache2/apache2.conf and add /etc/apache2/ in the following lines <code> 140: IncludeOptional /etc/apache2/mods-enabled/*.load 141: IncludeOptional /etc/apache2/mods-enabled/*.conf 144: Include /etc/apache2/ports.conf 216: IncludeOptional /etc/apache2/conf-enabled/*.conf 219: IncludeOptional /etc/apache2/sites-enabled/*.conf </code> **Configuration error: More than one MPM loaded.**\\ Looking in the// /etc/apache2/mods-enabled// directory showed that mpm_event was active. Although checking the compiled in modules of apache returned: <code> sudo apache2ctl -l Compiled in modules: core.c mod_so.c http_core.c event.c </code> Event seemed to be loaded twice since it's already compile in... We need to disable the mpm_event module: <code> sudo a2dismod mpm_event </code> **Invalid command 'User'**\\ If you get this error, you probably don't have the mod_unixd module enabled. It should have been compiled along apache with the settings given above. ==== Restart your Apache Server ==== <code> sudo /etc/init.d/apache2 restart </code> ----- ===== Compile Apache2 from Sources ===== ----- To have a fine control over the options that we need enabled in our apache2 server, we'll go for the compilation from source method. Here's how to proceed: ==== Download Sources ==== First, go to the [[http://httpd.apache.org/download.cgi|Apache download page]] and identify the version you'd like to install (as of this writing, the latest stable version being 2.4.7). Download it using the provided link or your can wget it: <code> sudo mkdir /opt/apache cd /opt/apache sudo wget http://apache.cu.be//httpd/httpd-2.4.7.tar.gz </code> It's always safer to verify that the downloaded package hasn't been modified using the checksum available next to the download link you've used: <code> sha1sum httpd-2.4.7.tar.gz | grep ‘9a73783b0f75226fb2afdcadd30ccba77ba05149′ </code> If a line is returned, the file is OK, we can proceed, else, return to step 1. ==== Compile from Sources ==== We will now extract the archive and move into the newly created directory: <code> sudo tar xzf httpd-2.4.7.tar.gz cd httpd-2.4.7 </code> === configure for compiling === Let's now configure the options we want for our apache2 install, the options specified here are specifically crafted to suit our [[packages:amp:php|Phpfarm installation]]. The important options regarding Phpfarm are: * enable-so * enable-suexec * enable-suexec-caller=daemon – You can change this according to which user your apache runs under. The other parameters are: * prefix=/usr/local/apache2 tells apache where to install all the files needed. In this case we are installing apache to /usr/local/apache2 directory. * enable-mods-shared=all tells apache to compile all modules as dynamic shared modules. We can then enable these modules in httpd.conf file, via the LoadModule directive. * enable-mod-rewrite tells apache to enable mod rewrite. <code> sudo ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-mods-shared=all --enable-so --enable-mod-rewrite --enable-suexec --with-suexec-caller=daemon sudo make sudo make install </code> === possible errors === At configure or make time you might encoounter some errors based on your activated options and the available libraries on your system, here are a few examples: **mod_deflate** <code> mod_deflate has been requested but can not be built due to prerequisite failures </code> <code> sudo apt-get update sudo apt-get install zlib1g-dev </code> **Bundled APR** <code> error: Bundled APR requested but not found at ./srclib/. </code> This one is a bit trickier, you need to go to [[http://apr.apache.org/download.cgi]] and download the latest apr and aprutil libraries, then put the files in you apache's installer directory under /path/to/apache/installer/srclib/, and extract them. Finally you need to change the extracted directories names, removing the version number: <code> cd /opt/apache/httpd-2.4.7/srclib sudo wget http://apache.cu.be//apr/apr-1.5.0.tar.gz sudo wget http://apache.cu.be//apr/apr-util-1.5.3.tar.gz sudo tar xfz apr-1.5.0.tar.gz sudo tar xfz apr-util-1.5.3.tar.gz sudo mv apr-1.5.0 apr sudo mv apr-util-1.5.3 apr-util </code> **pcre-config for libpcre not found**\\ You'll also need to download the library, this time from [[ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/]], select the latest version and download it, extract, configure and make it: <code> pcre-config for libpcre not found </code> <code> sudo mkdir /opt/pcre cd /opt/apache/httpd-2.4.7/srclib/ sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz sudo tar xzf pcre-8.34.tar.gz sudo mv pcre-8.34 pcre cd /pcre sudo ./configure sudo make sudo make install </code> If at runtime you get an error of type //**error while loading shared libraries: libpcre.so.1**//: <code> cd /lib/x86_64-linux-gnu sudo ln -s libpcre.so.3.13.1 libpcre.so.1 </code> After you fixed the errors, go back to your apache installer's directory and relaunch ./config, make and make install... ==== Test your Apache Installation ==== In your browser application, go to [[http://localhost]], you should get a message like: //**Unable to connect**// Startup apache2: <code> sudo /usr/local/apache2/bin/apachectl -k start </code> In your browser application, go to [[http://localhost]], you should get a message like: //**It works!**// ===== Install the apache2 Package(s) ===== <wrap important>**THIS PROCEDURE HAS BEEN REPLACED BY THE COMPILATION PROCESS**</wrap> You need to install not only the apache2 package, but also, the corresponding libapache2-* packages for the modules you need in your Apache instances. Also note that we're choosing the suexec version of Apache, mainly to fulfill the requirements for [[packages:amp:php|running phpfarm]]: <code> sudo apt-get update sudo apt-get install apache2-suexec sudo apt-get install libapache2-mod-perl2 libapache2-mod-python libapache2-mod-php5 libapache2-mod-fcgid libapache2-mod-fastcgi ... </code> You can make sure that apache is running using: <code> sudo service apache2 status </code> It might be important to note that the extra packages that were installed included php: php5-cli php5-common php5-json.\\ This means **you now have a version of php installed at the system level**, to find out exactly what version it is: <code> php --version PHP 5.5.1-2 (cli) (built: Aug 5 2013 14:10:28) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies </code> ===== Managing Rights on Web Files ===== It can sometimes become complex to manage access rights on the directories in /var/www. Specifically when different people (developers) need to access the same directory. Here is one solution that I think is a pretty good one to resolve this kind of problem. It is inspired by [[http://serverfault.com/questions/6895/whats-the-best-way-of-handling-permissions-for-apache2s-user-www-data-in-var|this thread on serverfault.com]]. === Create a new group for www editors === Then add all necessary users to that group: <code> sudo groupadd www-pub sudo usermod -a -G www-pub <username> </code> We use the usermod command with the -a option, in order to append to existing groups. You can check what groups a user is member of using: <code> sudo groups <username> </code> === Change ownership of everything under /var/www === Set ownership of all directories and files in /var/www to root:www-pub <code> sudo chown -R root:www-pub /var/www </code> === Change permissions of to directory === In the next chmod command, used values mean: * 2: setting the "Set group ID" (SETGID) bit * 7: rwx for owner (root) * 7: rwx for group (www-pub) * 5: rx for world (including apache www-data user) <code> sudo chmod 2775 /var/www </code> Setting the SETGID bit causes the group (www-pub) to be copied to all new files/directories created in that directory. Other options are: * SETUID (4): to copy the user id * STICKY (1): which, I think, let only the owner delete files Note that we didn't use the -R (recursive) option, thus only the top /var/www directory has it's rights changed. That's because the -R option would discriminate between directories and files and would apply the same rights to both types. === Change permissions on directories === To selectively apply the chmod command only onto directories, we use the find command like so: <code> sudo find /var/www -type d -exec chmod 2775 {} + </code> === Change permissions on files === <code> sudo find /var/www -type f -exec chmod 0664 {} + </code> === Change the "umask" for your users === The umask controls the default file creation permissions, 0002 means files will have 664 and directories 775. Setting this can be achieved by editing the /etc/profile. It means files created by one user, will be writable by another in the same, www-pub, group without the need to chmod them. <wrap todo>The umask is now controled by pam_umask -> Dig this !</wrap> ==== Logout / Login ==== You'll have to logout, then login again in order for the group changes to take effect. ===== Places of Interest Regarding Apache ===== The Debian/Ubuntu apache layout has some specifics that are detailed in the [[http://wiki.apache.org/httpd/DistrosDefaultLayout#Debian.2C_Ubuntu_.28Apache_httpd_2.x.29|apache wiki distros default layout]] page. Managing a web server implies accessing many files, be it configuration or log files. Here is a quick reminder of the places that might be of interest using the Apache server: **Debian, Ubuntu (Apache httpd 2.x)**: * ServerRoot :: /etc/apache2 * DocumentRoot :: /var/www * Apache Config Files :: /etc/apache2/apache2.conf * :: /etc/apache2/ports.conf * Default VHost Config :: /etc/apache2/sites-available/default, /etc/apache2/sites-enable/000-default * Module Locations :: /etc/apache2/mods-available, /etc/apache2/mods-enabled * ErrorLog :: /var/log/apache2/error.log * AccessLog :: /var/log/apache2/access.log * cgi-bin :: /usr/lib/cgi-bin * binaries (apachectl) :: /usr/sbin * start/stop :: /etc/init.d/apache2 (start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean) Notes: The Debian/Ubuntu layout is fully documented in /usr/share/doc/apache2/README.Debian Debian/Ubuntu use symlinks to configure vhosts and load modules. Configuration files are created in their respective sites-available and mods-available directories. To activate vhosts and modules, symlinks are created in the respective sites-enabled and mods-enabled directories to the config files in either sites-available and mods-available. Debian provides scripts to handle this process called 'a2ensite' and 'a2enmod' which activates vhosts and modules. The default vhost is defined in /etc/apache2/sites-available/default, and overrides the [[http://httpd.apache.org/docs/current/mod/core.html#documentroot|DocumentRoot]] set in the server context. ===== Setup for Running Multiple Instances of Apache ===== <wrap important>**THIS DOESN'T WORK PROPERLY AT THE MOMENT!!!**</wrap>\\ The following section is a slight rewrite of: [[http://larig.wordpress.com/2010/06/09/multiple-instances-of-apache/]] === Script Check === First things first: check that the apache start/stop script\\ **/etc/init.d/apache2**\\ includes the line: <code> DIR_SUFFIX="-${0##*/apache2-}" or DIR_SUFFIX="-${SCRIPTNAME##apache2-}" </code> If not, these notes will be pretty much no help to you, and you should consider upgrading to a version that has it. ==== System Configuration ==== It’s easy (in debian at least) to have more than one instance of apache2 running because the management scripts check whether they were invoked as “somethingapache2″ or as “somethingapache2-something”. In the notes below ‘b’ is used as the suffix, so paths will end with ‘apache2-b’. === Paths To Be Copied === We need to identify what needs to be copied or linked from the original instance of apache2, so we need a list of what paths are included in our current instance. <code> sudo cd / && ln -s -nf var/lib/dpkg/info dinfo </code> This means that the path info for package <pkg> is available at /dinfo/<pkg>.list Now, lets write a shell script to automate directories replication. The code below uses "echo" to allow verification of what will be done, when the output of this script seems acceptable, simply change "**echo**" for "**cp -a**" and it will effectively duplicate the directories: <code> sudo nano apache-dirdup.sh #!/bin/bash DIR_SUFFIX="b" for p in $(grep apache2$ /dinfo/apache2.list \ | grep -Fv share \ | grep -Fv init.d \ | grep -Fv lib); do echo $p "${p}-$DIR_SUFFIX" done (Ctrl-x - Y) to exit nano saving the file. </code> Make sure that your script is executable: <code> sudo chmod ugo+x apache-dirdup.sh </code> On my system it resulted in the following output: <code> sudo ./apache-dirdup.sh /var/cache/apache2 /var/cache/apache2-b /var/log/apache2 /var/log/apache2-b /etc/cron.daily/apache2 /etc/cron.daily/apache2-b /etc/logrotate.d/apache2 /etc/logrotate.d/apache2-b /etc/apache2 /etc/apache2-b /etc/bash_completion.d/apache2 /etc/bash_completion.d/apache2-b /etc/default/apache2 /etc/default/apache2-b </code> === Path To Be Linked === The idea is exactly the same as for directories replication except that this time, we'll replace "**echo**" by **ln -s -nf**" once the script output seems right: <code> sudo nano apache-dirlink.sh DIR_SUFFIX="b" for p in $(grep -E "sbin/|init.d/" /dinfo/apache2.list \ | grep -F 2); do d=${p%/*} f=${p##*/} if [ $p != "$d/$f" ]; then echo "Paths got mangled ($d) ($f)" >&2 exit 1 fi (cd $d && echo $f "${f}-$DIR_SUFFIX") done (Ctrl-x - Y) to exit nano saving the file. sudo chmod ugo+x apache-dirlink.sh sudo ./apache-dirlink.sh apache2 apache2-b a2enmod a2enmod-b a2query a2query-b apache2ctl apache2ctl-b a2dismod a2dismod-b a2enconf a2enconf-b a2disconf a2disconf-b a2dissite a2dissite-b a2ensite a2ensite-b </code> ==== Run as Different User ==== If you want the new instance to run as a different user, just edit **/etc/apache2-b/envvars**. and look for: <code> export APACHE_RUN_USER=www-data-b export APACHE_RUN_GROUP=www-data-b </code> Make sure www-data-b exists <code> sudo grep www-data-b /etc/passwd www-data-b:x:1001:33:www-data:/var/www:/bin/sh </code> If the above command doesn't return the expected line, create the user <code> sudo useradd -Gwww-data -d/var/www www-data-b </code> Read/edit /etc/passwd to make sure the generated entry is: <code> www-data-b:x:1001:33:www-data:/var/www:/bin/sh </code> Then invoke <code> /etc/init.d/apache2-b start </code> === More paths to be linked === The above all works... until you upgrade the ‘main’ instance of apache and your sibling instances are left out in the cold, possibly broken. Until some handy scripts turn up, the answer is to copy less and link more. <wrap important>Watch out: this time it doesn't "echo" it links immediatelly!</wrap> <code> sudo nano apache-linkmore.sh #!/bin/bash DIR_SUFFIX="b" for d in conf.d mods-available; do (cd /etc/apache2/$d \ && find * -maxdepth 0 -type f) \ | \ (cd /etc/apache2-$DIR_SUFFIX/$d \ && while read f; do ln -s -nf ../../apache2/$d/$f done) done (Ctrl-x - y: to exit nano saving file) sudo chmod ugo+x apache-linkmore.sh sudo ./apache-linkmore.sh </code> <code> cd /etc/apache2-$DIR_SUFFIX # Can add envvars to following list if running as same user for f in apache2.conf httpd.conf; do ln -s -nf ../apache2/$f done </code> === Custom Settings per Instance === So now you have the flexibility to run the new instance as a separate user, to use a separate perl binary, to use the same perl binary but with a completely different modperl environment, and so on. It’s advantageous to keep apache2.conf a symbolic link and never edit it. If you want to have custom settings, eg the number of child processes, just add/edit a file under conf.d. /etc/apache2-b/conf.d/threads: <code> <IfModule mpm_prefork_module> StartServers 2 MinSpareServers 2 MaxSpareServers 4 MaxClients 150 MaxRequestsPerChild 0 <IfModule> </code> ==== ERROR ==== <WRAP alert> At this stage I got an error: <code> service apache2-b start [FAIL] Starting web server: apache2 failed! [warn] The apache2-b configtest failed. ... (warning). Output of config test was: AH00526: Syntax error on line 4 of /etc/apache2-b/mods-enabled/fastcgi.conf: FastCgiIpcDir /var/lib/apache2/fastcgi: access for server (uid 1001, gid 1001) failed: write not allowed by group Action 'configtest' failed. The Apache error log may have more information. </code> </WRAP> No time to dig that at the moment, I'll come back to this later m(