


Optimizing the PHP Development Experience on macOS with Homebrew and Valet
Jul 28, 2025 am 04:39 AMFirst install and configure Homebrew, install it through the /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" command, then update the shell configuration file to ensure brew is in PATH, then execute echo 'eval "$(/opt/homebrew/bin/brew shellenv)" >> ~/.zprofile and run eval "$(/opt/homebrew/bin/brew shellenv)", then add the PHP repository brew tap shivammathur/php and brew tap homebrew/services, install the specified PHP version such as brew install Shivammathur/php/php@8.3 and link brew link php@8.3. If necessary, add the PHP path to ~/.zshrc and refresh the configuration. Finally, verify through php -v; then set Laravel Valet, first install Composer, brew install composer, then install Valet globally, composer global require laravel/valet, ensure ~/.composer/vendor/bin is in PATH, then run valet install initialization environment, use valet park to set the project directory such as ~/Sites as an accessible path, or use valet link to create links for a single project to achieve http://project name.test access; to further enhance the environment, brew install mysql and brew services start MySQL runs MySQL, or select MariaDB, and install Redis, execute brew install redis and brew services start redis, add PHP extensions through brew install php@8.3-redis and run valet restart restart restart service. To enable Xdebug, you need to execute valet use php@8.3 --with-extension=xdebug and configure listening port 9003 in the IDE. Optional operations include running valet install --with-trusted-ca trust root certificate, using valet domain .local to replace the default domain name, and enabling HTTPS for the site through valet secure project-name. It is recommended to regularly brew upgrade for daily maintenance. php@8.3 updates PHP, executes valet restart after major changes, uses valet which checks the route, and valet forgets to unlink the project, and ultimately implements a lightweight, efficient local PHP development environment without Docker or Vagrant.
Setting up a smooth PHP development environment on macOS used to be a headache—managing Apache, PHP versions, MySQL, and virtual hosts manually was time-consuming and error-prone. Thanks to Homebrew and Laravel Valet , developers can now get a lightweight, fast, and reliable local PHP stack up and running in minutes. Here's how to optimize your PHP development workflow on macOS using These tools.

Install and Configure Homebrew
Homebrew is the missing package manager for macOS, and it's the foundation of a clean, maintainedable dev setup.
- Install Homebrew (if you haven't already):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Update your shell profile to ensure
brew
is in your PATH (especially on Apple Silicon Macs):
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
- Tap the PHP and other useful repositories :
brew tap shivammathur/php brew tap homebrew/services
- Install PHP (choose your preferred version, eg, 8.3):
brew install shivammathur/php/php@8.3
- Link the PHP version so it's available globally:
brew link php@8.3
Optional: Add PHP to your shell profile if it's not in PATH automatically:
echo 'export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
- Verify installation :
php -v
You now have a modern PHP version managed cleanly via Homebrew.
Set Up Laravel Valet for Local Development
Valet is a minimalistic, Laravel-built development environment that uses Nginx and dnsmasq under the hood. It's fast, uses minimum resources, and supports .test
(or custom) domains automatically.

- Install Valet via Composer :
Make sure Composer is installed:
brew install composer
Then install Valet globally:
composer global requires laravel/valet
Ensure
~/.composer/vendor/bin
is in your PATH:echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
- Install and Launch Valet :
valet install
This configures Nginx, dnsmasq, and starts required services via brew services
.
- Park your projects directory :
Navigate to your projects folder (eg, ~/Sites
) and run:
cd ~/Sites valet park
Now, any folder inside ~/Sites
will be accessible at http://folder-name.test
.
- Serve a single project (alternative to park):
cd ~/Sites/my-project valet link my-project
Now accessible at http://my-project.test
.
Enhance Your Setup with Useful Tools
A great PHP dev environment isn't just about PHP and servers—add these tools to round it out.
- Database: Install MySQL or MariaDB
brew install mysql brew services start mysql
Or use MariaDB:
brew install mariadb brew services start mariadb
- Redis (for caching, queues, etc.)
brew install redis brew services start redis
- PHP Extensions via Homebrew
Valet uses the system PHP, so you can install extensions via:
brew install php@8.3-redis php@8.3-memcached php@8.3-xdebug
Note: After installing extensions, restart Valet:
valet restart
- Xdebug for Debugging
Enable Xdebug with:
valet use php@8.3 --with-extension=xdebug
Then configure your IDE (eg, VS Code, PhpStorm) to listen on port 9003 (default in modern PHP).
Bonus: Custom Domains and SSL
Valet uses HTTPS by default with trusted local certificates.
- Trust the Valet CA globally (optional but helpful):
valet install --with-trusted-ca
- Use a custom domain (eg,
.local
instead of.test
):
valet domain .local
Now your projects are at http://project.local
.
- Secure a site with TLS :
valet secure project-name
This enables HTTPS for that specific parked site.
Final Tips for a Smooth Workflow
- Keep PHP updated:
brew upgrade php@8.3
- Restart Valet after major changes:
valet restart
- Use
valet which
to see which site serves a domain - Run
valet forget
in a project to un-link it
Optimizing PHP development on macOS doesn't require Vagrant or Docker for most use cases. With Homebrew managing your core tools and Valet handling serving and domains, you get a fast, quiet, and powerful local environment that stays out of your way.
Basically: install once, park your code, and go.
The above is the detailed content of Optimizing the PHP Development Experience on macOS with Homebrew and Valet. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WSL2isthenewstandardforseriousPHPdevelopmentonWindows.1.InstallWSL2withUbuntuusingwsl--install,thenupdatewithsudoaptupdate&&sudoaptupgrade-y,keepingprojectsintheLinuxfilesystemforoptimalperformance.2.InstallPHP8.3andComposerviaOnd?ejSury’sPPA

NginxhandlesstaticfilesandroutesdynamicrequeststoPHP-FPM,whichprocessesPHPscriptsviaFastCGI;2.OptimizePHP-FPMbyusingUnixsockets,settingpm=dynamicwithappropriatemax_children,spareservers,andmax_requeststobalanceperformanceandmemory;3.ConfigureNginxwit

It is recommended to use Homebrew to install PHP, run /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" to install Homebrew, and then execute brewinstallphp or a specified version such as brewinstallphp@8.1; after installation, edit the php.ini file in the corresponding path to adjust memory_limit, upload_max_filesize, post_max_size and display_

OPcache and JIT are the core tools for PHP8.0 performance optimization. Correct configuration can significantly improve execution efficiency; 1. Enable OPcache and set opcache.enable=1, opcache.memory_consumption=192, opcache.max_accelerated_files=20000, opcache.validate_timestamps=0 to implement opcode caching and reduce parsing overhead; 2. Configure JIT to enable tracking JIT through opcache.jit_buffer_size=256M and opcache.jit=1254

CompilingPHPfromsourceisnotnecessaryformostprojectsbutprovidesfullcontrolforpeakperformance,minimalbloat,andspecificoptimizations.2.ItinvolvesconvertingPHP’sCsourcecodeintoexecutables,allowingcustomizationlikestrippingunusedextensions,enablingCPU-spe

LaunchanEC2instancewithAmazonLinux,appropriateinstancetype,securesecuritygroup,andkeypair.2.InstallLAMPstackbyupdatingpackages,installingApache,MariaDB,PHP,startingservices,securingMySQL,andtestingPHP.3.DecouplecomponentsbymovingdatabasetoRDS,storing

ChooseaCI/CDplatformlikeGitHubActionsorGitLabCIfortightversioncontrolintegrationandminimalinfrastructure;2.DefineaconsistentPHPenvironmentusingcontainerizationwithimageslikephp:8.2-cliorcomposer:latestandinstalldependenciesviacomposerinstall--no-inte

VerifysystemrequirementsanddependenciesbyconfirmingOScompatibilityandinstallingessentiallibrariesandbuildtools,usingpackagemanagerslikeaptoryumtosimplifydependencymanagement.2.CheckPHPconfigurationandcompilationerrorsbyrunningaminimal./configurecomma
