Often you just want to do a quick WordPress setup locally on your Mac for trying something out. I always do a quick local WordPress setup with Valet. Laravel Valet is an application that is created by the developers behind Laravel. It can be used to run all sorts of apps and WordPress is one of them. Thanks to the Evan Mattson’s CLI Valet Command package you can use Valet to create WordPress sites with a single command.
Prerequisites
So what do you need? You need to setup Laravel Valet and for that you need Homebrew (MacOs package manager) including PHP and MariaDB. You also need Composer to install the Laravel Valet package itself.. Let’s go through settings all these up.
Homebrew
So what do you need? You need to setup Laravel Valet and for that you need Homebrew (MacOs package manager). So install Homebrew using:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrew Packages
Then you need to install PHP 7.2 (currently).
brew install homebrew/php/php72
And you also need to install MariaDB
brew install mariadb
Composer & Laravel Valet
Then you can install Laravel Valet with composer. Most of you using Laravel should have it already, but just in case. To install Composer do the following in a directory of your choice
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
Next step is to install the composer package for Laravel Valet
composer global require laravel/valet
WP CLI & WP CLI Valet
You should have WordPress Command Line Interface installed too. You can read about it here. But on top of that you need to install the WP Valet package. This package does all the magic of using the coolness of Laravel Valet and WP CLI. You can do the installation using this wp command:
wp package install git@github.com:aaemnnosttv/wp-cli-valet-command.git
That will get you going.
WordPress Website Installation
Once that is done you can install WordPress using Valet and Bedrock as a setup using:
wp valet new my-project --project=bedrock
Bonus: Local Site Copy
So what if you quickly want to set up an existing website? This so you can make changes for your client? There are many options. You could do a general WordPress Valet setup, replace the database and add the wp-content directory. That would do the trick. You could also do a general Valet WordPress setup and than do a BackupBuddy restore.
To start a new project as a base you simply run:
wp valet new my-project --project=wp
Then inside the newly created directory my-project run
valet link new-project
Using valet links you can check if it was created, but of course also by surfing to https:/my-project.test. You can then login at https://my-project.test/wp-login.php with username admin and password admin.
Local Restore
Now let’s say I want to go the BackupBuddy restore way. How do I proceed? I install the BackupBuddy plugin and import the backup using the backup file and the import file. Issue is that BackupBuddy refuses to run backups or restores due to errors with wp-cron and others.
Error: Error #9038: Loopback test error:cURL error 6: Could not resolve: site.test (Domain name not found)
. URL:https://site.test/wp-admin/admin-ajax.php?action=itbub_http_loop_back_test&serial=96ytxigaj612suq
. If you need to contact your web host, tell them that when PHP tries to connect back to the site at the URLhttps://site.test/wp-admin/admin-ajax.php?action=itbub_http_loop_back_test&serial=96ytxigaj612suq
via curl (or other fallback connection method built into WordPress) that it gets the errorcURL error 6: Could not resolve: site.test (Domain name not found)
. This means that WordPress' built-in simulated cron system cannot function properly, breaking some WordPress features & subsequently some plugins. There may be a problem with the server configuration (eg local DNS problems, mod_security, etc) preventing connections from working properly.
We do have 1024MB as a memory limit already at /usr/local/etc/php/7.3/conf.d/php-memory-limits.ini and we also made execution time 120 instead of 30 at /usr/local/etc/php/7.3/php.ini
But with or without SSL we still got stuck updating via BackupBuddy’s interface. So what you can better do is replace wp-content and import the database as a whole. We imported with WP Database Backup.
WP Database Backup
We did however had to re-create the database and using utf8mb4. Basic WP Valet database setup caused the import to fail and even using different import settings than Greek Windows did not help. Still got stuck at
[ERROR in query 1] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'PK ' at line 1 [ERROR in query 2] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '??4?A?? ??G?ж??O ?????? ? fW??n?,?m??e?x? ? ?
With new database under the same name we could import. Warning shots were fired and a database update was needed by WordPress but things did work in the end. That and with home url and site url changed to work with .test . Of course image would still load remote site images, but for local code tweaks that did not matter.