The Montoya Herald — ChristianMontoya.com
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:
looking forward for more information about this. thanks for sharing. Eugene
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
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/
Thank you for this really helpful instruction. i was stuck with old PHP
Many thanks for your sharing. I was successful on updating my site to PHP 5.2.8
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
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
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/
Thanks for this. Saved me a lot of time..
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
Had to say thank you for this tutorial. Helped me alot.
Thanks Christian. =)
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.
@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.
Ok, thanks for taking the time to write this up and to answer my question.
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.
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.