Install a WordPress development environment with Laravel Valet

Laravel Valet is a development environment for macOS minimalists. It was developed to use in Laravel projects, but in this post, I will explain how to install and use with WordPress.

You need:

Steps

Update brew:

brew update

Install the latest PHP version (currently PHP 8.0):

brew install php@8.0

Install Composer globally:

brew install composer

Make sure that ~/.composer/vendor/bin is in your PATH:

echo $PATH

If you need to add the previous folder to your path, execute:

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.zshrc
source ~/.zshrc

Install Laravel Valet as a global resource:

composer global require laravel/valet

Execute the Valet install command. This command installs nginx and dnsmasq:

valet install

Ping to some .test domain, to check that the configuration is correct:

ping foo.test

Install MySQL 8.0:

brew install mysql@8.0
brew services start mysql
mysql_secure_installation

Create a database for WordPress:

mysql -uroot -p

CREATE DATABASE wordpress CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'wordpress'@'localhost' identified by 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost;
FLUSH PRIVILEGES;
exit

Install the WordPress CLI:

brew install wp-cli

Download and install WordPress:

mkdir -p ~/code/wordpress/wordpress
cd ~/code/wordpress/wordpress
wp core download
wp config create --dbname=wordpress --dbuser=wordpress --dbpass="password" --locale=en_US
wp core install --url="wordpress.test" --title="Test Site" --admin_user=admin --admin_password="password" --admin_email=example@example.com

Start serving the wordpress.test site with this command:

valet link

Secure the new site with:

valet secure wordpress

Now, you can access to the development site at:

https://wordpress.test/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.