1. Prerequisites
Apache web server should already be installed. Refer to my previous post on How to install Apache 2 on Linux. If you are planning to use PHP with MySQL, you should have My SQL already installed. I wrote about How to install MySQL on Linux.
2. Download PHP
Download the latest source code from PHP Download page. Current stable release is 5.2.6. Move the source to /usr/local/src and extract is as shown below.
# bzip2 -d php-5.2.6.tar.bz2
# tar xvf php-5.2.6.tar
3. Install PHP
View all configuration options available for PHP using ./configure –-help (two hyphen in front of help). The most commonly used option is –-prefix={install-dir-name} to install PHP on a user defined directory.
# cd php-5.2.6
# ./configure --help
In the following example, PHP will be compiled and installed under the default location /usr/local/lib with Apache configuration and MySQL support.
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
# make
# make install
# cp php.ini-dist /usr/local/lib/php.ini
4. Configure httpd.conf for PHP
Modify the /usr/local/apache2/conf/httpd.conf to add the following:
Make sure the httpd.conf has the following line that will get automatically inserted during the PHP installation process.
LoadModule php5_module modules/libphp5.so
Restart the apache as shown below:
# /usr/local/apache2/bin/apachectl restart
5. Verify PHP Installation
Create a test.php under /usr/local/apache2/htdocs with the following content
# vi test.php
Go to http://local-host/test.php , which will show a detailed information about all the PHP configuration options and PHP modules installed on the system.
6. Trouble shooting during installation
Error 1: configure: error: xml2-config not found:
While performing the ./configure during PHP installation, you may get the following error:
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
Configuring extensions
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
Install thelibxml2-devel and zlib-devel as shown below to the fix this issue.
# rpm -ivh /home/downloads/linux-iso/libxml2-devel-2.6.26-2.1.2.0.1.i386.rpm /home/downloads/linux-iso/zlib-devel-1.2.3-3.i386.rpm
Preparing... ########################################### [100%]
1:zlib-devel ########################################### [ 50%]
2:libxml2-devel ########################################### [100%]
Error 2: configure: error: Cannot find MySQL header files.
While performing the ./configure during PHP installation, you may get the following error:
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
checking for MySQL UNIX socket location... /var/lib/mysql/mysql.sock
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
Install the MySQL-devel-community package as shown below to fix this issue.
# rpm -ivh /home/downloads/MySQL-devel-community-5.1.25-0.rhel5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-devel-community ########################################### [100%]
No comments:
Post a Comment