Home > Article > PHP Framework > Laravel development: How to configure a local development environment using Laravel Valet?
Laravel is a popular PHP framework that provides developers with powerful tools and features. If you want to use Laravel for local development, then you need to use a local development environment. In this article, we will describe how to configure a local development environment using Laravel Valet.
Laravel Valet is a local development environment tool for Mac users that makes configuring your development environment quick and easy. Valet uses Nginx as a web server and also provides other features such as MySQL, PHP, Redis, Mongodb, etc.
First, you need to make sure Homebrew is installed on your Mac. Open a terminal and run the following command to check whether Homebrew is installed:
brew --version
If the version of Homebrew is returned, it means it has been installed successfully.
Next, we need to install Valet. Run the following command in the terminal:
composer global require laravel/valet
The above command will install Valet globally. After the installation is complete, run the following command to initialize:
valet install
During the initialization process, Valet will install the necessary software packages and set Nginx as the default web server.
After the installation is complete, you need to set Valet to start automatically. Run the following command in the terminal:
valet trust
This command will install Integer SSL and set it as a trusted local development certificate.
Next, let’s create a new project and set it up to use Valet. Assume your project path is /Users/yourname/Projects/my-app
. Run the following command in this directory:
cd /Users/yourname/Projects/my-app valet link
The above command sets Valet as the local development environment for this project. Now you can view your application by typing http://my-app.test
in your browser.
If you want to use MySQL as the database, please make sure you have installed MySQL before using Valet and start MySQL using the following command:
brew services start mysql
Now, you can do this in .env
Specify the connection to the MySQL database in the file. Here is an example:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=my_database DB_USERNAME=root DB_PASSWORD=
Finally, if you are no longer using Valet, you can use the following command to remove Valet and return to the default web server.
valet uninstall
Using Valet when developing locally can provide a convenient development experience, allowing you to build Laravel applications faster. I hope this article will be helpful to you, and I hope you can develop your applications smoothly when using Valet!
The above is the detailed content of Laravel development: How to configure a local development environment using Laravel Valet?. For more information, please follow other related articles on the PHP Chinese website!