Tweak Homestead v0.3.3+ or Valet to Work with Craft 2
I use Laravel Homestead for 99% of my development work, mainly Craft, Laravel, and ExpressionEngine. After previously using MAMP, switching to Homestead has been an absolute delight. If you need some convincing, here are a few reasons why you too, may want to consider the switch.
Homestead v0.3.3+ brought with it MySQL 5.7.5 which introduced stricter GROUP_BY functionality. If you care to dig into the details, you can read more about the changes here.
Unfortunately, these changes break Craft 2 sites. Brad Bell addressed the issue in this Stack Exchange question saying that the compatibility issue is completely resolved in upcoming Craft 3, but it doesn’t make sense to backport the fixes down to Craft 2. He presented a workaround, but it wasn’t Homestead-specific, so I figured I would put the directions together in case anyone else runs into the issue.
SSH into your Homestead box using…
ssh firstname.lastname@example.org -p 2222
Edit the my.cnf file found in /etc/mysql/. Use whatever editor you feel comfortable with. I’ll use Vim.
Note: For Laravel Valet, the my.cnf file you want to edit is located at /usr/local/etc/my.cnf
sudo vim /etc/mysql/my.cnf
Add the following to the bottom of my.cnf…
# Set SQL Mode (excluding ONLY_FULL_GROUP_BY)
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
Save those changes and then restart MySQL to activate them!
sudo service mysql restart