Friday 20 January 2012

How to Compile Apache & Php in linux

  Compiling PHP and Apache from source

Assuming Apache source and Php source are in /usr/src directory.

To compile Apache
$ cd /usr/src 
$ tar -zxvf httpd-2.0.44.tar.gz
$ cd /usr/src/httpd-2.0.44 
$ ./configure --prefix=/wwwroot --enable-so ( Dynamic Shared Object (DSO) Support ) this module is used to enable dso.
$ make 
$ make install
$ /wwwroot/bin/apachectl start 

Now test apache installation by going to http://localhost.
Stop apache for php installation.

$ /wwwroot/bin/apachectl stop

To compile PHP
$ cd /usr/src $ tar -zxvf php-4.3.0.tar.gz 
$ cd /usr/src/php-4.3.0
$ ./configure --prefix=/wwwroot/php --with-apxs2=/wwwroot/bin/apxs --with-config-file-path=/wwwroot/php --with-mysql
$ make 
$ make install

Now you have to edit Apache configuration file /wwwroot/conf/httpd.conf.

If LoadModule php4_module modules/libphp4.so line hasn't been added by php install to /wwwroot/conf/httpd.conf, then you have to add it yourself. Add it somewhere below section named "Dynamic Shared Object (DSO) Support" 

LoadModule php4_module modules/libphp4.so 

Now add this line to /wwwroot/conf/httpd.conf file: 

AddType application/x-httpd-php .php

Start Apache now:  $/wwwroot/bin/apachectl start
Now create a test PHP file using any text editor and add these lines to it:
<?php
phpinfo();
?>

Save it under /wwwroot/htdocs as info.php
Now test your PHP installation by accessing file info.php:

http://localhost/info.php

DSO
The modules can be statically compiled into the httpd binary when the server is built. Alternatively, modules can be compiled as Dynamic Shared Objects (DSOs) that exist separately from the main httpd binary file. DSO modules may be compiled at the time the server is built, or they may be compiled and added at a later time using the Apache Extension Tool (apxs). 

apxs is a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server. This is achieved by building a dynamic shared object (DSO) from one or more source or object files which then can be loaded into the Apache server under runtime via the LoadModule directive from mod_so.

So to use this extension mechanism your platform has to support the DSO feature and your Apache httpd binary has to be built with the mod_so module. The apxs tool automatically complains if this is not the case. You can check this yourself by manually running the command.

$ httpd -l

The module mod_so should be part of the displayed list. If these requirements are fulfilled you can easily extend your Apache server's functionality by installing your own modules with the DSO mechanism by the help of this apxs tool:

$ apxs -i -a -c mod_foo.c

The arguments files can be any C source file (.c), a object file (.o) or even a library archive (.a). The apxs tool automatically recognizes these extensions and automatically used the C source files for compilation while just using the object and archive files for the linking phase.

DSO helps to add dynamic modules after we install apache. 

No comments:

Post a Comment