Compile Apache HTTPD 2.4.X & PHP¶
This page hasn't recently updated. Information found here could be outdated and may lead to missconfiguration.
Some of the links and references may be broken or lead to non existing pages.
Please use this docs carefully. Most of the information here now is only for reference or example!
What Is Needed / Requirements¶
Compiling apache from source is very easy you have to follow some steps. In case of almost all linux distributions Apache http server can be installed via its package manager. There are some advantages of compiling Apache (or any other application) from source, but If you don't have any special requirement I advise to install Apache from package manager. But yet in certain cases you have to compile from source:
- You do not have root access. In this case it will be hard to install the necessary packages. :) But If every needed packages are installed you can compile apache. And run it with your own user. If you install apache from package manager, apache will write its log files with root user, and the config files will be writable for only root user. Of course you can give (r/w) permission to other user to these files. I think this scenario is rare, and without root access your possibilities are very limited.
- You can install different version of the application, which cannot be install via package manager.
- You can complie the application with certain flags and options which may be missing in the repository.
- You have to install all dependencies manually.
- Your package manager will unaware of the changes.
- Your applications will have to be updated manually.
- Maybe you package manager will be overwrite the dependencies.
In my case I had to install the following packages:
apt-get install libpcre3-dev
apt-get install libxml2-dev
My OS: Debian GNU/Linux 8 Linux vps10 2.6.32-042stab116.2 #1 SMP Fri Jun 24 15:33:57 MSK 2016 x86_64 GNU/Linux
These packages must be downloaded:
I created a certain user which will be used all over the whole install process and this user will run the apace process.
I modified this user's shell to
/bin/false and home directory to
So this user won't be able to login to the linux box, but you can use
sudo to switch to apache2 user:
sudo -u apache2 bash
Download the necessary sources¶
I put all sources to:
cd /opt/apache2/ mkdir sources cd sources/ wget http://xenia.sote.hu/ftp/mirrors/www.apache.org//httpd/httpd-2.4.23.tar.gz wget http://xenia.sote.hu/ftp/mirrors/www.apache.org//apr/apr-1.5.2.tar.gz wget http://xenia.sote.hu/ftp/mirrors/www.apache.org//apr/apr-util-1.5.4.tar.gz wget http://fr2.php.net/distributions/php-5.6.25.tar.gz
Compile Apache whit apr and apr-util¶
First you have to untar the apache source
Untar apr, apr-util
Rename APR directories
Apache will be installed to
After the make install command you can start you newly installed apache httpd server.
But if you try to start apache you will be get this error:
Yes, only root user can bind ports below 1025. So we have to modify listen port in
After that little modification apache can be started. Check the log file:
cat /opt/apache2/httpd-2.4.23/logs/error_log [Sat Aug 27 12:02:53.021908 2016] [mpm_event:notice] [pid 30164:tid 140121349551872] AH00489: Apache/2.4.23 (Unix) PHP/5.6.25 configured -- resuming normal operations [Sat Aug 27 12:02:53.021972 2016] [core:notice] [pid 30164:tid 140121349551872] AH00094: Command line: '/opt/apache2/httpd-2.4.23/bin/httpd'
Now your apache web server is accessible on port 8080, you can call it from your browser.
Previously we downloaded the php source, now untar it:
This will create a new directory:
/opt/apache2/php-5.6.25 This is the install path of php.
During the installation php will modify your apache configuration to load php module:
LoadModule php5_module modules/libphp5.so
And you can find the php module in apache modules directory:
Before you restart your apache2 instance place your php.ini to the appropriate place:
apache2@vps10:/opt/apache2/php-5.6.25/lib$ cp /opt/apache2/sources/php-5.6.25/php.ini-production php.ini
To check if php is working place
info.php file to your htdocs directory with this content:
You can call this file using lynx:
As you can see "compiling apache from source" consist of a few steps, but after that if you need any additional php module you will have to install them manually by:
- Using /opt/apache2/php-5.6.25/bin/pear
- Using /opt/apache2/php-5.6.25/bin/pecl
- Compile from source (phpize, configure, make, make install)
If you can afford, consider using your package manager to install apache & php, because it is much simpler and in most cases you won't need to compile from source.