/ Code Igniter

Run certain sites with PHP 5.6 on Ubuntu 16.04

I ran into a terrible problem today with one of my webapps.

TLDR: PHP 7 has changes that break certain code that was working on PHP 5.6.

It had something to do with foreach routines. But, I don't quite have the time to debug it so that my codeigniter webapp works with PHP 7.0.

Sense prevailed, and I decide to run this particular webapp using PHP 5.6.

A google search revealed quite a few options and many seemed complicated enough for me to not pursue them!

The following worked great for me and it was really fast to debug and get up an running!

Install PHP 5.6 alongside PHP 7 in Ubuntu 16.04

My Ubuntu 16.04 is configured to use PHP 7 and that is great! Here are the steps to install PHP 5.6 without screwing anything up.

Add Ondřej Surý's PPA:

sudo apt-get install python-software-properties
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

Install PHP 5.6

sudo apt-get update # We need to ***remove*** php5 packages, so we can use php5.6 packages # from the PPA instead sudo apt-get remove php5-common sudo apt-get autoremove # Now we install php5.6 packages. sudo apt-get install php5.6-fpm

Now that should install PHP 5.6!

Configure NGINX to use PHP 5.6

The following PHP handling block worked for me:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
	try_files $uri =404;
	fastcgi_split_path_info ^(.+\.php)(/.+)$;
	fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
}

That should allow this webapp to work using PHP 5.6.

Solve MySQL issues

Before I could grab the beer .. I ran into a terribly MySQL issue. I was repeatedly getting the error: Call to undefined function mysqli_init() from my mysqli driver that was being used by the CodeIgniter code.

I managed to solve it using the following steps:

Enable mysql extension in the PHP5.6 /etc/php/5.6/fpm/php.ini file.

Uncomment following lines (or add them)

extension=php_mysql.dll                                                                                                                              
extension=php_mysqli.dll

Now .... that did not solve it!!

I was still running into the same error. After few hrs of searching, I figure out I need to install few more php5.6 packages!

I added the following that were required by my Code Igniter code! And everything worked!

sudo apt-get install php5.6-mysql php-gettext php5.6-mbstring php-xdebug
sudo apt-get install php5.6-mcrypt

Moral of the story: If there is no problem .. it is likely a version problem! :-)

Credits: