DEV Community

Ngobrolin IT
Ngobrolin IT

Posted on

WordPress Local Development Mac OS Using Valet

Hello, dev.. πŸ‘‹

In this tutorial, I will share how to use Valet for local WordPress development. Well, maybe WordPress friends are a little unfamiliar with Valet, but Laravel friends are probably very familiar and often use it.

What is Valet?

OK, so Valet is a tool for creating a local development environment used on the Mac OS operating system. So, the way Valet works is that it will configure our project root folder using Nginx which works in the background, and then Valet uses DnsMasq to direct all requests using the *.test domain to the website that is activated on the Nginx server.

Valet itself was created by the Laravel development team, you can read the documentation here. They claim that Valet is very light, only using 7 MB of RAM. Even though this tool was created by Laravel developers, it turns out that Valet also supports WordPress development.

How to Install Valet

This valet can only be used on Mac OS, so what you need is Mac OS and homebrew installed on Mac OS.

So, before installing valet, you must first update your homebrew

brew update
Enter fullscreen mode Exit fullscreen mode

The first thing you need is to install Composer, you can install it directly from getcomposer.org or you can also install Composer from homebrew

brew install composer
Enter fullscreen mode Exit fullscreen mode

Now, after installing Composer, what you need to install is the latest PHP using homebrew.

Then install Valet using Composer by running the following command

composer global require laravel/valet
Enter fullscreen mode Exit fullscreen mode

Once successful, you can use the valet command in your terminal command line

Create Site

To create a new site, first go to the project folder then run the command

cd myprojectapp
valet link
Enter fullscreen mode Exit fullscreen mode

Then you can access it using the address myprojectapp.test

Secure HTTPS

Sites created using valet can also be accessed via https. Go to the project folder and run the following command

valet secure
Enter fullscreen mode Exit fullscreen mode

Case Study Example

The following is an example of a case study, we create a wordpress folder, we download the WordPress core using WP CLI, then we create a site using Valet and finally, we create the site so that it can be accessed using https.

Last login: Sat Jul  8 10:19:01 on ttys000
You have new mail.
➜  ~ cd Sites
➜  Sites mkdir wordpress
➜  Sites cd wordpress
➜  wordpress wp core download
Downloading WordPress 6.2.2 (en_US)...
Using cached file '/Users/dhimaskirana/.wp-cli/cache/core/wordpress-6.2.2-en_US.tar.gz'...
Success: WordPress downloaded.
➜  wordpress valet link
Password:
A [wordpress] symbolic link has been created in [/Users/dhimaskirana/.config/valet/Sites/wordpress].
➜  wordpress valet secure
Restarting nginx...
The [wordpress.test] site has been secured with a fresh TLS certificate.
➜  wordpress 
Enter fullscreen mode Exit fullscreen mode

Good luck 🍻

Top comments (0)