Make MySQL 5.7+ behave like MySQL 5.6

You've upgraded your environment to MySQL 5.7 and everything is broken.

MySQL 5.7 includes a number of changes to the sql mode which are talked about here:

The old defaults can be set via the sql_mode property on a per-query basis or server wide via the my.cnf file.

To apply the old defaults:

  • Open your my.cnf (usually found at /etc/mysql/my.cnf )
  • Add a line under [mysqld] section. sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION
  • Close your file and restart mysql.


Thanks to Ian and Logan from Austin PHP for this solution.

Working with Legacy PHP

I support a legacy application and have recently begun making modifications to this code base. Creating a dev environment for older php can be a beast. This wouldn’t have been possible without vagrant. Here are some tricks I discovered while setting up my php 5.2 dev environment in 2016.

Did someone already do this?

I found

In my case, I don’t want the entire environment inside vagrant and had trouble with some of the configuration decisions of these boxes.

They were really specific to testing wordpress.

Configure Vagrant

Mine is based on bento/centos-5.11

It was the most popular centos 5.x box at the time.

This image doesn’t have apache or php installed by default.

Edit the Vagrantfile and enabled the local networking.

This gives you a consistant ip address each time you start your dev environment. “private_network”, ip: “”

Increase the memory alloted to vagrant box. Look for this near the end of a “standard” vagrant file.

  config.vm.provider “virtualbox” do |vb|

# Display the VirtualBox GUI when booting the machine

vb.gui = false

# Customize the amount of memory on the VM:

vb.memory = “1024”


I added a line to start apache after the box finishes starting up. ( This is at the end of a “standard” vagrant file. )

In my setup. The apache config for my virtual host is a part of the applications code repository.

This caused problems because apache was failing to start because vagrant hadn’t mounted my shared folder yet.

config.vm.provision “shell”, inline: <<-SHELL

sudo /etc/init.d/httpd start


Installing php 5.2 in 2016

Your options are find rpms or compile from source. I tried the ‘compile from source’ route and it didn’t go so well.

There are a number of libraries that php depends on that have been updated and are no longer compatible.

hense the php52-backports project. I was able to compile but had trouble building an apache module.

It was much easier to find RPMS.

I used iworx-unsupported repo. It was referenced in many spots and was only missing one plugin I needed.


name=IWorx Unsupported



/etc/yum.repos.d/iworx-unsupported.repo (END)

It does not have an xdebug module so I had to install that via the pecl repository.

yum install php.x86_64 php-cli php-soap php-devel php-mysql php-pdo php-mcrypt php-mysqli php-pear php-gd php-devel gcc gcc-c++ autoconf automake unzip zip

Can’t mount folders in vagrant after yum update

Running yum update will probably break your box’s ability to mount shared folders.

To fix; you’ll need to rebuild virtualbox’s guest additions.

sudo /etc/init.d/vboxadd setup

Installing old xdebug

Version 2.2.7 is the last version which supported php 5.2

If you use pecl to install and build the module, you’ll get the latest release which doesn’t support php 5.2.

We’ll have to compile this module manually.

You will need to install gcc, gcc-c++, autoconf automake php-devel and php-pear.

mkdir /opt/xdebug

cd /opt/xdebug

wget –no-check-certificate

tar -z -x -f ./xdebug-2.2.7.tgz

cd ./xdebug-2.2.7


./configure –enable-xdebug


make install

My xdebug config looks like this:



xdebug.remote_enable = 1

; default for vagrant

xdebug.remote_host =

Since we configured a static address earlier, we can now use that address with xdebug.

I was so happy the first time phpStorm started a debug session with this app. Screaming and clapping.

Connecting to local MySQL

I’m used to using my local mysql instance for development. Having it virtual box with all the constrants of virtualbox is awkward.

I wanted to connect my virtual box guest to a mysql server running on the host.

If are ok with mysql running on all your ip addresses, then you can just use the same address you used for xdebug. Edit the /etc/my.cnf to allow connections from and you’re set. In my case, mysql only runs on localhost.

We can still connect it to the guest via a ssh proxy.

vagrant ssh — -R 3306:localhost:3306

As long as the command prompt is open, your guest will be able to use the proxy.

I think that covers all the gotchas encountered while trying to configure my dev environment for old php.

PHP 5.2 has been unsupported since Jan. 2011, but a dev environment is the first step to modernizing this app. From a breif test on php 7, I’ll have plenty of work to do for years to come.


Error: Cask ‘vagrant’ definition is invalid: Bad header line: parse failed

You need to update vagrant to get some work done and trying to use brew to install vagrant is failing with an error message of "Error: Cask 'vagrant' definition is invalid: Bad header line: parse failed".


You probably haven't updated brew in a really long time. Here's how to get that working again.

brew update; brew cleanup; brew cask cleanup
brew uninstall --force brew-cask; brew update

Thanks to adidalal of the caskroom project for this solution.


mod_mime + php = hacked site.

So I learned something about mod_mime today that made my jaw drop.

The default way of telling apache to parse a php file looks something like this:

AddHandler php5-script .php

If you install php via the command line on RHEL 4,5 or 6, this is how it sets it up.

What I didn't know is that mod_mime expands the match (.php) to anywhere in the file name.
So test.php or test.php.csv or test.php.jpg would all be passed to the php handler to be executed.


That's a big deal when your application accepts file uploads and is only type-checking the last file extension.
Magento, expression engine, wordpress, etc…

The workaround is to only apply the php handler to files which end in ".php"

<FilesMatch \.php$>
    SetHandler php5-script

And for a little extra 'security', disable php for a directory if you're accepting uploads.

<Directory "/var/www/html/example/uploads">
    php_flag engine off

Which I'm going to go back and change on any server I've ever setup.
I learned this tid-bit from a security advisory from magento.

UPDATE: You may also see a lot of folks who recommend turning on "open_basedir" in php to lock thinks down.
There is a cavet there too. When "open_basdir" is in use, php disables the realpathcache. 
This makes loading/including files very slow.