Before compiling Apache, you must know the current configuration line for PHP, as you will have to recompile PHP and most likely you have PHP installed on your webserver. The easiest way to do that is to create a file called phpinfo.php on the root directly on a website hosted on your webserver, containing the following:
Then, open this file using your browser (e.g., http://www.yoursite.com/phpinfo.php, where yoursite.com is the URL of the website containing the phpinfo.php file), and copy everything that is listed beside “Configure Command”.
Another way to achieve the same result is to run the command (you will have to change the “/usr/local/apache2/” path to point to where Apache is actually installed on your server):
#/usr/local/apache2/php/bin/php -i | grep “Configure Command”
In both cases, you will have to remove all single quotation marks (apostrophes) from the text you copied.
If you need to know where Apache is currently installed on your system, simply run:
#find / -name apxs
One big difference between Apache 2.4 and previous versions is that the APR (Apache Portable Runtime) modules don’t come together with Apache anymore. Therefore, besides downloading the latest version of Apache 2.4, you must download the latest versions of APR and APR-util, which are available at http://apr.apache.org/download.cgi.
Let’s assume that you downloaded all three files (Apache, APR, and APR-util) to the directory /downloads. You must decompress the three files, and move APR and APR-util to the correct directories under the Apache compilation directory. For example (replace x, y, and z with the correct numbers, depending on the versions you downloaded):
/downloads# tar -xvzf httpd-2.4.x.tar.gz
/downloads# tar -xvzf apr-x.y.z.tar.gz
/downloads# tar -xvzf apr-util-x.y.z.tar.gz
/downloads# mv apr-x.y.z /downloads/httpd-2.4.x/srclib/apr
/downloads# mv apr-util-x.y.z /downloads/httpd-2.4.x/srclib/apr-util
Now you have the proper structure to compile Apache (change –prefix=/usr/local/apache2 to where you want to install Apache; we suggest you use the path to the current Apache installation):
/downloads# cd httpd-2.4.x
/downloads/httpd-2.4.x# ./configure –prefix=/usr/local/apache2 –enable-deflate –enable-mods-shared=all –with-included-apr –enable-nonportable-atomics=yes
/downloads/httpd-2.4.x# make && make install
If you want to use the “old” “prefork” engine, add –with-mpm=prefork to the configure line.
Now you have Apache 2.4 compiled. You must now recompile PHP, if you have PHP installed on the system (most likely).
Assuming, again, that you downloaded the latest PHP packed to /downloads, you must:
/downloads/httpd-2.4.x# cd /downloads
/downloads# tar -xvzf php-x.y.z.tar.gz
/downloads# cd php-x.y.z
/downloads/php-x.y.z# [paste here the compilation line you obtained from phpinfo]
/downloads/php-x.y.z# make && make install
If you use a caching system such as Xcache (which we highly recommend you install to improve performance of your webserver), you must recompile it as well. Assuming you downloaded the latest version of Xcache to /downloads, you must run the following commands (you must replace “/usr/local/apache2/php/” with the actual PHP installation directory, if different):
/downloads/php-x.y.z# cd /downloads
/downloads# tar -xvzf xcache-x.y.z.tar.gz
/downloads# cd xcache-x.y.z
/downloads/xcache-x.y.z# /usr/local/apache2/php/bin/phpize –clean
/downloads/xcache-x.y.z#./configure –enable-xcache –enable-xcache-optimizer –with-php-config=/usr/local/apache2/php/bin/php-config
/downloads/xcache-x.y.z# make && make install
Pay attention to the output provided by the installation script, as it will show you where xcache.so was installed (it will be a path such as “/usr/local/apache2/php/lib/php/extensions/no-debug-zts-20090626/”.
If you had Xcache installed before, all you need to do now is to edit the php.ini file (located at /usr/local/apache2/php in our examples), find xcache.so, delete the line where it is present, and replace it with something like:
extension = /usr/local/apache2/php/lib/php/extensions/no-debug-zts-20090626/xcache.so
The path must be the one provided by the installation script. Save the php.ini file and you are now ready to make the proper adjustments to the httpd.conf file as described on the next page.
If your previous PHP installation didn’t have Xcache installed, you must add the proper configuration lines to php.ini, as follows (of course you must change “/usr/local/apache2/php/” to the actual location of php.ini, if you installed Apache and PHP under a different directory):
/downloads/xcache-x.y.z# cat xcache.ini>>/usr/local/apache2/php/php.ini
You must now edit php.ini file, look for xcache.so, and replace the line where it is present with the line published above (“extension…”).
You also must configure “xcache.count” with the number provided by the command cat /proc/cpuinfo |grep -c processor.
And we recommend you change xcache.optimizer from “Off” to “On”.
You can fine-tune Xcache later by checking its control panel, after Apache is online for a while. Xcache’s control panel is available under the “xcache” directory under Xcache’s installation directory. For example, you can run the following command to have Xcache’s control panel available at http://www.yoursite.com/xcache (you must replace /www/yoursite with the actual path to your website on your server, of course):
/downloads/xcache-x.y.z# mv xcache /www/yoursite
Let’s now see the additional configurations we must perform.