Friday, 20 January 2012

How to Recompile Apache

We can add a new apache module by either recompiling apache or use apxs tool

Check which all options are available under configure that you need to compile
./configure --help

apache to a particular location using "--prefix"
# ./configure --prefix=/home/apache/ 
# make
# make install

If you need only apache html page just start the service
# /home/apache/bin/apachectl start

make needed changes in apache configuration file 
Listen 80/8080  change this if you need to listen to any other port
Listen 192.168.1.197:8080 http://192.168.1.197:8080

Then if you want to add/Compile PHP with Apache download the php source

# Download php-5.3.8.tar.gz
# /home/apache/bin/apachectl stop
# cd php-5.3.8
# ./configure --prefix=/home/php --with-apxs2=/home/apache/bin/apxs --with-config-file-path=/home/php --prefix=/home/apache/php
# make 
# make test
# make install
# cp /usr/local/src/php-5.3.8/php.ini-development  /home/php/lib/php.ini  

Now Load the PHP module,check the module is there in /home/apache/module/ (libphp5.so) now in httpd.conf add the php module if it is not there
    LoadModule php5_module modules/libphp5.so

 # Tell Apache to parse certain extensions as PHP. In httpd.conf add
    AddType application/x-httpd-php .php
 It tells which all file system you have to handle php,jsp etc.

For new php version add the tag "php" and put the index.html and info.php in /home/apache/htdocs/

<?php
 phpinfo();
 ?>

Adding new module using apache apxs tool

Here we can add a gsoap module to apache
/bin/httpd -l ------ shows the static modules installed while we configure apache.

# cd gsoap-2.8/ -------- Download this package

# cd /usr/local/src/gsoap-2.8/gsoap/mod_gsoap/mod_gsoap- 0.6/apache_20
  going to Add gsop module
Before compiling the module make sure that apache is running.
Then add the module using apxs tool
# /home/apache/bin/apxs -a -i -c mod_gsoap.c

compile the .c file and it create a .o file (mod_gsoap.o) / if apache is running it will create/copy a .so file in apache/module folder. This adding modules are called dynamic moduls.

Check module is reached in apache module folder

# ls /home/apache/modules/ (mod_gsoap.so)

and add the LoadModule option in httpd.conf file ( check below line is there or not. In apache 2.X it may come automatically )

LoadModule gsoap_module modules/mod_gsoap.so 

# Restart Apache

Enable another module by re-compiling apache

If we want to enable another option/module in apache either recompile apache or add its module. To recompile apache Go to its source.( In Production servers no recompiling bcz errors may occure only adding module using apxs # Here going to install ldap module.

Take the apaceh source package that you already installed, same version
# cd /usr/local/src/httpd-2.2.21
# make clean
# make distclean
# ./configure --prefix=/home/apache/ --enable-ldap
# make
# make install
# /home/apache/bin/httpd -l
     util_ldap.c

always better to use apxs tool other than re-compling apach



No comments:

Post a Comment