Skip to content

Installing PHP

June 11, 2012

Right to round off my knowledge of LAMP, i will now install PHP from source on to the Centos Webserver.

So first things first, lets install the latest PHP from the main website which is PHP 5.4.3: –

www.php.net

Installation of PHP on Centos Server

prompt> wget -v http://uk3.php.net/distributions/php-5.4.3.tar.gz

Unzip the compressed file and the archive: –

prompt> tar -zxvf php-5.4.3.tar

Now we need to make sure that the Apache Extension Tool is installed. For more information regarding the Apache Extension Tool please visit: –

http://httpd.apache.org/docs/2.2/programs/apxs.html

We can check that it is properly installed by: –

prompt> /usr/local/apache2/bin/apachectl -l | grep mod_so

As long as you get a result listing mod_so then you are okay, if you do not get anything feedback from the prompt then this could be a sign that the Apache Extension Tool has not been installed properly.

We need to make sure we have the libraries to install xml and html applications that is a dependency for php, install it by typing: –

prompt> yum install libxml2-devel

Okay now we can start to install PHP, make sure you are in the folder and then type the following: –

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

prompt> make

prompt> make install

Now that PHP has been installed, we need to setup out php.ini file as specified in; –

http://www.php.net/manual/en/install.unix.apache2.php

To setup the php.ini file to be used we do the following; –

prompt> cp -v php.ini-development /usr/local/lib/php.ini

During the make install in the previous step it actually edited the httpd.conf file to load the module which is php5. Now we need to configure the Apache Directives to make sure that PHP files are parsed by the Apache Webserver and only specific files are parsed by the Apache Webserver for security reasons. So let’s put the following into the httpd.conf file which is located at /usr/local/apache2/conf/httpd.conf and make sure to add a tab to the second line before starting to type: –

<FilesMatch \.php$>

SetHandler application/x-httpd-php

</FilesMatch>

Okay, now that Apache Webserver has support for PHP. We can now test that Apache Webserver does support PHP files. Lets use the simple tutorial from PHP’s main website ( http://www.php.net/manual/en/tutorial.firstpage.php ), so make sure to create a file with a .php extension, e.g. test.php and put the following source code in it and save it:-

<?php echo ‘

This serves as confirmation that this webserver supports PHP

‘; ?>

Navigate to the above file using your Internet browser (e.g. http://localhost/test.php) and hit return. This should show a webpage that echo’s the above message which means that PHP works 🙂

Advertisements

From → Linux

One Comment
  1. Simply want to say your article is as astounding. The clarity in your post is just excellent and i can assume you’re an expert on this subject. Fine with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the rewarding work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: