I’m a Mac user, and I enjoy the sheer simplicity (and speed) of Laravel Valet for all of my local-development needs. I use it for Laravel projects, Symfony projects, pure-PHP ones, and also most WordPress development.
Here’s a quick summary of what I just had to do to get Writers.com working locally using Laravel Valet. Because of an outdated plugin, I needed to use an older version of PHP (PHP 7.4; I’m usually running 8.1 today). Thankfully, using old versions of PHP (for specific folders/projects) in Valet has been possible for a while thanks to the isolate
command.
But I was a little rusty at readying a WordPress site for local development using the command-line. And because I needed to use the valet isolate
command, I also needed a slightly-strange CLI incantation for using the right PHP version when WP-CLI loaded up my WordPress site. In case I ever need it again, or someone else does, I thought I’d write a quick little guide of how I got a backup of a WordPress site running locally with an older PHP version in Laravel Valet.
Some Quick Notes & Prerequisites
- I’m assuming you’ve already installed and been using both Laravel Valet and WP-CLI. I don’t think installing those is within the scope of this little article. (Both tools have good guides, as do lots of other people 🤓)
- I’ve noted my filenames and paths, but you’ll probably need to change them. In general if it says
writers
below, that’s a signal you’ll probably need to change the command/location to match your system, SQL dump, etc. (Might be obvious…) valet isolate
is awesome, and can also be really useful for non-WordPress projects that aren’t on ANCIENT PHP versions. As long as it can be downloaded from Homebrew, you can reasonably expect to be able to pull it in with avalet isolate php@X.Y
. Per-site PHP versions is such a great feature to have in Valet.
Running WordPress with older PHP on Laravel Valet, step-by-step
Here’s a summary of what I did to get a WordPress site running locally on Laravel Valet with a different version of PHP:
- Grabbed the ZIP download of the latest WordPress site backup from the host (Kinsta, in this case).
- Unzipped the ZIP in my Valet directory. For long-ago reasons, for me that’s
Users/davidbhayes/WebDev
. (Because of the way Kinsta packs their downloads, I had to “pull-up” everything from thepublic
directory to the “root” of the directory. So I ended up with all my classic WordPress files inWebDev/writers
, including the SQL file. - Here’s where I had to change database-connecting credentials in
wp-config.php
. If you’re using the default Valet MySQL setup, yours would be the same as mine. I changed the WordPress database username and password:/** MySQL database username */ define( 'DB_USER', 'root' ); /** MySQL database password */ define( 'DB_PASSWORD', '' );
- Now, you’ll need to move into the project’s directory in the terminal (for me that means opening the project in PhpStorm and using the Terminal there). Importing the database (because I don’t think WP-CLI loads up the whole WordPress site) worked fine with a simple/classic version:
wp db import writerscom.sql
- Then I realized the site was broken because of the outdated WordPress plugin which couldn’t run on modern PHP (8.1 today). So I used Valet’s
isolate
command to make the site use the right (different) version of PHP:valet isolate php@7.4
- Then the classic WordPress database-search-and-replace (so the site really works) didn’t work straightforwardly, because the command seems to load the WordPress site and use your default version of PHP to do so. So you have to be careful and make sure you use the version of PHP you’ve
valet isolate
d to. But to do that while running WP-CLI requires a slightly awkward maneuver: using the full path to your WP-CLI. (You can discover this with a simple:which wp
assuming you’ve got the CLI’s.phar
renamed towp
, as is typical.) Anyway, all of this means that to run the final command I ended up doing my search-and-replace withvalet php /usr/local/bin/wp search-replace https://writers.com http://writers.valet
Hopefully this is helpful to someone (even if just me). PHP has gotten so much faster (both in terms of performance and rate-of-language-change). But using different versions of PHP can still be a sticky problem. But thankfully there’s Valet’s isolate
. Happy WordPressing!