Laravel Valet is a local development environment for Mac users who want to create WordPress sites quickly and easily. It’s a lightweight, minimalist tool that uses the built-in PHP server and Nginx to serve your WordPress sites.
Unlike other local development tools, such as MAMP, XAMPP, or Local by Flywheel, Laravel Valet does not require you to configure a virtual host, a database, or a port for each site.
Instead, you can simply create a new site in any directory, and link it to a custom domain name (such as .test) with one command. It also provides automatic HTTPS for your sites, so you can test them securely and avoid browser warnings.
Some of the features and benefits of Laravel Valet are:
- Fast and easy installation: You can install Laravel Valet with Composer and Homebrew in only a few minutes. You don’t need to download or install any bulky software or packages.
- Automatic HTTPS: Laravel Valet uses the mkcert utility to generate and trust SSL certificates for your sites. You can access your sites with HTTPS without any configuration or hassle.
- Custom domain names: Laravel Valet allows you to use any domain name (such as .test, .dev, or .local) for your sites. You can link any directory to a domain name with one command, and access it in the browser.
- Multiple PHP versions: Laravel Valet lets you switch between different PHP versions (such as 7.3, 7.4, or 8.0) with just one command. This enables you to test your sites with different PHP versions without affecting other sites or settings.
- Custom drivers: Laravel Valet supports various frameworks and applications, such as WordPress, Laravel, Symfony, Drupal, etc. You can also create your own custom drivers for any application that you want to use with Valet.
Laravel Valet is a great tool for WordPress developers who want to work locally with speed and simplicity. It’s especially useful for developers who work on multiple WordPress sites or projects at the same time.
In this article, we will show you how to use Laravel Valet to set up a local WordPress dev environment in only a few minutes.
Prerequisites
Before you can use Laravel Valet to create and run WordPress sites, you need to have the following requirements:
- A Mac computer: Laravel Valet is only compatible with macOS. You’ll need to have a Mac computer with macOS Sierra (10.12) or higher.
- Port 80 is free: The websites will be served port 80 of your computer. You should make sure that no other programs, such as Apache or Nginx, are binding to your local machine’s port 80.
- Supported PHP Version: Laravel Valet requires PHP 7.3 or higher to work. You can check your PHP version by running php -v in the terminal.
- Composer: Composer is a dependency manager for PHP. You’ll need to have Composer installed on your Mac in order to install Laravel Valet and other tools.
- Homebrew: Homebrew is a package manager for macOS. You’ll need to have Homebrew installed on your Mac to install some of the dependencies of Laravel Valet, such as Nginx and MySQL.
These are the main prerequisites for using Laravel Valet. If you already have them, you can proceed to the next section. If not, you can follow the links provided to install them on your Mac.
Installing Laravel Valet
To install Laravel Valet on your Mac, you need to follow these steps:
- Open the terminal and run the following command to install Laravel Valet using Composer:
composer global require laravel/valet
- Run the following command to install and start Valet:
valet install
- This command will install Nginx and Dnsmasq using Homebrew, and configure your Mac to use Valet’s drivers. It will also register Valet’s daemon to launch when your system starts.
- By default, Valet will use the
.test
domain for your sites. If you want to use a different domain, such as.dev
or.local
, you can run the following command:
valet domain <tld-name>
For example, if you’d like to use .app
instead of .test
, run valet domain app
and Valet will start serving your projects at *.app
automatically.
- To check if Valet is running properly, you can run the following command:
valet status
- This command will show you the status of Valet’s services, such as Nginx, Dnsmasq, and PHP. You should see something like this:
Valet services are running:
[OK] Nginx is running
[OK] Dnsmasq is running
[OK] PHP 7.4 is running
- If you see any errors or warnings, you can run the following command to restart Valet:
valet restart
That’s it! You have successfully installed Laravel Valet on your Mac. You are now ready to create and run WordPress sites with Valet.
Installing WordPress
To create a new WordPress site using Laravel Valet, you need to follow these steps:
- Choose a directory where you want to store your WordPress site. For example, you can create a directory called wordpress in your Sites folder:
cd ~/Sites
mkdir wordpress
- Go to the directory and install WordPress using WP-CLI or Composer. You can use either of them to download and install WordPress core files and dependencies. For example, you can use WP-CLI to install WordPress with the following command:
wp core download
- Alternatively, you can use Composer to install WordPress with the following command:
composer create-project roots/wordpress
- Both commands will create a wp-config.php file in your directory. You can edit this file to configure your database settings and other options. You can also use WP-CLI or Composer to install plugins, themes, and other components for your WordPress site.
- Use Valet to link your site directory to a custom domain name. For example, if you want to use wordpress.test as your domain name, you can run the following command:
valet link wordpress
valet open
- This command will create a symbolic link between your site directory and the .test domain. You can also use a different domain name if you want.
- Access your site in the browser. You can now visit your site by typing wordpress.test in the browser. You should see the WordPress installation screen where you can enter your site title, username, password, and email address. After completing the installation, you can log in to your WordPress dashboard and start building your site.
- Use Valet to secure your site with HTTPS. If you want to use HTTPS for your site, you can run the following command:
valet secure wordpress
- This command will generate and trust an SSL certificate for your site using the mkcert utility. You can then access your site with HTTPS by typing https://wordpress.test in the browser. You should see a green lock icon in the address bar indicating that your site is secure.
You have successfully created a new WordPress site using Laravel Valet. You can now enjoy the benefits of a fast and easy local development environment for WordPress.
Troubleshoot Common Issues
If you encounter any problems with Valet or WordPress, you can try some of the following solutions:
- Restart Valet by running valet restart.
- Check the status of Valet by running valet status.
- Check the logs of Valet by running valet logs.
- Check the configuration of Valet by running valet config.
- Unlink and relink your site by running valet unlink wordpress and valet link wordpress.
- Unsecure and resecure your site by running valet unsecure wordpress and valet secure wordpress.
- Update Valet by running composer global update.
- Update WordPress by running wp core update or composer update.
Final Thoughts
In this article, we have covered how to use Laravel Valet to set up a local WordPress dev environment in minutes. Laravel Valet is a great tool for WordPress developers who want to work locally with speed and simplicity. It’s especially useful for developers who work on multiple WordPress sites or projects at the same time.
You can start using Laravel Valet to keep your site directories organized and consistent, such as using a naming convention or a folder structure to group your sites by type, client, or status. For example, you can use clientname-projectname.test as your domain name, or create a clients folder to store all your client sites. For more information and documentation on Laravel Valet, you can visit the official documentation.
Another quick and easy way to set up a testing environment is by creating a staging site on RunCloud. RunCloud lets you focus on your product and takes care of server management. You don’t need to be a Linux expert to host a successful website, start using RunCloud today and see for yourself.