Resolve Website Issues After PHP upgrade 2017 [SOLVED]

Site Issues after upgrading PHP

After upgrading to PHP 7, you may notice that your site is having issues. For example on a WordPress site, certain plugins will be disabled and you will see messages stating that certain PHP modules are missing.


  • requires the function mb_detect_encoding to import and export CSV files
  • …currently has no PHP cURL library activated
  • AWS plugin is disabled
  • mb_detect_encoding not enabled
  • SOAP module not enabled
  • ZipArchive Library is missing or disabled
  • PHP Fatal error: Cannot redeclare class wfWAFWordPressRequest

The admin.php?page=wc-status page will tell you that certain PHP modules are missing as well.

After installing these modules on your server and confirming that they are working, your site may still produce these errors.

From the command line, the following command will output what version of PHP is being used.

And this will tell you what php.ini file is being looked at:

But, this can fool you! It shows you the php.ini file that is used by the PHP CLI, NOT the Apache web server serving your site!

How to see what version of PHP Apache is using

Is Apache still using the old php.ini file?

To see, output the php.ini file as Apache “sees” it by creating a file with in the root of your website and checking what version is being used.

WARNING: Give this file an obscure name. Do not name it phpinf.php. We do not want to give malicious coders any information about our system, do we?
REMOVE THIS FILE as soon as you are done with it as it is a security risk to have it there.

For this article, I am using an example of replacing PHP 5.6 with PHP 7.1 on an Ubuntu 14 server.

If you have installed PHP 7.1

If Apache is still looking at PHP5 (or whatever older version you had), it is likely that the Apache module for the upgraded PHP version is not installed.

One way to check for this is to take a look at the list of Apache modules.
On the command line, one cal list the enabled modules filtered for php modules like this:

If your output lists your old PHP version, then Apache needs the new PHP module installed and enabled.

Tell Apache to use the right PHP Version

You will first need to disable the old PHP module. Then install the Apache module for the new PHP version. If you have not yet installed the new PHP version, this can be done all on one line like this:

Here are the commands:

How to fix wp-user stopped working after PHP Upgrade [resolved]

A server side user can have special permissions to won you WordPress application.

If you have set one up and it stops working after you upgrade your PHP it is likely related to SSH2 PHP module.

A while back I took advantage of this post from Digital Ocean about Secure Updates and Installations in WordPress on Ubuntu and it worked great until I upgraded to PHP7.

I had upgraded from PHP 5 to PHP 7. After upgrading to PHP 7 it is necessary to install PHP 7’s version of the ssh2 package.

How to install ssh2 for php7 on ubuntu

It’s pretty easy, really.

ssh into your server via the command line.

Then update you package manager for Ubuntu.

Then install the PHP 7 ssh2 package with the following command.

HINT: If your PHP version is 7.0 then use php7.0-ssh2 instead.

Then restart your apache2 server

Hope this helps someone!

Error First Callbacks in Node JS

Callbacks are a systemic part of a Node.js application. A non-blocking well-balanced flow of controlled asynchronous modules is made possible by properly implemented callbacks. But what is “properly implemented”? Creating code that will scale with your projects means using a reliable protocol that is a well-known standard.

The “error-first” callback (also known as an “error-back”, “errback”, or “node-style callback”) was introduced to solve this problem and has since become the standard for Node.js callbacks.” — TheNodeWay

Having a dependable pattern when it comes to callbacks is important. This is because node uses asynchronous code heavily. The asynchronous code gets confusing really fast. It would be a heavy burden to bear for developers to be stuck maintaining varied styles from one module to the next.

“While every use-case has different requirements and responses, the error-first pattern can accommodate them all.” — TheNodeWay

The pattern is very simple. The first parameter of a callback is “reserved” for a possible error object. The second parameter is for successful response data. If there is no error then the error parameter will be null.
This means that successfully returned data is expected to be in the second argument.

Here is an example of what it may look like:

Notice that the first argument is the error object and can be checked. If there is an error, it is then handled. If there is no error, subsequent successful data arguments can then be processed.

Why New Domain Keeps Forwarding to Old Domain [Solution]

After changing a domain name and updating the DNS records you might find yourself baffled by the fact that the site continues to redirect to the old domain. You may be frustrated as you have seemingly tried everything.

Likely, you are dealing with a WordPress site. With a WordPress website, references to the domain name are hard coded into the database.

Migrating WordPress site to new Domain Name

After changing a domain name for a WordPress site, the database will need to be updated to reflect the change. Failing to change the references to the old domain name in the database means the site is still attempting to point at the old domain name.

To fix this issue, perform the MySQL queries shown below. In case it is not obvious, replace ‘old-site’ with the name of your previous domain name, and replace ‘new-site’ with your current domain name.

CAUTION: Remember to first make a backup of your current database.

MySql queries for migrating site to new domain

The MySql queries for migrating site to new domain are as follows:

SOLID OOP, Liskov Substitution Principle

Liskov Substitution Principle

The Liskov Substitution Principle [1] (LSP) is applied to inheritance hierarchies. LSP specifies that classes should be designed such that client dependencies can be substituted with subclasses without the client “knowing”.

How to apply the Liskov Substitution Principle

To adhere to Liskov Substitution Principle, subclasses must function in the same way as their base classes. The specific functionality of the subclass may be different but must conform to the expected behavior of the base class. This means that, in order to be a true behavioral subtype, the subclass must implement the base class’s methods and properties. It also means the subclass must conform to the base class’s implied behavior.

A subclass behavior should never do less than its superclass. In other words, if the subtype does something that the client does not expect, such as throw an exception or imposes unexpected behavior, then the design in violation of the Liskov Substitution Principle.

Why is the LSP important?

Undefined behavior results from not adhering to the Liskov Substitution Principle. Undefined behavior can be a real “Gotcha” as it can seem to work okay during development and then unexpectedly bug out in production. This kind of issue can cause a team to spend weeks debugging something that is very difficult to duplicate.


Liskov Substitution Principle,


Open/Close Principle (OCP)

The Open/Close Principle means that software entities should be open for extension but closed for modification [1].

Open to extension

“Open to extension” means that classes are designed with the possibility of new functionality in mind. Down the road, one can extend functionality as new requirements come up.

Closed for modification

“Closed for modification” means that once you have developed and tested a class, it should not be modified, except to correct bugs.

High Level “How to” OCP

Rather than using concrete classes, abstractions such as interfaces or abstract classes may be used to extend functionality as the need arises. Then creating new classes that implement the interfaces can extend the functionality. The new classes which implement the interfaces can be tested as units without having to make changes to the original class.

Benefits of OCP

Applying OCP in you object oriented design cuts down on the need to change source code once it has been written. In this way, the “Open to extension Closed for modification” principle reduces the risk of introducing new bugs.

This is a good argument for unit testing. Once each unit has been tested there should be no need to modify it since it’s single responsibility has been proven.


  1. Open/closed principle,

SOLID OOP, Single Responsibility Principle

Single Responsibility Principle (SRP):

Single responsibility principle [1] means that any one class should not have more than one reason to change. For this to be true, a class will only have one single responsibility.

Avoid creating a god class [2]. Objects that are controlling way too many other objects in a system and often becoming “The Class That Does Everything” is known as a “God class”.

Straight forward easy to read comments on our classes and methods can help one recognize if the single responsibility principle is being adhered to.


  1. Single Responsibility Principle,
  2. God Class,,


PHP: Dynamically refer to an object property

Sometimes you may need to programmatically determine which property of an object you would like to call. Are you trying to dynamically refer to an object property?

In order to do this, you need to get past an issue with ambiguity.

The PHP documentations says:

…if you write$$a[1] then the parser needs to know if you meant to use $a[1] as a variable, or if you wanted $$a as the variable and then the [1] index from that variable.

PHP has a simple way of dealing with this.

The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second.

So if you have an object with a variable property, you can write like this:



PHP Find php.ini and edit configuration settings from command line

Manipulating the PHP ini file from the command line is really quite straight forward.

To get yourself started on the command line, just ask PHP for help like this:

You’ll see a list of options and arguments.

From the php help output one can see that the -i option will show what amounts to the contents of the phpinfo() function.

By piping this output through grep, we can filter for the php.ini file and figure out where the file is.

With this information one can use the -d flag to alter php.ini setting from the command line as well.



Example of Promise.all()

Do you need to iterate over an array of promises? Promise.all() is often the best way.

Promise.all(iterable) returns a single promise.

Promise.all(iterable) only resolves after every promise in an array of promises has completed resolving. Since the elements of the array are promises, they do not resolve in any particular order.

If there is an error in any of the promises in the array of promises, then promise.all will abort and the error will bubble up to the .catch method.

Promise.all example

Often the array of promises pass to promise.all() is built using .map(someCallbackfunction) and results in a new array. The map methon on the original array does not alter the original array. Learn more about the method here.

artDataPromises is a new array containing the promises as a result of the original paintingTitles array being mapped with the getArtData(paintingTitle) function.

getArtData(paintingTitle) is a function that takes each array element as a parameter and returns a promise of the art data related to that painting title.

Promise.all(artDataPromises) does not resolve until all the promises contained in artDataPromises have first resolved.