You are here

How To Upgrade To PHP 7 On CentOS 7 With No Existing Virtual Hosts

NOTES: The following code was all I needed to set up a basic LAMP stack on a Linode server, and should work fine on DigitalOcean, Vultr, etc.

Today I'll show you how to upgrade to PHP 7 on CentOS 7 with no virtual hosts set up (meaning it's a new server with no websites set up yet). When I initially installed PHP on CentOS 7, it gave me PHP 5.4.16. But with everyone slowly moving to PHP 7, I had to figure out how to do this too, and decided to write this post to help others.

First, you'll want to consider the main advantage & disadvantage before upgrading to PHP 7:

#A. The main advantage of PHP 7 is S-P-E-E-D. I'll write a related blog post in the near future regarding this, but trust me when I say the difference between PHP 5 & 7 is like the difference between heaven and hell. ;)

#B. But before upgrading to PHP 7, you need to understand that your websites might not function 100% properly unless you patch up code that was made for earlier versions of PHP. I'll also write a related blog post in the near future regarding this, but you need to be prepared in case something goes wrong. The good news is that the vast majority of the patches should already be available online, since most of the code should've been all patched up by now. Unless you have a very complicated website, you will most likely be ok to upgrade.

So here's how to upgrade to PHP 7:

#1. sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#2. sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#3. sudo yum remove mod_php php-cli php-common
#4. sudo yum install php70w php70w-opcache
#5. (Optional) php -v
#6. sudo yum install php70w-gd php70w-mbstring php70w-mcrypt php70w-mysqlnd php70w-xml
#7. sudo systemctl restart httpd.service

Notes:

#1 - #2. This downloads PHP 7.
#3. This removes existing PHP packages.
#4. This installs PHP 7.
#5. This just spits out the PHP version.
#6. This installs additional essential PHP 7 modules, without which I got error messages when trying to install MariaDB (or MySQL), phpMyAdmin, Virtualmin & Webmin later on.
#7. This restarts Apache in CentOS 7. In CentOS 6, the command would be "sudo service httpd restart". So if you want to upgrade to PHP 7 on CentOS 6, you can just follow steps #1 - #6 above, and then change the code for step #7 accordingly.

And that's it. In the near future, I'll write a related blog post on how to upgrade to PHP 7 on CentOS 7 with existing virtual hosts already set up. I've done it once before, and remember it being a bit of a pain in the ass to configure correctly, so I'll spin up a new test server on Vultr shortly and play around with it for the next few weeks first. Stay tuned! :)

Tags: 

You are here