Published

Setting up Laravel Valet + MySQL via Homebrew

After far too much delay, I’ve finally ditched MAMP Pro. 🎉

I’m now trying Laravel Valet + MySQL via Homebrew for local PHP development on my MacBook Pro. The notes below are an account of the steps I took for future reference. There were some fiddly points getting started and I expect there to be more, but I’m pretty pleased with the swap overall.


0. Back up databases

The pre-step is to back up any preexisting databases so that you can set them up later if needed. Personally, I use Sequel Pro for all local and some remote database management, so I pulled my necessary exports from there.

1. Install and configure Laravel Valet

The first step is to install Laravel Valet. Their installation docs are pretty much all that is needed. The only caveat is that I’d be a little careful about updating Homebrew or Composer willy nilly, just be wary if you already have it installed and need your preexisting version for any reason. While completing the installation steps, pay attention to the warnings! Complete any recommended steps if you can, they pop up for a reason.

If all went well, at this point you should have an Apache server so you’d be ready to work on a file-based website such as one that uses Kirby CMS or a static site generator (Hugo, Gatsby, Jekyll, etc).

2. Install and configure MySQL with Homebrew

To work on a database-driven site like a Craft CMS or WordPress build, the next step is to install MySQL via Homebrew.

The Laravel Valet docs mention this step, but for me it was nowhere *near* as simple as their two-command recommendation. I think there was likely a conflict with my preexisting MAMP-specific MySQL setup and possibly an old Homebrew installation. I ran the commands from the Valet docs to install MySQL v5.7 and run it, but I would get the error The server requested authentication method unknown to the client [caching_sha2_password] on the front-end. This error indicated that it was actually running MySQL v8 (read more). Sure enough, mysql --version returned mysql Ver 8.0.16 for osx10.14 on x86_64 (Homebrew). To sort it out, I had to reinstall and restart the MySQL service.

To remove MySQL, I followed these instructions. (Be careful with those commands, they remove a lot of stuff.)

After I’d gotten rid of MySQL, I ran the Homebrew commands below to install, link, and start the service.

brew install mysql@5.7
brew link --force mysql@5.7
brew services start mysql@5.7

Note that I tried doing this without the link but consistently ran in to the error Can't connect to local MySQL server through socket '/tmp/mysql.sock' when trying to connect in the next steps. Linking seemed to sort it.

The Homebrew installation command recommended a step involving mysql_secure_installation which sets the root user’s password. We need this for phpMyAdmin and Sequel Pro (coming up below), so I completed this step as well.

3. Set up and / import databases

Once MySQL is set up and running, it’s time to set up your databases. Check out this article for some useful instructions on how to create a user and database on the command line. To import one of your SQL exports from earlier, run mysql -u [username] -p [databasename] < [filename.sql] replacing the bits in brackets with your username, database, and filename. When prompted, enter the password you set up via mysql_secure_installation.

Otherwise, you can do add your database via a UI such as phpMyAdmin (see Laravel Valet-friendly steps) or Sequel Pro.

4. Adjust PHP settings (optional)

I usually adjust my PHP settings (e.g. memory_limit, max_execution_time, post_max_size, etc.) to something that is similar most of my sites’ production hosting environments. Ideally this would be less manual (Docker? Ansible?), but that’s exploration for another day.

I thought that changing the PHP settings would be as simple as adjusting the php.ini file that is specified in the “Loaded Configuration File” value returned by phpinfo(). I edited /usr/local/etc/php/7.2/php.ini and then ran valet restart to restart the server and… it didn’t work. One of my changes was respected according to phpinfo(), but the rest weren’t.

I checked the “Additional .ini files parsed” value and saw that the file /usr/local/etc/php/7.2/conf.d/php-memory-limits.ini was also in use. After I edited this file to include my preferred settings and restarted Valet, all was well.

5. Adjust Nginx config (optional)

Valet’s default Nginx config should normally be sufficient, but you might have to tweak it for certain edge cases.

My edge case was the British Earways site (read more). I was working with it locally and suddenly ran in to a 413 Request Entity Too Large error when attempting to upload a very large audio file. To get around this, I needed to raise the client_max_body_size Nginx directive.

To adjust the Nginx configuration, I first had a look at the main config file by running /usr/local/etc/nginx/nginx.conf. Scanning through that, I saw a few includes:

include "/Users/[username]/.config/valet/Nginx/*";
include servers/*;
include valet/valet.conf;

I had a look at /Users/[username]/.config/valet/Nginx/valet.conf, found client_max_body_size and changed that value to suit my requirements, and then restarted the server by running valet restart.

Other useful things

Run brew services list to find out which services are running. This is useful for troubleshooting if you’re having PHP or mySQL errors.

If you’re adjusting the PHP settings in a .ini file, run valet restart, and then suddenly start seeing only an “It works!” screen where your site should be, you probably have to stop Apache first before restarting Valet. Most guidance online recommends running apachectl stop, but I had trouble with this (see related StackOverflow thread). Instead, I ran valet stop, sudo killall httpd, then valet start. This worked smoothly.

Here’s a list of MySQL commands.

For more info about what $PATH is and why it’s important, see this Unix & Linux Stack Exchange thread or notes on the command line geared towards beginners.

I usually use redirect rules to use media from production when developing locally, for example when working on the WordPress theme that powers this site. Laravel Valet doesn’t seem to play nice with the normal .htaccess method, maybe because it’s actually an Nginx server. See “Proxying images to a remote host on Laravel Valet” for an effective alternative using a local driver.

On an image-heavy project using Craft CMS, I ran in to a 504 error brick wall at one point. Could not for the life of me figure out the problem, even after pouring over the error logs. Ultimately I uninstalled and then reinstalled valet, and that seemed to do the trick.


Edit 10 July 2019 – Added further notes based on working with Laravel Valet the past few days, including the PHP and Nginx config adjustments.

Edit 04 October 2019 – Various small wording adjustments and additional reference links. Used these notes for reference when working with SB to adjust his own setup, and it was clear that some bits could use clarification.

Edit 18 October 2019 – Added note regarding 504 errors.

Published

Richard Hollis’s book on Henry van de Velde, and a note on the index

Spread from book on Henry van de Velde by Richard Hollis

Richard Hollis’s Henry van de Velde: The Artist as Designer is out at long last. A lot of love, sweat, and tears has gone in to that book. It is absolutely jam packed, covering pretty much all of HvdV’s life with over 400 images. As part of Occasional Papers, I worked on the permissions, a bit of editing, and compiled the index.

Read about how the index was compiled

Published

Pub takeaways

Takeaways from a particularly good evening in the pub last night:

And a salad recipe from a great cab driver:

In a large bowl, combine some diced cucumber, diced celery, and halved cherry tomatoes. Add finely chopped wet garlic or green onions (scallions). Toss with olive oil and lemon juice and season to taste. Optional additions include olives, mint, boiled Jersey potatoes, rocket (arugula), or feta. Use apple cider vinegar if you don’t have lemon juice.

Published

Surfing with coffee 3

Surfing w/ coffee #3. Order of exploration, seems more single-track than usual:

A
Open Hacker News, drawn to Frequent versus infrequent developers (in languages and so on) (↓B) (↓C)

B
Is it worth the time? on XKCD; pleased to find this again

C
Hello, I am a DWiki (↓D)

D
Wiki Principles (↓E)

E
Wiki Is Not Wikipedia (↓F)

F
GitHub repo for remodelling wiki as a single page application (↓G)

G
Cunningham & Cunningham Inc., “a small consultancy that has specialized in object-oriented programming” (↓H) (↓I) (↓J)

H
Plate Blading; “As he skates away he feels the need to fabricate further explanation.”

I
C2.COM as Public Space; “Have you ever noticed that some publicly owned museums can be hard to see while privately owned billboards are hard to avoid?”

J
Expense calculator shell script


See previous: surfing 2, surfing 1

Published

Shopify theme dev notes, early 2018

We’re picking up a Shopify site that was put on hold for a little bit, and I’m pleasantly surprised by a few things I’ve come across. The pause might have been blessing in disguise for the site on the whole. The dev tools have progressed a bit during the hiatus, and I’ve come across a Sections workaround that might 🤞 give a little more content flexibility beyond the homepage.

Read more

Published

Surfing with coffee 2

Surfing w/ coffee #2. Order of exploration:

A
Google search “web worker” paper.js jerky (trying to sort out animation+ajax issues) → Paper.js issue #634 “Allow using paperjs without canvas” → Paper.js issue #561 “Add Font and Glyph types from plumin.js” (↓B) → Plumin.js (↓C) → Louis-Rémi Babé @louis_remiSurge, static web publishing

B
Opentype.jsFrederik De Bleser (↓D) → NodeBox, tools for generative design

C
Yannick Mathey @_____________yUSA, limited edition typographic print

D
Overtone, collaborative programmable music → Meta-eX, “Live coding. Live synths. Live music.”

See previous surf sesh.