Bobcares

Digitalocean – Change PHP version – Common errors and fixes

by | Dec 18, 2018

DigitalOcean Droplet owners often need to change PHP version on their servers to support custom web applications. This PHP change involves many configuration changes in web server too.

And, any faulty step in this PHP change process can affect the working of all websites.

At Bobcares, we help cloud server owners with PHP version change as part of our Managed Cloud Services.

Today, we’ll see the steps to change PHP version, common errors with version change and how we fix them.

How to change PHP version in DigitalOcean

We know that changing PHP version will affect all the websites in the Droplet. Therefore, it is a critical task.

Now, let’s see how our Support Engineers do this without affecting the websites.

 

1. Backup Droplet

First and foremost, we take a backup of the Droplet. This involves taking a snapshot of the server with the current settings. When there is a problem with new version of PHP, it works as a fallback option. This helps to restore the Droplet and make websites available in a jiffy.

 

2. Add new PHP package

Now, our Cloud Engineers update the system packages and fetch the new PHP files to the server. For instance, in an Ubuntu server, the exact commands to install PHP7.2 would be:

apt-get update && apt-get upgrade
apt-get install php7.2
apt-get install php-pear php7.2-curl php7.2-dev php7.2-mbstring
apt-get install php7.2-fpm

Now, we have the new PHP7.2 version, its modules and process manager on the Droplet.

 

3. Change Web server configuration

The next step is to make web server use the new version of PHP.  The exact change depends on the type of web server too.

For example, in a Droplet with Apache web server, our Support Engineers do the following to enable PHP7.2

a2enmod php7.2
service apache2 restart

Similarly, we edit the Nginx web server configuration files like /etc/nginx/sites-available/default, /etc/nginx/sites-enabled/default to reflect new PHP version.

Again, to set new PHP 7.2 as the default PHP of the Droplet, we use:

update-alternatives --set php /usr/bin/php7.2
service nginx restart

The restart of the web server ensures that all websites now use new PHP.

 

4. Remove old PHP package

Now, we can remove the old PHP files.

To remove PHP7.0 package files from an Ubuntu Droplet, we use:

apt-get purge php7.0 php7.0-common

 

Common errors in PHP version change and their fixes

Although, the steps to change PHP version looks simple, we often see server owners complain about website failures after PHP change.

Let’s now have look at the top errors.

 

1. Default PHP showing old version

At times, even after changing the PHP version, the default PHP will still show the old version. But, when you check the version of PHP in the browser, it shows correct version.

This happens because of not updating the command line version of PHP correctly. To fix this, our Cloud Engineers remove the old PHP binary file and link it to the correct file. The steps to set PHP7.2 would include:

rm /usr/bin/php
ln -s /usr/bin/php7.2 /usr/bin/php

2. Websites showing errors

Similarly, often websites report errors like 500 internal server errors, memory limit errors, etc. due to incorrect PHP configuration.

Here, we first check the existing PHP configuration of the domain as well as the server. Then, we analyze the web server log files to find the real reason for the error.

These errors mostly happen when the server owners do not recreate customization in the php.ini file of the new version.

To fix the errors, our Cloud Specialists edit the correct php.ini file, change the PHP parameters, etc. Then, we do a web server restart and that fixes the errors.

Again, it is a matter of fact that the website code should be compatible with the version of PHP on the server.

 

3. PHP pages show as Plain text

Recently, we got a support request from a DigitalOcean Droplet owner that all php pages just show the code in the browser. The Droplet was using Nginx as the web server.

On checking, we could see that the Nginx was not using the correct PHP Fastcgi Process Manager. As a result, the website code was not able to execute and show proper pages.

To fix, we edited the file /etc/nginx/sites-enabled/default and added the path to correct PHP7.2 FPM with this entry.

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

After Nginx restart, websites started working again.

 

Conclusion

Changing the PHP version on the DigitalOcean Droplet involves a series of steps. However, a slight mistake in the process can take all your websites down. Today, we saw how our Cloud Engineers change the PHP version on the server without causing downtime.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.