For many reasons many people want to compile their own source code to build apache and php / mod_perl these days. We will discuss the steps required in doing just that. But unlike most others we will throw in some bonuses, like installed mod_perl and the hardened php project’s suhosin patch to php, to help make the internet a more secure place to live.
Lets get to business: We will start with Apache. If you do not know what apache is well, the Apache HTTP Server; to put it simply Apache is the most popular web server on the internet and it has helped make the growth of the internet what it is today. Stating that we will be using Apache 1.3.x at the time of writing this article the current apache version is 1.3.3.7. You can download the source code at
http://httpd.apache.org/
Copy and paste code!
cd /usr/local/src
wget http://www.ibiblio.org/pub/mirrors/apache/httpd/apache_1.3.37.tar.gz
tar xzvf apache_1.3.37.tar.gz
cd apache_1.3.37
./configure –prefix=/usr/local/apache
–enable-module=most –enable-shared=max
make && make install
That should have Apache built from source, compiled and installed in /usr/local/apache
and the configuration is in /usr/local/apache/conf the default document root is in /usr/local/apache/htdocs. To start and stop apache issue
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl start
Try it by going to http://www.yoursite.com or http://1.2.3.4
Mod_perl: Mod perl is optional but if you wanted to use it, it requires just a few lines to install and modify. At the time of writing this article mod perl is at version 1.30. You can obtain the latest source at
http://perl.apache.org/
wget http://perl.apache.org/dist/mod_perl-1.0-current.tar.gz
perl Makefile.PL USE_APXS=1 WITH_APXS=/usr/local/apache/bin/apxs EVERYTHING=1
make && make install
Thanks to USE_APXS=1 and WITH_APXS=/usr/local/apache/bin/apxs, mod_perl compilation is done correctly, and will be compiled as a DSO (Dynamic Shared Object).
To make your perl files script.pl work in apache you need to modify /usr/local/apache/conf/httpd.conf to include:
AddHandler cgi-script .pl
After this mod_perl will be ready to use.
PHP: PHP’s growth alone is because of it’s ease of use and ability to let beginner programmers create dynamic scripts and websites. However PHP has many security concerns and because of that in this guide we will be compiling php with the hardenred php project’s Suhosin security patch.
Suhosin available at:
http://www.hardened-php.net/suhosin/index.html
PHP source available at:
http://www.php.net/
At the time of writing this article PHP version is 4.4.6 and 5.2.1. We will be using PHP 5 for our example. We will be using the suhosin patch that goes with the version of PHP 5.2.1 available at http://www.hardened-php.net/suhosin/download.html
You must get the patch directly from the hardened-php project download page listed above. Afterwards place the extracted file in /usr/local/src/ for it is the directory all our examples are using to compile from.
Use the commands below to extract the suhosin patch as well for it is in a bz2 format.
Copy and paste:
tar -xfj php-5.1.4.tar.bz2
wget http://us2.php.net/get/php-5.2.1.tar.gz/from/this/mirror
tar xzvf php-5.2.1.tar.gz
cd php-5.2.1
patch -p 1 -i ../suhosin-patch-5.2.1-0.9.6.2
./configure –with-mysql –with-gd –enable-suhosin –with-xml –with-gettext –enable-mbstring –with-curl –with-xmlrpc –with-zlib –enable-mbregex –enable-sockets –with-iconv –enable-bcmath –with-apxs=/usr/local/apache/bin/apxs
make && make install
In the configure line you can remove or add more modules as you wish, this is just a sample of what we would normally use on a production type system for certain tasks.
You will need to tell apache that you want php files to be read as php and not text! This is very important! Because if you do not, you may expose your PHP code and sensitive code as clear text, you do not want this.
Open /usr/local/apache/conf/httpd.conf
Copy and paste:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Search for DirectoryIndex and make the line as below
index.html index.htm index.php index.pl
You can specify the order in which you want documents to display as default by arranging the index.html index.php fields from left to right.
Restart Apache
/usr/local/apache/bin/apachectl restart
You should be set now!
You can test that everything is working in php by making a file called test.php in /usr/local/apache/htdocs insert the following:
<?php phpinfo(); ?>
Thats it! Try it out, let me know what you think!
Good luck and happy serving 
Powered by Gregarious (42)
Share This now!