Saturday, April 24, 2010

Initial installations before developing php extensions.

To develop php extensions we have to be installed php in our system. Since it takes time and involve lot of works we can easily forget the steps we have to follow. Therefore I decided to document the steps I followed when setting up my development environment. I use UBUNTU 9.04 as my platform for php-tsql research works. Before we do anything it's necessary to install some development tools which require in extension development life cycle. Therefore you first install the latest versions of following packages in to you system.

1. libxml2 (which is required to compile php source code)
2. libtool
3 make
4. automake
5. autoconf
6. m4
7. bison

But remember that some of the packages may require some other once to be installed previously. If the installation stop somewhere, look at the error and install the requesting package first. Then you can install the interrupted package again. These kind of installations require a huge patience because it may take lot of time in progress printing different things and finally give you an error saying, without a particular package it cannot continue. Then you have to install that package patiently. All you have to do to install each package is,

step 1: Decompress the the package file.
step 2: Go into the package directory.
step 4: Give the commands,

sudo make install

Now I assume you have installed those packages. Now It's time to install apache server and php. download the sources of apache2 and php. Decompress the package files and spend some time reading readme files in those. I think most important one is INSTALL file in php. Now we're installing apache2.

step 1: Decompress the the apache2 package file.
step 2: Go into the package directory.
step 3: To configure and install apache2 give the command,

./configure --enable-so
sudo make install

To check whether apache2 installed correctly start the apache2 server normally. eg:

sudo /usr/local/apache2/bin/apachectl start

Open your wed browser and go to localhost, it should show the message "It Works"
To stop the server,

sudo /usr/local/apache2/bin/apachectl stop

Now apache2 is ok. Its time for php installation.

step 1: Decompress the php package file.
step 2: Go into the package directory.
step 3: To configure and install php give the command,

./configure --with-apxs2=/usr/local/apache2/bin/apxs
sudo make install

If these steps completed without any error, php is installed. But you have to do some more before you start using php.

step 4: To setup your php.ini file, give the command

cp php.ini-development /usr/local/lib/php.ini

step 5: You have to make sure whether apache2 is aware of the installed php. Open the file httpd.conf (it should be in /usr/local/apache2/conf directory) and check whether this kind of an entry is there in the file,

LoadModule php5_module modules/

If not, put that line in the file.

step 5: In that httpd.conf file put this line also in the correct position,

AddType application/x-httpd-php .php .phtml

Now php also installed correctly. To check whether php is working, copy following code to a php files body named testinfo.php and put it in the htdocs directory of apache2.


Now start apache2 server and go to the URL http://localhost/testinfo.php. It should give you the phpinfo page. If so, it confirms that php also working.
Here's a good reference with more detailed description about compiling from the source,

All the best & Enjoy your extensions developing works with this new platform. There's an article on extension writing in this blog. Better to read it.

No comments:

Post a Comment