Published August 30th, 2005 by Jim O'Halloran

PHP 5 for CentOS 4.1

One nice thing about CentOS is the long support life and stability of the system. One not so nice thing is that because it is based on Red Hat Enterprise, the package selection is pretty conservative. That’s not too bad though, Apache is 2.0.52, MySQL is a 4.0.x version, so things are reasonably current. One thing that’s really dated though is PHP (4.3.x)… I’ve been using PHP 5 for a while and quite like it, so a PHP 5 package for CentOS would be nice. Good news though is that one already exists, its in the CentOSPlus repository. This post to the CentOS Mailing List explains what the CentOSPlus repo is for.

To enable CentOSPlus edit /etc/yum.repos.d/CentOS-Base.repo. After [centosplus] heading, you’ll see a line that currently says “enabled=0″. Change that to “enabled=1″ to enable CentOSPlus. Once the CentOSPlus repo is enabled, “yum update” will search the repository and offer to upgrade any packages to newer versions from CentOSPlus. If you had PHP installed previously, this will upgrade you to PHP 5.0.x.


38 Responses to “PHP 5 for CentOS 4.1”

Feed for this Entry Trackback Address
  1. 1

    Dominic Says

    Hello,

    I did this but it updated everything with the exception of PHP which is what I wanted!. Any ideas?

  2. 2

    James Says

    Just what the doctor ordered. Thanks so much, Jim.

    jas

  3. 3

    Doug Says

    Thanks Jim. This post was most helpful.

  4. 4

    Doug Says

  5. 5

    Steven Says

    Perfect simple step - thanks tons!

  6. 6

    Hudson Says

    Thank you very much for your help!

  7. 7

    Phil Says

    Aha! Great. Thanks very much

  8. 8

    Artur Says

    Most excellent :-) will try this in the morning. Trying to find rpms for php5 for centos3 but I guess no such animal exists.

  9. 9

    Tachou Says

    Thanks alot, you save the night !

  10. 10

    Mark Says

    I can’t believe it. I’ve wasted hours trying to get php5 to compile and your little tip fixed it in seconds. Thanks!

  11. 11

    Mark Says

    Oops! Spoke to soon.
    This version lacks some important features which I need, such as pgsql support. Had to uninstall it and re-install the older version. Any ideas?

  12. 12

    jim Says

    pgsql support is usually packaged separately, try a “yum install
    php-pgsql”.

    Jim.

  13. 13

    jim Says

    Got this reply in email from Mark…

    —– Cut Here ——
    Thanks for your reply, Jim

    Tried that, but pgsql still won’t work, and phpinfo() indicates that php was configured without pgsql. Is there a way of retrofitting a confiure options?

    Thanks,
    Mark
    —– Cut Here ——

    Just checked the mirror I used and there’s definately a php-pgsql rpm in the centos plus repository… So a few things you might want to check…

    1) The once you’ve got php 5 and the php-pgsql package installed, check the “extension_dir” setting in php.ini, make sure the directory exists and the pgsql.so file is in that directory. Mine is set to “/usr/lib/php/modules”, so that’s where the .so files will be installed by default. If yours isn’t set to that directory then it might be easier to change the extension_dir rather than move the .so’s.

    2) Make sure the line “extension=pgsql.so” appears somewhere either in php.ini or one of the /etc/php.d/*.ini files. This will force PHP to load the pgsql extension.

    I’m not sure how phpinfo() determines the configure command line, whether the exaual command line is compiled into PHP itself when its built, or whether it’s just reconstructed when the phpinfo() page is generated based on the extensions that are currently loaded. Either way, the presence of a pgsql section in the phpinfo output is probably the most reliable indicator of whether the extension is loaded or not.

    Jim.

  14. 14

    jim Says

    Another worthwhile thing to do would be to check the syslog or /var/log/php.log to see if there’s any error messages indicating problems loading the pgsql extension. They might give you a pointer as to where to look next.

    Jim.

  15. 15

    Raul Says

    I’ve known about the CentOSPlus repository for a while (http://mirror.centos.org/centos/4.3/centosplus/x86_64/RPMS/), but have always downloaded and installed the RPM’s by hand. This is so much more convienient since YUM will usually handles all the dependencies.

    Great stuff.

  16. 16

    Piers Says

    Great posting, very helpful.

  17. 17

    Craig Says

    hell yeah, worked like a charm!

    Thanks!!!

  18. 18

    Jonee Ryan Ty Says

    actually you just have to enable the repo and as root do a

    yum upgrade php

    instead of updating your whole system

  19. 19

    Jason Says

    Great tip! Thanks a bunch…Just saved me all sorts of pain!

  20. 20

    Boyce Says

    This worked for me, but I use the protect and fastest mirror plugins and didn’t want to upgrade packages other than php5 so I made a slight change suggested by the article linked to in Jim’s post. I have the CentOSPlus already enabled already but the Base and Updates repositories protected. I didn’t want to change that so I used the “exclude=php*” directive on each and then did a “yum checkupdate php” and found it available. Its installed now and working like a charm. Thanks!

  21. 21

    Mark Crosby Says

    I just want to say thank you so much for this!!

  22. 22

    AMing Says

    I wait php5 so long. It is helpful for me. Thank you very much

  23. 23

    Pau Says

    Awesome! Thanks!

  24. 24

    Peter Stubbs Says

    If you are using Blue Quartz GUI do not install this as it will break it.

  25. 25

    Nitesh Says

    Awesome! Thanks man! It worked like a blink of an eye…

  26. 26

    mike Says

    Whoa you saved me at least an hour! Hooray for google :)

  27. 27

    Johnson Chen Says

    This is very neat! Save me a bundle of headache. Thank you!

  28. 28

    acito Says

    I faced some problem when i update to php 5..

    look into phpinfo()

    Configure Command
    ‘./configure’ ‘–without-pear’ ‘–without-mysql’ ‘–without-gd’ ‘–without-odbc’ ‘–disable-dom’ ‘–disable-dba’ ‘–without-unixODBC’ ‘–disable-pdo’ ‘–disable-xmlreader’ ‘–disable-xmlwriter’

    which PEAR and MySql is needed..

    after update.. my application indicate this error:
    PHP PEAR must be installed. Visit http://pear.php.net for help with installation.

    i have install Pear and located under /usr/share/pear

    any help might be useful

    thanks in advance.

  29. 29

    www.gamebeat.net Says

    Thanks a bunch, just what I needed!

  30. 30

    Wil Says

    Hey there… I did this and it went off just fine thanks. php-xml was not installed so first I had to do a yum install php-xml but after that it was all gravy.

    When I look at phpinfo()’s results however it still says PHP Version 4.3.9
    When I run php –version from the shell I see PHP 5.1.6

    WTF?

  31. 31

    jim Says

    If you haven’t already, you’ll need to restart Apache to force it to reload the PHP modules. Typing “service httpd restart” at a command line is the easiest way to do it.

    Jim.

  32. 32

    Roshan Kulkarni Says

    I had a difficult time getting PHP 5 to work with MySQL on CentOS Release 5. phpinfo() indicated that the PHP configuration had the –without-mysql option. Also, there was no mysql section in the output of phpinfo().

    Here is what finally made it work:

    * Do a ‘yum install php-mysql’

    * Check /etc/php.ini to determine the extension_dir where php modules are located. It was ‘/usr/lib/php/modules’ on my machine.

    * Check if mysql.so was present in the modules directory.

    * Add a ‘extension=mysql.so’ entry in php.ini

    That’s it. MySQL works from PHP now. phpinfo() still shows that the configuration is –without-mysql. However there is now a mysql section in the output of phpinfo().

    Hope this helps.

    -Roshan
    http://www.it.iitb.ac.in/~roshan

  33. 33

    John Says

    Your advice was a great start for me, as I’m probably in way over my head- but certainly trying to learn. I enabled centosplus and tried to update the entire system with yum via webmin, but the upgrade failed without giving any context. So then I thought I should try a smaller step by just updating php. Any idea why I’m getting this missing dependency? What steps would you take from here? Any help would be greatly appreciated. Thank You, John

    # yum upgrade php

    Setting up Upgrade Process

    Setting up repositories

    Reading repository metadata in from local files

    Resolving Dependencies

    –> Populating transaction set with selected packages. Please wait.

    —> Package php.x86_64 0:5.1.6-3.el4s1.8 set to be updated

    –> Running transaction check

    –> Processing Dependency: php = 4.3.9-3.22.9 for package: php-mysql

    –> Processing Dependency: php-cli = 5.1.6-3.el4s1.8 for package: php

    –> Processing Dependency: php = 4.3.9-3.22.9 for package: php-pear

    –> Processing Dependency: php-common = 5.1.6-3.el4s1.8 for package: php

    –> Restarting Dependency Resolution with new changes.

    –> Populating transaction set with selected packages. Please wait.

    —> Package php-common.x86_64 0:5.1.6-3.el4s1.8 set to be updated

    —> Package php-mysql.x86_64 0:5.1.6-3.el4s1.8 set to be updated

    —> Package php-cli.x86_64 0:5.1.6-3.el4s1.8 set to be updated

    –> Running transaction check

    –> Processing Dependency: php-pdo for package: php-mysql

    –> Processing Dependency: libmysqlclient.so.15()(64bit) for package: php-mysql

    –> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15)(64bit) for package: php-mysql

    –> Processing Dependency: php = 4.3.9-3.22.9 for package: php-pear

    –> Restarting Dependency Resolution with new changes.

    –> Populating transaction set with selected packages. Please wait.

    —> Package php-pdo.x86_64 0:5.1.6-3.el4s1.8 set to be updated

    —> Package mysql-libs.x86_64 0:5.0.48-1.el4.centos set to be updated

    –> Running transaction check

    –> Processing Dependency: php = 4.3.9-3.22.9 for package: php-pear

    –> Finished Dependency Resolution

    Error: Missing Dependency: php = 4.3.9-3.22.9 is needed by package php-pear

  34. 34

    Ollie Says

    You saved my bacon as I need to use PHP 5 for the Zend Framework. Thanks a ton.

  35. 35

    Matthew Says

    Thanks a bundle! I was going to download a MySQL 3rd-party RPM but this saved me a few dozen megabytes!

    Thanks!

  1. 1

    Jim O’Halloran’s Weblog » Blog Archive » MySQL 5 on CentOS

    Pingback on Jul 30th, 2006 at 11:21 am
  2. 2

    No Sheep » Dotster VPS Upgrade to PHP 5 and MySQL 5

    Pingback on May 7th, 2007 at 10:45 pm
  3. 3

    links for 2007-05-27 « J.P.DeFillippo

    Pingback on May 29th, 2007 at 6:33 pm

Leave a Reply

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>