Run certain sites with PHP 5.6 on Ubuntu 16.04

. 2 min read

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:


Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube