This is second article related to CentOS somewhat outdated default setup.
I have previously discussed Steps to update MySQL to 5.5 and now its time to look at PHP
If you run VPS or dedicated server with CentOS 6.x installed often you will find that default setup would include somewhat antiquated PHP and MySQL versions – 5.3 and 5.1 respectively.
Unfortunate situation dictated by the fact that main distro package used in such environment does not include latest versions.
If SSH and Linux management is allowed, it does not take long to bring environment up to date.
Note: it is much easier to update packages right away once server is still fresh and there is not much other software installed.
Update PHP to 5.5 on CentOS from SSH
Make sure you have root access to underlying Linux and open SSH session.
- Check version of PHP installed. Let’s assume PHP 5.3 or 5.4 is present. You should see something similar to the following output
# php -v PHP 5.4.17 (cli) (built: Jul 23 2013 00:02:04) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
- Default CentOS repo accessible with yum would not have proper PHP version and you would need to add Webtastic repo with
# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
- As mentioned above we are interested in latest stable version of PHP 5.5. Let’s make sure it is in fact available for installation
# yum list available | grep php55
then examine output to make sure php55w packages are present.
- Depend on your current configuration, you may need some additional PHP libraries (full list can be found here), so please take a note of what packages you have installed and setup in your system before proceeding with next step
- Now you can install the new PHP 5.5 core and packages. Options below is most basic and commonly used configuration for 64bit system
# yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64
Once operation is completed, run PHP version check again, you should see that PHP version is now 5.5
# php -v
PHP Upgrade fails with dependency error “Error: php55w-common conflicts with php-common-5.3.3-23.el6_4.i686”
Since there is previous version of PHP present and we did not do clean uninstall, dependency resolution procedure may become “confused” and could not figure out what to do with common package.
Try the following two commands before you attempt installing PHP again
# yum install yum-plugin-replace # yum replace php-common --replace-with=php55w-common
First will ensure that we do have replace option support and then update php-common package before we update PHP core
php -v command shows ionCube compatibility error
Simply put, ionCube extension is older version and not compatible with new PHP version.
What is the ionCube in the first place and why we better keep it?
ionCube is an PHP code encryption extension usually used with Zend Engine and allows protect otherwise open text PHP code from direct access and analysis. Many commercial PHP products would come encrypted and without this extension you may no longer will able to use them.
Let’s assume ionCube is here to stay and let’s see what we can do to reanimate it.
- Visit ionCube download section and get two files: Loader Wizard or loader-wizard.php (do not confuse it with Loader Installer) and Loader package for Linux 64-bit
- Unpack Loader package along with loader-wizard.php into web server folder which you can later access from your browser
- Open loader-wizard.php in your browser and follow steps presented
- Once all steps are completed and wizards verifies the location of the required ionCube extension file, restart Apache and verify PHP version again. You should see ionCube is now loaded successfully
# service httpd restart # php -v
In some cases PHP would unable to load proper version of ionCube
Try the following:
- visit /etc/php.d folder and look for 00-ioncube-loader.ini or similar
- if located open for edit and check what zend_extension file is referenced to make sure proper version of the loader is used
php -v command shows timezone warning
PHP Warning: date(): It is not safe to rely on the system's timezone settings
This message easily to notice when you run php -v after upgrading to latest version of PHP as it is no longer set by default.
- For CentOS locate system php.ini typicaly found /etc/php.ini
- Open it in a text editor
- Find the following line
- If line is commented out, you need first uncomment it
- Visit PHP.net and locate the time zone you want to run your server in
- Use string name of the time zone desired. Please note that you need to enclose name in double quotes
- Since you are editing PHP settings, you may as well increase PHP memory limit to 512M by changing
- Save your changes and exit out of text editor
- Restart Apache
service httpd restart
While not strictly necessary, I would recommend reboot your server. This may help with some phantom issues encountered rarely due to some ongoing active processes.
Don’t forget to log off and close your SSH session