Delicious Bookmark this on Delicious

Computer Forums

Installing PHP on an Apache server - Compiling PHP



Place yourself in the the php-5.3.7 folder:

cd /home/Username/Desktop/php-5.3.7

Now, very much like when compiling an Apache server, you need to use the configure command in order to prepare the makefile for PHP:

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql

Make sure the path to the apxs environment is adapted to your own system configuration, and don't forget the --with-mysql option in case you plan to use mysql databases. When the configuration is done, run the making process:

sudo make
sudo make install

You can now look for the file libphp5.so which is the shared library for php 5. If you can't find it easily, run:

sudo update db
locate libphp5.so

Did you find it ? You can then place it in the folder of your choice: normally, upon compilation and installation, a copy of libphp5.so was already installed in the following locations and there should be no reason why you would like it to be somewhere else:
  • In the modules folder of your Apache installation (as specified by the configuration above)
  • in the libs folder of your php-5.3.7 folder
Once you have verified that the shared library libphp5.so is where it is supposed to be, it's time to edit the Apache configuration so that your Apache server loads the shared library and can make use of it.

Computer Forums

Installing PHP on an Apache server - Editing httpd.conf so that it loads libphp5.so



Open the Apache configuration file httpd.conf in your favorite text editor (mine's Bluefish ...). You will find http.conf in the conf/ folder of your Apache directory. If you can't find it, try to use the locate Linux command (after running sudo updatedb). If you still can't find it, then maybe it is named differently (depending on your Linux distribution or whatever bundle you are using)
Add the following line to the dynamic shared objects section of the httpd.conf file (note that it might have been added automatically during the make install step above, in which case you don't need to do anything, of course):

LoadModule php5_module modules/libphp5.so

Load PHP dynamic shared object

Installing PHP on an Apache server - Editing httpd.conf so that it can process PHP extensions



You can now edit httpd.conf so that it can tell which file extensions will be processed as PHP files. In order to do this, add the following lines to httpd.conf:

< FilesMatch \.php$ >
SetHandler application/x-httpd-php
< /FilesMatch >


Installing PHP on an Apache server - Restarting Apache and testing PHP support



In order to test your PHP, just add a file index.php to your htdocs/ directory (or www/ directory, or whatever that folder containing your website documents is named). You can also add the following script to index.php: < ?php phpinfo(); ? >

Now make sure your Apache server is started, and point your web browser to http://localhost/. If your PHP installation was successful, a page containing the PHP information of your installation will be displayed (example below):

PHP info after installation

In this Linux tutorial we saw how to download, compile and install PHP on your Apache server running on Linux. The next step will be to learn how to properly configure PHP (by editing the php.ini file). Unless you prefer to learn first how to install a mysql server and link it to Apache.

Computer Forums

Next tutorial: PHP configuration


Back to computer forums