亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
Solution
What is the difference between Valet and traditional WAMP/LAMP/MAMP environments?
Common problems and solutions that Valet may encounter in actual development
How does Valet support mainstream PHP frameworks and CMS such as Laravel and WordPress?
Home Backend Development PHP Tutorial How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS

How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS

Jul 23, 2025 pm 06:06 PM
mysql laravel git docker composer php environment setup php tutorial 蘋果mac系統(tǒng) apac

The core steps to deploy a PHP site using Valet on macOS are: 1. Install Homebrew; 2. Install Composer; 3. Install Valet globally; 4. Execute the valet install configuration service; 5. Use valet park or valet link to deploy the project. Valet realizes "zero configuration" local PHP site running through Nginx, DnsMasq and PHP FPM, no virtual host settings are required, low resource usage, and simple and efficient operation. Compared with integrated environments such as MAMP and XAMPP, Valet is lighter and focuses on core functions of the Web server. It does not bundle the database and graphical interface, and is suitable for quick switching of multiple projects. Common problems such as service exceptions can be solved through valet restart, PHP version switching supports global settings, and domain name resolution problems can be handled by valet diagnosis or reinstall Valet. Valet has a variety of built-in framework drivers, such as Laravel, WordPress, etc., which automatically recognizes and optimizes configurations to improve development efficiency.

How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS

Valet is undoubtedly the simplest and most efficient tool I have ever used to quickly build a PHP development environment on macOS. It cleverly utilizes Nginx, DnsMasq, and PHP FPM to provide you with extremely low resource usage and a “zero configuration” concept, allowing you to get up and run your local PHP site in an instant, without the need for tedious virtual hosting setup or a massive integration environment.

How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS

Solution

To deploy a PHP site on your Mac using Valet, the core steps are very straightforward. I personally think that it encapsulates all the complex service configurations very well, and you only need a few commands to handle them.

First, make sure that Homebrew is installed on your Mac, which is the cornerstone of package management on macOS. If you haven't installed it yet, run this in the terminal:

How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS
 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After Homebrew is completed, we need Composer and PHP dependency management tools. Valet itself is installed through Composer.

 brew install composer

Next, install the Valet body. Here I usually choose a global installation so that it can be called anywhere:

How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS
 composer global requires laravel/valet

After installing Valet's dependencies, you also need to let Valet "settling down" in your system and configure Nginx and DnsMasq:

 valet install

valet install command does a few things: it installs and configures Nginx, DnsMasq, and sets them as self-start services. DnsMasq is responsible for parsing your local .test domain name (default suffix) to 127.0.0.1 so that you can point to your-project.test by visiting your-project.test . Nginx is responsible for handling HTTP requests.

Now, your Valet environment is built. To deploy a PHP site, you just need to go to your project directory and execute:

 valet park

Or, if you just want a specific directory to be the site root directory, instead of all the subdirectories under the entire parent directory become sites, you can use valet link :

 cd ~/Sites/my-php-project
valet link my-php-project

This way, you can access your project in your browser via http://my-php-project.test . I have built dozens of WordPress sites with it, and the silky feeling is something big guys like MAMP and XAMPP cannot give it.

What is the difference between Valet and traditional WAMP/LAMP/MAMP environments?

To be honest, when I first started to come into contact with Valet, I was also curious about the essential difference between it and old integrated environments such as MAMP and XAMPP. After using it for a while, I found that their design philosophy was completely different.

Tools like MAMP and XAMPP are often "one-stop" solutions. They usually package Apache, MySQL, PHP, phpMyAdmin, etc., and provide a graphical interface for you to start, stop services and configure virtual hosts. This is friendly for beginners as everything is in one bag. But the disadvantages are also obvious: they are usually bloated, resource-intensive, and you may not need all of these components. For example, if you only do PHP development, Apache may appear a bit "heavy", and Nginx is often more efficient in handling static files and concurrent connections.

Valet is taking the "minimalist" route. It does not provide a huge graphical interface and is entirely based on command line operations. It focuses only on web servers (Nginx), DNS resolution (DnsMasq), and PHP runtime environments (PHP FPM). Where is the database? It won't help you install it, you can install MySQL or PostgreSQL separately, or use Docker. This "do only one thing and get it done" philosophy makes Valet extremely lightweight and fast.

More importantly, Valet's "zero configuration" feature. You don't need to manually edit the Nginx configuration file to set up a virtual host for each project. valet park command automatically registers all subdirectories in a directory you specify as accessible sites (for example, ~/Sites/project-a will become project-a.test ). This automated domain name resolution and site service greatly simplifies the management of multi-project development. For me, this means I can switch projects quickly without having to configure them every time.

Common problems and solutions that Valet may encounter in actual development

Although Valet is easy to use, in actual use, you will occasionally encounter some small episodes. Fortunately, it is designed to be relatively robust and most problems have direct solutions.

A more common scenario is that when you update the PHP version or Valet itself, the service may have some minor problems. For example, a site suddenly cannot be accessed, or the PHP version is wrong. At this time, I usually try the simplest "restart method" first:

 valet restart

This command restarts all services managed by Valet (Nginx, DnsMasq, and PHP FPM), and usually solves most temporary configuration or service startup issues.

Another common problem is the PHP version switching. There may be multiple PHP versions installed on your Mac (such as PHP 7.4, 8.0, 8.1, etc.). Valet will use the latest PHP version installed by Homebrew by default. But if your project depends on a specific PHP version, or if you want to switch between different projects, Valet provides very convenient commands:

 valet use php@8.1 # Switch to PHP 8.1
valet use php@7.4 # Switch to PHP 7.4

This will globally switch the PHP version used by Valet. If you want a specific project to use a different PHP version, Valet currently does not have a direct "switch by project" function, but you can consider using more professional PHP version management tools such as phpbrew or asdf , or specifying it through Nginx configuration. However, for most scenarios, global switching is enough.

Sometimes, you may encounter .test domain name resolution failure. This is usually something wrong with DnsMasq. You can try running valet diagnose to check the running status and configuration of Valet. It will give some diagnostic information to help you locate the problem. If the problem persists, try uninstalling and reinstalling Valet:

 valet uninstall
composer global remove laravel/valet
# Make sure to delete the ~/.config/valet directory rm -rf ~/.config/valet
# Then re-execute the installation steps composer global require laravel/valet
valet install

This is almost a "panacea" that solves most difficult problems, as it clears out all old configurations and rebuilds.

How does Valet support mainstream PHP frameworks and CMS such as Laravel and WordPress?

Valet's support for mainstream PHP frameworks and CMS is an important reason why I chose it. It has a variety of "drivers" built-in, which can automatically identify project types and configure them accordingly, which saves a lot of manual adjustments.

When you put a Laravel project in the Valet managed directory (for example through valet park ), Valet will automatically recognize that this is a Laravel application. When you access your-laravel-project.test , Valet intelligently routes the request to the public directory of the Laravel project and starts the Laravel request lifecycle. You don't need to do any extra configuration, like magic.

The same is true for WordPress. Valet has a dedicated WordPress driver. When you put a WordPress installation directory into the valet park directory, Valet can recognize it and correctly handle WordPress URL rewrite rules (such as beautiful permalinks). I often use Valet to quickly build a temporary WordPress development environment and conduct theme or plug-in development testing, which is very efficient.

In addition to Laravel and WordPress, Valet supports many other frameworks and CMS, including Symfony, Zend Framework, Statamic, Jigsaw and more. This out-of-the-box compatibility allows developers to focus on the code itself rather than the environment configuration.

From a performance perspective, Valet performs very well due to its lightweight design. As a web server, Nginx has natural advantages in handling static files and high concurrent requests, while PHP FPM can efficiently manage PHP processes. This all runs locally and has minimal resource usage, which means longer battery life and quieter fans for MacBook users. Personally, I feel that Valet's response speed in local development environments is much faster than those Apache-based integrated environments, especially when running several projects at the same time. It can automatically enable HTTPS (via the valet secure command), which also provides great convenience for local development to simulate HTTPS behavior in the production environment.

The above is the detailed content of How to use Valet to build a PHP environment on Mac Quick PHP site deployment method under MacOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Ethena treasury strategy: the rise of the third empire of stablecoin Ethena treasury strategy: the rise of the third empire of stablecoin Jul 30, 2025 pm 08:12 PM

The real use of battle royale in the dual currency system has not yet happened. Conclusion In August 2023, the MakerDAO ecological lending protocol Spark gave an annualized return of $DAI8%. Then Sun Chi entered in batches, investing a total of 230,000 $stETH, accounting for more than 15% of Spark's deposits, forcing MakerDAO to make an emergency proposal to lower the interest rate to 5%. MakerDAO's original intention was to "subsidize" the usage rate of $DAI, almost becoming Justin Sun's Solo Yield. July 2025, Ethe

There is only one kind of person who makes money in the currency circle There is only one kind of person who makes money in the currency circle Jul 29, 2025 pm 03:24 PM

What can truly make money stably is countercyclical traders with anti-human characteristics. 1. They identify whales in the market FOMO by fighting emotional kidnapping, and capture wrongly killed assets when panic sell-offs; 2. Establish mechanized trading discipline and strictly implement stop-profit and stop-loss rules to fight greed and fear; 3. Use cognitive arbitrage thinking to discover institutional trends and trend opportunities in advance through on-chain data and code updates and other underlying information, and ultimately solidify emotional isolation, data decision-making and countercyclical operations into trading instincts, thereby continuing to make profits in the encrypted market with amplified human nature.

How to build a REST API with Laravel? How to build a REST API with Laravel? Jul 30, 2025 am 03:41 AM

Create a new Laravel project and start the service; 2. Generate the model, migration and controller and run the migration; 3. Define the RESTful route in routes/api.php; 4. Implement the addition, deletion, modification and query method in PostController and return the JSON response; 5. Use Postman or curl to test the API function; 6. Optionally add API authentication through Sanctum; finally obtain a clear structure, complete and extensible LaravelRESTAPI, suitable for practical applications.

What is Eloquent ORM in Laravel? What is Eloquent ORM in Laravel? Jul 29, 2025 am 03:50 AM

EloquentORM is Laravel's built-in object relational mapping system. It operates the database through PHP syntax instead of native SQL, making the code more concise and easy to maintain; 1. Each data table corresponds to a model class, and each record exists as a model instance; 2. Adopt active record mode, and the model instance can be saved or updated by itself; 3. Support batch assignment, and the $fillable attribute needs to be defined in the model to ensure security; 4. Provide strong relationship support, such as one-to-one, one-to-many, many-to-many, etc., and you can access the associated data through method calls; 5. Integrated query constructor, where, orderBy and other methods can be called chained to build queries; 6. Support accessors and modifiers, which can format the number when obtaining or setting attributes.

Using Form Requests for Validation in Laravel. Using Form Requests for Validation in Laravel. Jul 30, 2025 am 05:04 AM

Use FormRequests to extract complex form verification logic from the controller, improving code maintainability and reusability. 1. Creation method: Generate the request class through the Artisan command make:request; 2. Definition rules: Set field verification logic in the rules() method; 3. Controller use: directly receive requests with this class as a parameter, and Laravel automatically verify; 4. Authorization judgment: Control user permissions through the authorize() method; 5. Dynamic adjustment rules: dynamically return different verification rules according to the request content.

How to integrate React with Laravel? How to integrate React with Laravel? Jul 30, 2025 am 04:05 AM

SetupLaravelasanAPIbackendbyinstallingLaravel,configuringthedatabase,creatingAPIroutes,andreturningJSONfromcontrollers,optionallyusingLaravelSanctumforauthentication.2.ChoosebetweenastandaloneReactSPAservedseparatelyorusingInertia.jsfortighterLaravel

Top 10 stablecoin concepts, Top 10 stablecoin rankings in 2025 Top 10 stablecoin concepts, Top 10 stablecoin rankings in 2025 Jul 29, 2025 pm 01:00 PM

The top ten leading stablecoins in 2025 are forecasted as: 1. USDT ranks first with its first-mover advantage and extremely high liquidity; 2. USDC follows closely with high compliance and transparency; 3. DAI, as a decentralized stablecoin, has a solid position in DeFi; 4. FDUSD benefits from Binance's rapid development; 5. PYUSD relies on PayPal ecosystem to have great potential to connect to traditional payments; 6. USDD attracts users through high returns within the Tron ecosystem; 7. TUSD emphasizes transparency through real-time auditing and multi-institutional custody; 8. FRAX innovatively adopts score algorithm mechanism to improve capital efficiency; 9. GUSD is regulated by NYDFS and monthly audits ensure security; 10. USDP as

Securing MySQL with Object-Level Privileges Securing MySQL with Object-Level Privileges Jul 29, 2025 am 01:34 AM

TosecureMySQLeffectively,useobject-levelprivilegestolimituseraccessbasedontheirspecificneeds.Beginbyunderstandingthatobject-levelprivilegesapplytodatabases,tables,orcolumns,offeringfinercontrolthanglobalprivileges.Next,applytheprincipleofleastprivile

See all articles