How to install php on linux server

How/Steps to install PHP on Linux/CentOS server.

To install the latest version of PHP you can use the below commands.

yum list php*

It will show the available PHP packages.

yum install php*

It will install that latest php.

If you are getting --skip broken then follow the below command.

yum install php* --skip-broken

It will skip the broken dependencies and install the latest php.


How to install Stable PHP 5.2 on Linux/CentOS server.

First check which php packages are available.

yum list php*

It will show php5.1 and 5.3. To install 5.2 PHP you have to install php5.1 and then upgrade it. To install php5.1.x you have to select the package name and follow the below command.

yum install php-*

It will install php 5.1.x on the server.

Now upgrade php5.1.x to 5.2x

rpm --import

Go to the yum repo directory

cd /etc/yum.repos.d

Download the  CentOS-Testing repo


Update to PHP5.2.x

yum --disablerepo=* --enablerepo=c5-testing update php

Install extra package

yum --disablerepo=* --enablerepo=c5-testing install php-xml

Restart Apache and make the Apache start on boot.

service httpd restart
chkconfig httpd on

Now check the PHP version:

php -v

It will show the below output

PHP 5.2.17 (cli) (built: Feb 21 2011 04:28:54)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies