How to Set Up a Local WordPress Environment Like a Pro with Valet, WP-CLI, and MySQL

If you're a developer or enthusiast looking to quickly spin up a local WordPress environment on your machine, you're in the right place! In this article, we’ll show you how to set up WordPress locally with just a few simple terminal commands using Valet, WP-CLI, and MySQL. This approach will streamline your workflow and help you get started with minimal effort, so you can focus on development instead of spending time on setup. Prerequisites Before we begin, here’s what you'll need installed on your machine: Valet – A fast and simple local development environment for macOS, providing a minimalistic approach to hosting websites. WP-CLI – A powerful command-line interface for managing WordPress installations and workflows. MySQL – WordPress relies on a database, and MySQL will handle that. We’ll walk through installing MySQL as part of this guide. Once you’ve installed these tools, you’ll be ready to create a local WordPress site in no time. Step 1: Install Valet Valet is a tool for macOS that configures your system to serve websites locally, using a minimal amount of resources. It simplifies the process of creating a local development environment and removes the need for a full-fledged stack like MAMP or XAMPP. To install Valet, open your terminal and run: composer global require laravel/valet Once installed, you can start the Valet service by running: valet install This will set up Valet to serve your sites in the background. Step 2: Install WP-CLI WP-CLI is an amazing tool that allows you to manage your WordPress sites entirely from the command line. From downloading WordPress to managing plugins and themes, WP-CLI makes WordPress development faster and more efficient. You can install WP-CLI by following these steps (make sure you have PHP installed): curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp After installation, you can verify WP-CLI is working by running: wp --info Step 3: Install MySQL MySQL is essential for running WordPress, as it provides the database functionality for storing your website’s data. Here's how to install MySQL on your system. Installing MySQL Using Homebrew (macOS) Install Homebrew (if you haven't already): Open the terminal and run the following command to install Homebrew (skip if already installed): /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Install MySQL: Once Homebrew is installed, you can install MySQL by running the following command: brew install mysql Start MySQL: After installation, start the MySQL service using the following command: brew services start mysql Secure MySQL Installation: To set up a root password and secure your MySQL installation, run: mysql_secure_installation Follow the prompts to set a root password and configure other security settings. Verify MySQL Installation: To verify that MySQL is properly installed and running, type: mysql --version This should display the MySQL version. Step 4: Create a Database for WordPress Log in to MySQL: To create a new database for WordPress, log in to MySQL: mysql -u root -p Enter your root password when prompted. Create a Database for WordPress: Once you're logged in to MySQL, create a new database for WordPress by running: CREATE DATABASE your_wp_database_name; Replace your_wp_database_name with the name you'd like to use for your WordPress database. Exit MySQL: Once the database is created, exit MySQL by running: EXIT; Step 5: Set Up Your WordPress Site Now that you have Valet, WP-CLI, and MySQL installed, you’re ready to create your WordPress site. Follow these steps: Create a Directory for Your WordPress Site: In your terminal, run the following command to create a new directory and navigate into it: mkdir your-wp-site && cd your-wp-site Replace your-wp-site with your desired site name. Download the WordPress Core Files: Use WP-CLI to download the latest version of WordPress: wp core download This will download all the necessary WordPress files into your site directory. Step 6: Link and Secure Your Site with Valet Valet makes linking your site and adding SSL a breeze. Link the Site to Valet: Run the following command to link the site to Valet: valet link This will create a .test domain for your site. For example, if you named your directory your-wp-site, you can access your site at: http://your-wp-site.test Secure the Site with SSL: To enable SSL for your site (to make it accessible via HTTPS), run: valet secure This command will generate an SSL certificate for your site. You’ll be able to access it at: ht

Apr 19, 2025 - 16:09
 0
How to Set Up a Local WordPress Environment Like a Pro with Valet, WP-CLI, and MySQL

If you're a developer or enthusiast looking to quickly spin up a local WordPress environment on your machine, you're in the right place! In this article, we’ll show you how to set up WordPress locally with just a few simple terminal commands using Valet, WP-CLI, and MySQL. This approach will streamline your workflow and help you get started with minimal effort, so you can focus on development instead of spending time on setup.

Prerequisites

Before we begin, here’s what you'll need installed on your machine:

  1. Valet – A fast and simple local development environment for macOS, providing a minimalistic approach to hosting websites.
  2. WP-CLI – A powerful command-line interface for managing WordPress installations and workflows.
  3. MySQL – WordPress relies on a database, and MySQL will handle that. We’ll walk through installing MySQL as part of this guide.

Once you’ve installed these tools, you’ll be ready to create a local WordPress site in no time.

Step 1: Install Valet

Valet is a tool for macOS that configures your system to serve websites locally, using a minimal amount of resources. It simplifies the process of creating a local development environment and removes the need for a full-fledged stack like MAMP or XAMPP.

To install Valet, open your terminal and run:

composer global require laravel/valet

Once installed, you can start the Valet service by running:

valet install

This will set up Valet to serve your sites in the background.

Step 2: Install WP-CLI

WP-CLI is an amazing tool that allows you to manage your WordPress sites entirely from the command line. From downloading WordPress to managing plugins and themes, WP-CLI makes WordPress development faster and more efficient.

You can install WP-CLI by following these steps (make sure you have PHP installed):

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

After installation, you can verify WP-CLI is working by running:

wp --info

Step 3: Install MySQL

MySQL is essential for running WordPress, as it provides the database functionality for storing your website’s data. Here's how to install MySQL on your system.

Installing MySQL Using Homebrew (macOS)

  1. Install Homebrew (if you haven't already):

Open the terminal and run the following command to install Homebrew (skip if already installed):

   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install MySQL:

Once Homebrew is installed, you can install MySQL by running the following command:

   brew install mysql
  1. Start MySQL:

After installation, start the MySQL service using the following command:

   brew services start mysql
  1. Secure MySQL Installation:

To set up a root password and secure your MySQL installation, run:

   mysql_secure_installation

Follow the prompts to set a root password and configure other security settings.

  1. Verify MySQL Installation:

To verify that MySQL is properly installed and running, type:

   mysql --version

This should display the MySQL version.

Step 4: Create a Database for WordPress

  1. Log in to MySQL:

To create a new database for WordPress, log in to MySQL:

   mysql -u root -p

Enter your root password when prompted.

  1. Create a Database for WordPress:

Once you're logged in to MySQL, create a new database for WordPress by running:

   CREATE DATABASE your_wp_database_name;

Replace your_wp_database_name with the name you'd like to use for your WordPress database.

  1. Exit MySQL:

Once the database is created, exit MySQL by running:

   EXIT;

Step 5: Set Up Your WordPress Site

Now that you have Valet, WP-CLI, and MySQL installed, you’re ready to create your WordPress site. Follow these steps:

  1. Create a Directory for Your WordPress Site:

In your terminal, run the following command to create a new directory and navigate into it:

   mkdir your-wp-site && cd your-wp-site

Replace your-wp-site with your desired site name.

  1. Download the WordPress Core Files:

Use WP-CLI to download the latest version of WordPress:

   wp core download

This will download all the necessary WordPress files into your site directory.

Step 6: Link and Secure Your Site with Valet

Valet makes linking your site and adding SSL a breeze.

  1. Link the Site to Valet:

Run the following command to link the site to Valet:

   valet link

This will create a .test domain for your site. For example, if you named your directory your-wp-site, you can access your site at:

   http://your-wp-site.test
  1. Secure the Site with SSL:

To enable SSL for your site (to make it accessible via HTTPS), run:

   valet secure

This command will generate an SSL certificate for your site. You’ll be able to access it at:

   https://your-wp-site.test

Step 7: Final WordPress Installation

At this point, your WordPress site is ready to go! You can now navigate to the URL (e.g., https://your-wp-site.test) in your browser to complete the WordPress installation process.

  1. Enter Database Information:

During the WordPress setup, you’ll be prompted to enter the database details. Use the following information:

  • Database Name: your_wp_database_name (the name you gave your database in MySQL)
  • Username: root (default for MySQL)
  • Password: Leave it blank (unless you set a password for MySQL root)
  1. Complete the WordPress Setup:

After filling in the database details, continue with the WordPress setup to configure your site’s title, admin username, and password.

Recap

In just a few simple steps, you’ve:

  1. Installed Valet, WP-CLI, and MySQL.
  2. Created a MySQL database for your WordPress site.
  3. Downloaded and set up WordPress using WP-CLI.
  4. Linked and secured your site with Valet.

This streamlined approach makes it easy to get a local WordPress environment up and running with minimal effort, leaving you with more time to focus on development.

Enjoy building your WordPress projects like a pro!