Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

First of all, I have used both of these development environments, and they are relatively easy to use. Currently, I use Valet, because Valet is more lightweight, out of the box, simple and efficient.

Valet or favored

Laravel offers two local development environments, Homestead and Valet. The difference between Homestead and Valet is the target audience and the approach to local development.

Homestead provides a complete Ubuntu virtual machine with an automated Nginx configuration. If you want a fully virtualized Linux development environment or Windows/Linux, Homestead is a good choice.

Valet is Mac-only and requires you to install PHP and database servers directly on your local machine.

This can be easily done by using Homebrew-related commands such as brew Install php72 and brew Install mysql.

Valet provides an extremely fast, minimal resource consumption local development environment, perfect for developers who only need PHP/MySQL and don’t need a virtual development environment.

Valet and Homestead are excellent choices for configuring a Laravel development environment. Which one to choose depends solely on personal preference and the needs of the team.

My choice

Yes, I used Homestead for Windows development and switched to Valet for Mac development.

Valet profile

Valet is the Laravel development environment for Mac minimalists. Without Vagrant, there is no need to configure the /etc/hosts file. You can even share your site openly using local tunnels.

Laravel Valet sets up your Mac to always run Nginx service in the background after boot. Valet uses DnsMasq to broker all requests to locally installed computer sites to domain names ending in *.test.

A perfect illustration of simplicity and efficiency: an extremely fast Laravel development environment takes up only 7MB of ram.

Valet is not trying to completely replace Vagrant or Homestead, but to provide an alternative that is more flexible, easy to use, and has a smaller footprint.

Valet supports, but is not limited to:

Laravel Lumen Bedrock CakePHP 3 Concrete5 Contao Craft Drupal Jigsaw Joomla Katana Kirby Magento OctoberCMS Sculpin Slim  Statamic Static HTML Symfony WordPress ZendCopy the code

The installation of the Valet

Valet requires macOS and Homebrew. Before installing, make sure that no other programs (such as Apache or Nginx) occupy port 80 on the local machine.

  • Use Brew Update to install or update Homebrew to the latest version.
  • Install PHP 7.3 using Homebrew’s brew install PHP command.
  • Install the Composer.
  • Install Valet using Composer’s Composer global require Laravel /valet command. Ensure that the ~/. Composer /vendor/bin directory is in the “PATH” of the system.
  • Run the valet install command to configure and install Valet and DnsMasq, register the Valet background service, and start automatically with the system running.

After Valet is installed, you can run the ping xxx.test command to ping any *. Test domain name on the terminal. If Valet is installed correctly, you can see the response from 127.0.0.1 on your terminal.

Valet automatically starts its process each time the machine starts. So once Valet initialization is complete, there is no need to run Valet start or Valet Install again.

How to use other domain names

By default, Valet uses the.test top-level domain to serve your project. If you want to use another domain name, you can use valet TLD tlD-name.

For example, if you want to use.xyz instead of.test and run Valet TLD XYZ, Valet will automatically change the site top-level domain name to *.xyz.

The database

If you want to use a database, run brew Install [email protected] on your terminal to install MySQL.

Once installed, you can start MySQL using the brew Services start [email protected] command.

You can then connect to the 127.0.0.1 database using the root username and an empty string password.

Specify the PHP version

Valet allows you to switch PHP versions using the Valet use php@version command.

If the specified version is not already installed, Valet will install the specified PHP version via Brew:

Valet use [email protected] valet use PHPCopy the code

Valet upgrade

Valet can be updated on the terminal using the Composer global update command.

After the upgrade, it is best to run Valet Install again, if necessary, so that Valet can upgrade the configuration file.

Upgrade to Valet 2.0

Valet 2.0 moves Valet’s underlying Web server from Caddy to Nginx.

Before upgrading to this version, you should run the following command to stop and uninstall existing Caddy processes:

valet stop
valet uninstall
Copy the code

Next, upgrade Valet (usually via Git or Composer) depending on your installation.

If Valet is installed using Composer, you should update to the latest major version using the following command:

composer global require laravel/valet
Copy the code

If you update Valet’s source code, you should execute the install command:

valet install
valet restart
Copy the code

After the upgrade, you may need to reset or re-link your site.

Service site

With Valet installed, you can start setting up your site.

Valet provides two commands to service Laravel’s site: Park and Link.

Park command

Run the mkdir ~/Sites command to create a new directory on the Mac.

Next, run CD ~/Sites and Valet Park to use the current working directory as the path to valet’s search site.

Next, create a new Laravel site in this directory, such as Laravel New Blog.

Open blog.test in your browser

Just as simple, any Laravel project created in the “PARKED” directory will be automatically accessed in this way: folder-name.test

The link command

To provide a single site in a directory rather than the entire directory, use the link command.

To use this command, switch to one of your projects in the terminal and run valet Link app-name.

Valet creates a symbolic link in ~/.config/ Valet /Sites to point to the current directory.

After running the link command, you can access the site from your browser in this way: app-name. Test

Run the valet links command to view a list of all directory links. You can also use valet unlink app-name to remove symbolic links.

Note: You can use valet Link to point multiple (sub-) domains to the same application. To add a subdomain or other domain name to an application, run valet Link subdomain-app-name in the application directory.

Secure your site with TLS

By default, the Valet service site is purely HTTP.

However, if you want a site to serve over encrypted TLS using HTTP/2, use the secure command.

For example, if the site is serving the laravel.test domain through Valet, you should run the following command to protect it:

valet secure laravel
Copy the code

To “de-secure” a site and resume serving its traffic over pure HTTP, use the unsecure command.

As with the Secure command, this command accepts the name of the host you wish to unsecure:

valet unsecure laravel
Copy the code

conclusion

Ok, that’s the basic function of Valet, isn’t it very simple and efficient?

These features are enough for our local development, but Valet supports more than these features, including:

Share your site, configure your site’s environment variables, customize Valet drivers, process related operations, and more.

And I’ll sort out some of the more advanced stuff in the next paper.

Related to recommend

At the same time, the wall crack amway this high-quality article, thank you for your support: Git use actual combat: multi-person collaborative development, emergency repair online bug Git operation guide.