Upgrading to PHP 5.6 should be a quick and easy, but as most of us have experienced first hand, things don’t always go smoothly. If you are doing this on a live web server then I suggest you put all your sites into maintenance mode before doing anything here. If you don’t do this you could end up dumping raw php code onto the users screen which could be bad bad news if the wrong kind of person sees it. It can be risky doing this if you aren’t too sure what you are doing, but ya gotta do what ya gotta do!
PHP 5.6 is not supported officially, so you are going to need to use a 3rd party repo. There is no need to worry about this, it’s perfectly safe. Start by setting up the repo, by executing one of the following commands, depending on whatever version of CentOS or RHEAL you are using.
CentOS / RHEL 7.x: rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm CentOS / RHEL 6.x: rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
You now have things setup to install PHP 5.6 (easy right!). Before you install you should remove older versions of PHP to avoid any conflicts. You may still get conflicting plugins, but they are easy to sort once you know you are correctly running the latest version. So lets remove the current version of PHP.
!!!WARNING!!! This install is quick, but make sure you you have apache either disabled or any websites in maintenance mode. Your database info and raw php code may be served to the users browser if php is not installed when the request is made. Stopping apache is the quickest way around this, but a maintenance site is best advised.
yum remove php*
The star will remove everything you have installed that is related to php. You will be reinstalling everything for php 5.6 after this so everything will be fine.
Now that any older PHP libraries and plugins are removed we can install the latest version of PHP. Before you do this make sure you aren’t running anything like cPanel that does not support this version of PHP. You shouldn’t have any issues if you keep your system up to date.
yum install php56w
If you want to install any additional PHP libraries you can do so using yum, but make sure you specify “php56w” and not “php” on its own. You should know already what libraries you use, if you don’t know you will eventually get errors that should be easy to fix. If there are issues that mbstring or any php library is not installed you can install it by typing “php56w-name-of-lib”. Here are some sample libraries that you might need.
yum install php56w-xml php56w-mbstring php56w-opcache
Missing dependencies after installing??
You will likely have some missing dependencies after the upgrade. There is no need to worry, you can reinstall them nice and easy. For example, after the upgrade you discover that scripts are failing when they try to process images. There is a good chance that it’s because the image GD library is missing. Running “yum install php56w-gd” will install the package and the errors will go away. The same applies to any other error messages you might be coming across for missing dependencies.