PHP Linux installation or php upgrade howto

Q. How do I install PHP under Red Hat enterprise Linux?

A. PHP (Hypertext Preprocesso) is a server-side web programming language that you can embed into HTML pages. When a user accesses a PHP-based page, PHP dynamically creates a web page that is then passed to the browser.

PHP works with Apache, Lighttpd and other webservers. PHP offers built-in database integration for several commercial and non-commercial database management systems. It also has the ability to perform many useful Web-related tasks using a large set of built-in functions.

PHP generally runs on a web server, taking PHP code as its input and creating Web pages as output, but command-line scripting and client-side GUI applications are part of the three primary uses of PHP as well. PHP can be deployed on any web server and on almost every OS platform free of charge.

Installing PHP is easy these days.

Red Hat enterprise Linux PHP installation

If you would like to install or upgrade PHP use up2date command:
# up2date php

CentOS/Fedora core Linux PHP installation

If you would like to install PHP use yum command
# yum install php

If you would like to upgrade PHP use yum command
# yum update php

Debian / Ubentu Linux PHP installation

If you would like to install or upgrade PHP use atp-get command
# apt-get install php4-cgi php4-cli
# sudo apt-get install php4-cgi php4-cli

To install PHP 5
# apt-get install php5-cgi php5-cli
# sudo apt-get install php5-cgi php5-cli

FreeBSD PHP installation

Use pkg_add command as follows:
# pkg_add -v -r php

Use above command to install Apache or Lighttpd web server.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 33 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
33 comments… add one
  • Mohan Jun 1, 2007 @ 6:43

    Can you please provide the detailed step by step process for Upgrading the PHP4 to PHP 5.?

    Also the system requirements for this like Zend Engine, Apache server version required or MySQL version required ?

  • 🐧 nixCraft Jun 1, 2007 @ 21:28

    Just run up2dat/yum or apt-get command to update version. If you need more help join our forum

  • Naresh Khokhaneshiya Oct 15, 2007 @ 13:54

    Hello there,
    Actually when I run ‘yum update php’ on CentOS 5, it does not update the php to the latest version of 5.2.3 and remains to version 5.1.6 only and says that it can not find any updates.
    Anything am I missing?
    Naresh Khokhaneshiya

  • 🐧 nixCraft Oct 15, 2007 @ 18:08


    5.1.6 is latest and stable for RHEL / CentOS. PHP 5.2.3 won’t be available for CentOS 5.0. You have to wait or compile from source code.

  • Mars Oct 24, 2007 @ 22:59

    I to in a way have the same problem as Naresh
    however a little defferant. I have version 5.1.6
    and am trying to install ffmpeg.php it needs the comand phpize to be ran and there is no sush program on my server !
    which phpize / it says none
    Why would this not get installed with my version of php (any ideas ?) Also if you have any thoughts as to how I can install this please let me no. I realy do not want to have to reinstall php or upgrade.
    have you hurd of a patch for this or something?

    Thanks Mars

  • 🐧 nixCraft Oct 25, 2007 @ 14:20


    Install php-devel package to get phpize binary:
    yum install php-devel

  • John Dec 29, 2007 @ 20:11


    Thanks for your guide. I ran the update command using yum and my PHP was updating to a version of Nov 2005. My system is Redhat. Can you tell me how to upgrade to the latest PHP version? Do I have to first uninstall the old version or something?


  • 🐧 nixCraft Dec 30, 2007 @ 11:43


    If you are using RHEL 4, there is no offical PHP 5 exists. Redhat only provides updates for RHEL 4. I strongly recommend to update your box to RHEL 5.x

  • Marlin Apr 5, 2008 @ 15:52

    HEllo all
    I ran this and it installed the phpize
    Install php-devel package to get phpize binary:
    yum install php-devel

    However now when i try to use phpize it says?
    make sure you run ‘usr/bin/phpize’ in the top level source directory of the module

    I have looked everywhere on the net and there is no help on this that i could find. Do you have any thoughts on what this means?

    Thank You

  • Photos China May 22, 2008 @ 7:37

    I tryed the command on Ubuntu:
    sudo apt-get install php5-cgi php5-cli

    Ant it installed the version 5.2.3 of php but the last version is 5.2.6.

    It’s not so important, but how upgrade to the last version using apt-get ?

    Thanks for this post

  • Danno Oct 27, 2008 @ 1:50

    Hey, I have the same questions. How is it easier to get the latest version installed, and not the patches. I ran configure make and make install, and I still get the previous version.

    It would be great if apt-get would install php 5.2.6

  • Bob Nov 20, 2008 @ 0:14

    I am on Fedora Core 6 and currently on PHP 5.1.6. When I ran “yum update php” it didn’t pick up the new 5.2 version, any ideas?

  • Jeff Dec 15, 2008 @ 12:29

    #yum update php
    Setting up Update Process
    Setting up repositories
    update 100% |=========================| 951 B 00:00
    base 100% |=========================| 1.1 kB 00:00
    centosplus 100% |=========================| 951 B 00:00
    addons 100% |=========================| 951 B 00:00
    extras 100% |=========================| 1.1 kB 00:00
    Reading repository metadata in from local files
    Excluding Packages in global exclude list
    Could not find update match for php
    No Packages marked for Update/Obsoletion

    fail to update..anyone can help?

  • joe blow Apr 15, 2009 @ 1:10

    What if you want to update PHP that isn’t supported by the vendor? You would need to either build yourself from source or find a pre-packaged PHP. I’ve encountered this with new bleeding edge applications that want the newest PHP 5.2 or 5.3. How do you integrate those versions of PHP with a currently existing Apache?

  • Ashwin Jun 30, 2009 @ 11:30

    To update php-4 to php-5 edit your repositories located in (/etc/yum.repos.d), then open CentOS-Base.repo using your favourite editor find [centosplus] below it you will find enable=0 change it to enable=1 an then run yum update php if have any issue do let me know.

    Ashwin Wadhwa

  • Aaron Nov 4, 2009 @ 15:27

    I love how everyone assumes I have yum, or apt-get, or up2date.

    I’m trying to upgrade php from bash command line and downloaded .gz packages.

    Working on a DoD SECRET network, I will never have cloud connectivity to use these nifty updaters.

    /google on

  • Jerry Ballmer Nov 16, 2009 @ 23:27

    “I love how everyone assumes I have yum, or apt-get, or up2date.”

    why wouldn’t they? that is the standard setup for most users.

    “Working on a DoD SECRET network”

    good thing you mentioned this, now we can all think of you in awe and realize how great you must be.

    “I’m trying to upgrade php from bash command line and downloaded .gz packages.”

    this is really all we needed in addition to letting us know you don’t have net access from your server in question.


  • Cripto Mar 16, 2010 @ 23:01

    Aaron, glad to know that…
    if it was secret, now it isnt anymore.
    Congrats for showing the world what you do / dont do.

    if you were more attentive, you would see the answer is up.
    You can compile from source, or downloadpre-packaged.

    Like Jerry said, it is quite common to use apt-get or yum.
    yum is Fedora and RH based.
    apt-get from Ubuntu and Debian.
    Both are standard and well accepted / respected.

    but of course,.. if you use a secret operating system and secret software in bash,
    you dont need the super common “nifty updaters”. ROTFL

  • farhad Mar 29, 2010 @ 12:42

    I have installed php 5.1.6 manually by rpm .
    I am try to upgrade from php-5.1.6 to php 5.2 in redhat 4 (Nahant Update 2)

    How can i do it ?

    • slacker Apr 27, 2010 @ 17:52

      This can be done in one of two ways.
      1. use yum as this post suggests:
      [root@box ~]# yum update php

      2 download the rpm (find the uri for the package from and do
      [root@box ~]# wget .rpm
      [root@box ~]# rpm -Uvh .rpm

  • slacker Apr 27, 2010 @ 17:48

    lame. apt-get, yum, up2date, etc are only wrappers for ‘s package manager. Assuming that ppl can install a distro, setup a repository, only to depend on that distro’s intrinsic utils is, as Aaron pointed out, lame. if nixcraft really wanted to be helpful, a brief reminder on ‘tar -zxvf .tar.gz && cd `ls | grep ` && ./configure && make && make install’ would have been far more beneficial. Don’t think that attitude of “apt-get and yum cover most everyone, so if you don’t have it, get” is going to earn you any cred.

    Use the source, Luke

  • everydaypanos Jun 24, 2010 @ 19:13

    Is it me or everyone is kind of trying NOT to answer the question? It’s like: I know how to update PHP but I don’t really care to help anyone else because I spent hours googling and some noob wants it on a plate.

    Don’t you just love the Open Source community spirit?

    At the end of the day, yum update php is NOT the solution. Because the problem is upgrading to a version of PHP that you actually want…

  • Andi Herdiana Jul 5, 2010 @ 3:53

    Please help me!
    How to upgrade php and MySQL on FEDORA CORE 4 with detail description!

    Thank you before!

  • Aaron Sep 15, 2010 @ 15:19

    Goodness, I wasn’t trying to garner any awe. I was venting because developing on a closed network RHEL server is a major pain in the ass! No repo’s make me cry hard.

    I forgot I even made this post haha. I’m faced with more of the same and started looking for a PHP upgrade procedure via BASH landed me back here…

    PHP 5.0 on the production server but my dev server is using 5.2 so when I went to stand up a Flex application today the DateTime function bit me.

    By the way, the network is still SECRET and will always be regardless if I speak of it or not.

    /google on MOAR!

  • Terry Sep 28, 2010 @ 15:15

    You must have a way to download files, if you can get a .gz source file.

    For example: at home, find the RPM for the package you want to use, burn it to a CD, take it to work, mount the CD, then use the rpm command to install the package.

    If bringing a file from home isn’t permitted, then ask your network admins to get the rpm file for you from the ‘net and copy it to your secret network. Then use rpm to install it.

  • Dayawansa Oct 18, 2010 @ 9:52

    I have PHP 5.1 and MYsql 5.0.22. My system is Redhat enterprse server 5. But I am unable to connect the mysql database through PHP.Can you tell me how to upgrade to the latest PHP version from internet at my unix box? Do I have to first uninstall the old version or something

  • Sanford Dickert Nov 23, 2010 @ 2:42

    Check the following site for an upgrade path on CentOS 5 at godaddy.

    • danoprey Jun 29, 2011 @ 9:28

      Perfect, thank you so much for the guide.

    • Ganga Sep 29, 2011 @ 11:26

      Yes. It works perfectly for me..
      I am using Centos5.5….

      Thanks Sanford….

  • sapy Feb 25, 2011 @ 11:16

    Pls run the following command :whereis php
    now depending on the mode of installation may be u can try setting the home path of php for updated version.

  • harfano Dec 5, 2012 @ 3:21

    i’ve trying Sandford suggestion but it’s not working.i’m using CentOS 5.8 (final) on i386.
    is there any other way? please…

  • prathap Feb 24, 2014 @ 9:27

    Hi All,

    I try to update php 5.1.6 to latest but not able to update. i’m using CentOS-5.10.

    [root@srv01 ~]# lsb_release -a
    LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
    Distributor ID: CentOS
    Description: CentOS release 5.10 (Final)
    Release: 5.10
    Codename: Final
    [root@srv01 ~]# php –version
    PHP 5.1.6 (cli) (built: Dec 10 2013 22:14:51)
    Copyright (c) 1997-2006 The PHP Group
    Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    [root@srv01 ~]# yum update php
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * addons:
    * base:
    * epel:
    * extras:
    * rpmforge:
    * updates:
    Setting up Update Process
    No Packages marked for Update
    [root@srv01 ~]#

  • Karthik Jul 9, 2016 @ 11:15

    I have difficulty to upgrade my Red hat 5.6 Server’s Php version 5.1.6 to 5.5. Can anyone guide me the steps which I should follow.
    I have downloaded .tar file, unzipped then ran the configure and make install commands. Then it shows php 5.5 when I’m running php -v command. But running the script for finding php details in browser its still showing 5.1.6 .

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum