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.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF