The Montoya Herald, a weblog about Blueprint, jQuery, design, music and life, publishing on the web since September 2005. Written by Christian Montoya: developer, designer and entrepreneur.

The Montoya Herald — ChristianMontoya.com

Search

Buy My DVD!

Like What I Do?

My Amazon.com Wish List

On this domain

Elsewhere

Upgrading PHP and installing APC on CentOS 5 with Plesk

Posted on October 1, 2008.

Every time I setup a new server, I find myself going through the same steps. Upgrade PHP to something greater than 5.2 (preferably, the latest stable version), install APC, and make sure it all works. It's always a pain, too, unless I follow the same basic steps, so I'm going to write them down here and hope that they don't change. Feel free to use these steps too. Remember, I'm running CentOS 5.2 Linux with Plesk, and I've already got PHP, MySQL and Yum installed.

Command Line Steps

Upgrading PHP:

wget -q -O - http://www.atomicorp.com/installers/atomic.sh | sh
yum update php

This enables the Atomicorp Yum repository, which includes a stable version of PHP 5.2. If a straight wget & sh seem scary, you can check out this page: Atomicorp Downloads.

At this point I restart apache, which is usually: service httpd restart. I then verify that PHP is at version 5.2 with:

php -v

The expected output is something like:

PHP 5.2.6 (cli) (built: May  2 2008 16:06:40) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Now it's time for APC (see an explanation of why APC is a must-have on any PHP server at the end of this post):

Install Pear:

yum install php-pear

This allows me to access the PHP Extension and Application Repository, which has APC.

Install PHP Development Tools:

yum install php-devel

This allows me to compile PHP extensions, and never seems to be installed by default.

Install Apache HTTPD development tools:

yum install httpd-devel

This is necessary to setup APC under PHP 5.2.

Install APC:

pecl install apc

This should build the extension, unless something goes wrong.

Now, to configure APC there are two options: either edit php.ini, or add apc.ini to the php.d folder. Either way, I use the following:

extension = apc.so
apc.enabled = 1
apc.shm_size = 48
apc.include_once_override = 1
apc.mmap_file_mask = /tmp/apc.XXXXXX

With the exception that sometimes I raise the apc.shm_size to a higher value. This value is the number of MB of shared memory to use for opcode caching, and on a bigger server with more RAM and more scripts to cache, I'm willing to allocate more.

Again, php.ini is usually located at /etc/php.ini and apc.ini would be a new file to place in the /etc/php.d/ folder. The important thing is to change one of these files, not both, or else you would be loading the extension twice.

Finally I restart apache again (service httpd restart) and verify that php -v returns the same output. If I want to verify that apc is working, I locate apc.php on the server and then copy it to a web-accessible directory. Then I load that script in my browser, and if I can see pretty graphs, then it's working. Don't leave this file in a web-accessible directory, though; you wouldn't want others getting the information it has.

And that's it… at this point, I'm ready to develop whatever application I'm working on. Now, as for an explanation of why I insist on APC these days, as opposed to Xcache or Eaccelerator or, gasp, nothing at all:

You have got to use an opcode cacher with PHP. Otherwise, all your scripts have to compile every time they run, which takes a significant amount of time in comparison to whatever else your scripts do. As for which one you should use, APC is very stable and widely supported. I've noticed that APC is less likely to fail than the other cachers, which is really important when I am working on production sites. Anyway, just try it for yourself; install APC on a server that doesn't have any other caching methods, and you should notice a difference.

P.S. The following links were essential to putting these steps together:

4 Trackbacks/Pingbacks

  1. Pingback: Pop Answers is now running on its own server at Slicehost | The Montoya Herald on December 6, 2008
  2. Pingback: Upgrading PHP and installing APC on CentOS 5 with Plesk | The Montoya Herald on May 20, 2009
  3. Pingback: PHP – APC tunning on June 23, 2011
  4. Pingback: PHP – APC tunning on June 23, 2011

23 Comments

  1. Eugene on October 21, 2008

    looking forward for more information about this. thanks for sharing. Eugene

  2. George on October 21, 2008

    Hi,
    after i finished
    i get this message:

    Failed loading /usr/lib/php/modules//php_ioncube_loader_lin_5.1.so: /usr/lib/php/modules//php_ioncube_loader_lin_5.1.so: undefined symbol: zend_unmangle_property_name_ex
    PHP 5.2.6 (cli) (built: May 2 2008 16:06:40)
    Copyright (c) 1997-2008 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

    can you advise me how sure it's working good please

    thanks a lot
    George

  3. Christian Montoya on October 22, 2008

    George, it sounds like you have a problem with IonCube loader, which is another module. It's possible that you need to update it or remove it. I would recommend visiting the atomicorp site and getting help over there, since everything starts with atomicorp's release of PHP 5.2.
    http://www.atomicorp.com/channels/

  4. Smr on January 19, 2009

    Thank you for this really helpful instruction. i was stuck with old PHP

  5. NguyenPham on February 17, 2009

    Many thanks for your sharing. I was successful on updating my site to PHP 5.2.8

  6. Steven on February 28, 2009

    Hi thanks for the tutorial I'm totally a newbie with all this stuff, really appeciate the tutorial but whenever I try to upgrade my server from PHP 4 to PHP 5 I get this error:

    Error: Missing Dependency: php-common = 5.2.8-3.el4.art is needed by package php-xml

    Do you know what the problem is? Please help

  7. Chris on March 12, 2009

    Thanks Christian - I've been really battling with the installation of APC and you got me setup straight away.

    Now I just need to get my Windows installation working as well…

    Thanks again

  8. Sam on July 24, 2009

    We had to go through a similar process on a RHEL4 system, with a few snags that you did not run into. So hopefully this list of problems/solutions will be of use to someone:

    http://www.nurelm.com/themanual/2009/07/24/upgrading-php-and-mysql-on-red-hat-enterprise-linux-4/

  9. lgcamson on August 15, 2009

    Thanks for this. Saved me a lot of time..

  10. Mehmet Korukmez on September 15, 2009

    Great Stuff.I have dedicated servet @ 1 and 1 which they dont provide any f****n support,but this tutorial helped me to solve my problem.
    Thanks

  11. Gabriel on September 18, 2009

    Had to say thank you for this tutorial. Helped me alot.

    Thanks Christian. =)

  12. Zeljko on May 17, 2010

    Hello,

    Thanks for the nice tutorial.

    I just wanted to know if there is a way to revert changes.

    You know, in case there is some php app that doesn't work with PHP 5.2.x ?

    Thanks again.

  13. Christian Montoya on May 17, 2010

    @Zeljko: I don't think so. Your best option is to back up your entire server configuration before you do the upgrade (kind of like a system restore point in Windows) and keep that handy in case you have to go back.

  14. Zeljko on May 19, 2010

    Ok, thanks for taking the time to write this up and to answer my question.

  15. Mike on June 25, 2010

    This is great just thought I would add a suggestion. IF you are running a previous version of mysql it may fail after updating. I wanted to try and save people time figuring this issue out because the resolution is very easy (or at least was for me), but the diagnosing took some time. If your mysqld service wont start type the following:

    tail -f /var/log/mysql.log
    chances are that somewhere in there there will be an error similar to this
    100625 10:59:13 [ERROR] /usr/libexec/mysqld: unknown option '–skip-bdb' (different skips depending on version i believe)

    all you have to do is:
    cp /etc/my.cnf /etc/my.cnf.bak * creates a backup just in case
    then remove or comment out the skip and restart the service and all should be functional.

  16. Helen on July 3, 2010

    Hi,

    I wish to upgrade PHP 5.1.6 to 5.3.2 in Plesk Panel 9.5, i follow the commands above but having below error:

    Error Downloading Packages:
    tzdata-java-2010i-1.el5.x86_64: failure: RPMS/tzdata-java-2010i-1.el5.x86_64.rpm from updates: [Errno 256] No more mirrors to try.
    krb5-workstation-1.6.1-36.el5_5.4.x86_64: failure: RPMS/krb5-workstation-1.6.1-36.el5_5.4.x86_64.rpm from updates: [Errno 256] No more mirrors to try.
    lcms-1.18-0.1.beta1.el5_3.2.i386: failure: CentOS/lcms-1.18-0.1.beta1.el5_3.2.i386.rpm from base: [Errno 256] No more mirrors to try.
    grep-2.5.1-55.el5.x86_64: failure: CentOS/grep-2.5.1-55.el5.x86_64.rpm from base: [Errno 256] No more mirrors to try.
    libsmbclient-3.0.33-3.29.el5_5.x86_64: failure: RPMS/libsmbclient-3.0.33-3.29.el5_5.x86_64.rpm from updates: [Errno 256] No more mirrors to try.

    Has the yum update support version 5.3.2 already? How can I update then?

    Thanks.

  17. Zeljko on November 18, 2010

    Hi, I tried on 1 server and everything was ok. Tried on the other and…

    Sorry, I was not able to successfully run APXS. Possible reasons:

    1. Perl is not installed;
    2. Apache was not compiled with DSO support (–enable-module=so);
    3. 'apxs' is not in your path. Try to use –with-apxs=/path/to/apxs
      The output of /usr/sbin/apxs follows
      cannot open /httpd/build/config_vars.mk: No such file or directory at /usr/sbin/apxs line 201.
      configure: error: Aborting
      ERROR: `/var/tmp/APC/configure –with-apxs' failed
  18. Dave Kopecek on January 25, 2011

    Fantastic. Thanks so much for this post.

    Did get the following warning on php -v after restart:
    PHP Warning: PHP Startup: apc.shm_size now uses M/G suffixes, please update your ini files in Unknown on line 0

    To fix change:
    apc.shm_size = 48

    to:
    apc.shm_size = 48M

    …With a little cash 48G would probably work too :-)

  19. cheko on January 28, 2011

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/module s/apc.so' - /usr/lib64/php/modules/apc.so: cannot open shared object file: No such file or directory in Unknown on line 0

    PHP 5.2.17 (cli) (built: Jan 7 2011 10:39:29)
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

    I receive this msj with php-v and i can´t import databases in phpmyadmin…

    any idea?

    thank´s…

  20. Filip on January 30, 2011

    Many thanx 4 this.

  21. Estanis on March 15, 2011

    Hello.
    I follow the manual and when i finish all the steps, i can't see any website from my server.
    when i try to surf the web http://tienda.ihug.es i get a blank website.
    All the webs in this server appear a blank website… do you know what's the problem? i'm using plesk 9.5.4 in centos 5

    thank you

  22. Flho on July 13, 2011

    Thanks for this tutorial. I must admit I haven't test it (I already know 'yum') but I want to say Mike saved my life today !!
    "all you have to do is:
    cp /etc/my.cnf /etc/my.cnf.bak * creates a backup just in case
    then remove or comment out the skip and restart the service and all should be functional."

    In fact, I upgrade PHP version (5.3.6 now) and the upgrade add this "skip-bdb" in my my.cnf, causing the "crash" of the service mysqld. Comment out this "skip-bdb" resolve the issue.

    Thanks Mike !

  23. Edgar on July 20, 2011

    Hello,
    great Job, thanks.
    I am using Centos 5.6 and Plesk. Upgrade to php5.3.6 with this tutorial and all works fine. Thanks a lot for this…
    The only thing i have to do after the upgrade is to upgrade the ion-cube-loader. But this was no problem.
    Greetings
    Edgar

Sorry, comments for this entry are closed at this time.