Installing PHP from source is much easier than most people think. In this tutorial I will describe how to install a bare PHP build with mysql/mysqli support in addition to configuring apache to interpret PHP scripts.

Compiling PHP Source

Alright, well in order to compile the PHP source code you must first have gcc install (# yum install gcc). Also if you want to be able to use PHP in apache then you need to have httpd and httpd-devel packages installed. Here is how I did my install. (Please note that I used PHP 5.2.6 for my install, but this will work with just about any php version, just be sure to untar and cd into the proper directory for your version of php.)

[root@nitrogen ~]# yum install gcc-c++ httpd httpd-devel apr-devel libxml2-devel zlib zlib-devel mysql-devel openssl-devel
[root@nitrogen ~]# wget http://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror
[root@nitrogen ~]# tar -zxvf php-5.2.6.tar.gz
[root@nitrogen ~]# cd php-5.2.6
[root@nitrogen cd php-5.2.6]# ./configure --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2 --with-libdir=lib64  --with-mysql --with-mysqli --with-zlib
[root@nitrogen cd php-5.2.6]# make clean
[root@nitrogen cd php-5.2.6]# make
[root@nitrogen cd php-5.2.6]# make install

You’re also going to want to place a php.ini into /etc/php.ini and make the /etc/php.d directory if you have not done so already.

[root@nitrogen cd php-5.2.6]# cp php.ini-recommended /etc/php.ini
[root@nitrogen cd php-5.2.6]# mkdir /etc/php.d

Installing PHP into apache

To install PHP into apache all you need to do is place the following configuration file in /etc/httpd/conf.d/php.conf.

# /etc/httpd/conf.d/php.conf
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages
#

LoadModule php5_module modules/libphp5.so

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncommenting the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

Finalizing our install is fairly simple, just restart apache by typing the following command and you should be good to run PHP applications for the web.

[root@nitrogen ~]# /sbin/service httpd restart

8 Comments

  1. Hi,

    I had done your step, my PHP is run smoothly with your code.
    However, I would like to add more PHP extension. What step should I do?

    I tried, and my step as follow
    $ /etc/init.d/httpd stop
    $ yum install freetype-devel.x86_64
    $ ./configuration –with-freetype-dir=/usr
    $ make clean
    $ make
    $ make install
    $ /etc/init.d/httpd start

    I also remove the semicolon in php.ini

    However, I went to phpinfo(). It still did not included the extension. Anything I miss?

    Like

  2. While configuring on Fedora 17 I got an error “mysql client is not bundled anymore” preventing me from using ‘make clean’. The solution was to : yum install mysql-devel. Then go back and re-configure.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.