4 minutes reading time (760 words)

How to Upgrade Your Website PHP Version

How to Upgrade Your Website PHP Version

If you are reading this post, chances are your website is running with an ancient version of PHP. You are not alone, PHP version 5.3 is used by 31.1% of all the websites and 5.4 has 29% share. Both of this PHP version already reached end of its life and no more security update will be provided. That means, you are already in big security risk!

Joomla is one of the most powerful and secure CMS on the planet now. But Joomla itself is not enough to protect your site if you are running old version of PHP. People often criticize, its CMS fault when their site get hacked but they didn’t realized it's could be their server stack.

Joomla recently raised its PHP version requirements to PHP 5.6 or 7 however it can run on PHP 5.3.10+ too. PHP 7 is already released and it's a breakthrough of PHP history. So, its high time to upgrade your server PHP version to PHP 7 or at least 5.6+. In this tutorial, I’m going to show you how you can do that.

**IMPORTANT : If you decided for PHP 7 make sure your Joomla version is 3.5+ in order to work properly.

Managed or Shared Hosting

The Easiest Way

Ask your host to update PHP version of your hosting. Most likely, they will do it for free and it’s the most easiest way to update. However, if they are refused or unable to do so, it's high time to switch to a reliable provider.

Upgrade PHP From cPanel

Most cPanel based hosting provider allow you to update PHP version from your cPanel. Search PHP Version Manager or PHP Configuration option and click on it.

Select PHP version 5.6+ or 7 and save.

Upgrade from .htaccess file

If above 2 method doesn’t work for you, your best bet is to upgrade PHP version using .htaccess file.

Go to cPanel, File Manager and choose "Web Root (public_html/www)". There create a new file (or edit the existing one) called .htaccess and add the following line:

To switch to PHP 5.6

AddHandler application/x-httpd-php56 .php .php5 .php4 .php3

To switch to PHP 7.0

AddHandler application/x-httpd-php70 .php .php5 .php4 .php3

This setting will apply recursively to all of the subdirectories. In case you'd like to have a different version of PHP in a subdirectory, create a new .htaccess file in it with the directive for the desired PHP version in it.

VPS or Dedicated Server

If you are running Ubuntu 14.04 or below you can update using this commands :

sudo apt-get upgrade
sudo apt-get dist-upgrade

Lets add php repo in our list. Pleaes choose approprite version.

For PHP 5.6

sudo apt-add-repository ppa:ondrej/php5-5.6

For PHP 7.0

sudo apt-add-repository ppa:ondrej/php

Upgrade to PHP 5.6

sudo apt-get install php5

Your PHP version is upgraded now and you just need to restart your server

Apache : sudo service apache2 restart

Nginx : sudo service nginx restart

Upgrade to PHP 7

Upgrading to PHP 7 require a little amount of extra work. Depends on your webserver you can perform this commands.

Upgrading mod_php with Apache

First, install the new packages. This will upgrade all of the important PHP packages, with the exception of php5-mysql, which will be removed.

sudo apt-get install php7.0

Note: If you have made substantial modifications to any configuration files in /etc/php5/, those files are still in place, and can be referenced. Configuration files for PHP 7.0 now live in /etc/php/7.0.

If you are using MySQL, make sure to re-add the updated PHP MySQL bindings:

sudo apt-get install php7.0-mysql

Upgrading PHP-FPM with Nginx

This section describes the upgrade process for a system using Nginx as the web server and PHP-FPM to execute PHP code.

First, install the new PHP-FPM package and its dependencies:

sudo apt-get install php7.0-fpm

You'll be prompted to continue. Press Enter to complete the installation. If you are using MySQL, be sure to re-install the PHP MySQL bindings:

sudo apt-get install php7.0-mysql

Note: If you have made substantial modifications to any configuration files in /etc/php5/, those files are still in place, and can be referenced. Configuration files for PHP 7.0 now live in /etc/php/7.0.

Now update your Nginx server block with new php7.0 socket path.

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

Save and exit the file. Now you are just a restart away.

sudo service nginx restart

Check your PHP version for Joomla admin > System > System Information. You can see your PHP version number there.

I strongly recommend to upgrade to PHP 7 because its PHP's later version and it will make your website blazing fast without doing anything.

0
Introducing GSoC 2016 Team
 

Comments

Already Registered? Login Here
No comments made yet. Be the first to submit a comment

By accepting you will be accessing a service provided by a third-party external to https://magazine.joomla.org/