PHP Linux installation or php upgrade howto

Posted on in Categories , , , last updated December 12, 2006

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

33 comment

  1. 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 ?

  2. 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?
    Regards,
    Naresh Khokhaneshiya

  3. 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

  4. Hi,

    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?

    Thanks

  5. 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

  6. 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

  7. 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

  8. #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
    Finished
    Could not find update match for php
    No Packages marked for Update/Obsoletion

    fail to update..anyone can help?

  9. 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?

  10. 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

  11. 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

  12. “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.

    HTH

  13. 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

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

      2 download the rpm (find the uri for the package from php.net and do
      [[email protected] ~]# wget .rpm
      [[email protected] ~]# rpm -Uvh .rpm

  14. 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

  15. 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…

  16. 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!

  17. 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.

  18. 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

  19. Hi All,

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

    [[email protected] ~]# 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
    [[email protected] ~]# 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
    [[email protected] ~]# yum update php
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * addons: mirror.dhakacom.com
    * base: mirror.dhakacom.com
    * epel: buaya.klas.or.id
    * extras: mirror.dhakacom.com
    * rpmforge: mirror.oscc.org.my
    * updates: mirror.dhakacom.com
    Setting up Update Process
    No Packages marked for Update
    [[email protected] ~]#

  20. Hi,
    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 Comment