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

目錄
Install and Configure Homebrew
Set Up Laravel Valet for Local Development
Enhance Your Setup with Useful Tools
Bonus: Custom Domains and SSL
Final Tips for a Smooth Workflow
首頁 后端開發(fā) php教程 用自制和代客優(yōu)化MACOS上的PHP開發(fā)體驗

用自制和代客優(yōu)化MACOS上的PHP開發(fā)體驗

Jul 28, 2025 am 04:39 AM
PHP Installation

首先安裝并配置Homebrew,通過/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"命令安裝,隨后更新shell配置文件確保brew在PATH中,接著執(zhí)行echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile并運行eval "$(/opt/homebrew/bin/brew shellenv)",然后添加PHP倉庫brew tap shivammathur/php和brew tap homebrew/services,安裝指定PHP版本如brew install shivammathur/php/php@8.3并鏈接brew link php@8.3,必要時將PHP路徑加入~/.zshrc并刷新配置,最后通過php -v驗證;接著設置Laravel Valet,先安裝Composer即brew install composer,再全局安裝Valet即composer global require laravel/valet,確保~/.composer/vendor/bin在PATH中,然后運行valet install初始化環(huán)境,使用valet park將項目目錄如~/Sites設為可訪問路徑,或用valet link為單個項目創(chuàng)建鏈接,實現(xiàn)http://項目名.test訪問;為進一步增強環(huán)境,可通過brew install mysql和brew services start mysql運行MySQL,或選擇MariaDB,安裝Redis則執(zhí)行brew install redis和brew services start redis,通過brew install php@8.3-redis等命令添加PHP擴展并運行valet restart重啟服務,啟用Xdebug需執(zhí)行valet use php@8.3 --with-extension=xdebug并在IDE中配置監(jiān)聽端口9003,可選操作包括運行valet install --with-trusted-ca信任根證書、使用valet domain .local更換默認域名、通過valet secure project-name為站點啟用HTTPS,日常維護建議定期brew upgrade php@8.3更新PHP、重大變更后執(zhí)行valet restart、使用valet which檢查路由、valet forget解除項目鏈接,最終實現(xiàn)一個輕量、高效、無需Docker或Vagrant的本地PHP開發(fā)環(huán)境。

Optimizing the PHP Development Experience on macOS with Homebrew and Valet

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.

Optimizing the PHP Development Experience on macOS with Homebrew and Valet

Install and Configure Homebrew

Homebrew is the missing package manager for macOS, and it’s the foundation of a clean, maintainable dev setup.

  1. Install Homebrew (if you haven’t already):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. 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)"
  1. Tap the PHP and other useful repositories:
brew tap shivammathur/php
brew tap homebrew/services
  1. Install PHP (choose your preferred version, e.g., 8.3):
brew install shivammathur/php/php@8.3
  1. 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:

Optimizing the PHP Development Experience on macOS with Homebrew and Valet
echo 'export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
  1. 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 minimal resources, and supports .test (or custom) domains automatically.

Optimizing the PHP Development Experience on macOS with Homebrew and Valet
  1. Install Valet via Composer:

Make sure Composer is installed:

brew install composer

Then install Valet globally:

composer global require laravel/valet

Ensure ~/.composer/vendor/bin is in your PATH:

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
  1. Install and Launch Valet:
valet install

This configures Nginx, dnsmasq, and starts required services via brew services.

  1. Park your projects directory:

Navigate to your projects folder (e.g., ~/Sites) and run:

cd ~/Sites
valet park

Now, any folder inside ~/Sites will be accessible at http://folder-name.test.

  1. Serve a single project (alternative to parking):
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 (e.g., 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 (e.g., .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.

以上是用自制和代客優(yōu)化MACOS上的PHP開發(fā)體驗的詳細內(nèi)容。更多信息請關注PHP中文網(wǎng)其他相關文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72
利用WSL 2的力量來實現(xiàn)Linux-intagity PHP開發(fā)工作流程 利用WSL 2的力量來實現(xiàn)Linux-intagity PHP開發(fā)工作流程 Jul 26, 2025 am 09:40 AM

wsl2isthenewstanceforseriousphpdevelopmentonwindows.1.installwsl2withubuntuingusingwsl-install,thenupdatewithsudoaptupdat E && sudoaptupgrade-y,keepprojectsinthelinuxfilesystemforoptimalperformance.2.installphp8.3andComposerviaondEjsurysppa

掌握PHP-FPM和NGINX:高性能設置指南 掌握PHP-FPM和NGINX:高性能設置指南 Jul 25, 2025 am 05:48 AM

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

在MacOS上設置PHP 在MacOS上設置PHP Jul 17, 2025 am 04:15 AM

推薦使用Homebrew安裝PHP,運行/bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"安裝Homebrew,再執(zhí)行brewinstallphp或指定版本如brewinstallphp@8.1;安裝后編輯對應路徑的php.ini文件調(diào)整memory_limit、upload_max_filesize、post_max_size和display_

解鎖峰值PHP性能:配置OPCACHE和JIT編譯 解鎖峰值PHP性能:配置OPCACHE和JIT編譯 Jul 24, 2025 pm 09:58 PM

OPcache和JIT是PHP8.0 性能優(yōu)化的核心工具,正確配置可顯著提升執(zhí)行效率;1.啟用OPcache并設置opcache.enable=1、opcache.memory_consumption=192、opcache.max_accelerated_files=20000、opcache.validate_timestamps=0以實現(xiàn)opcode緩存并減少解析開銷;2.配置JIT通過opcache.jit_buffer_size=256M和opcache.jit=1254啟用追蹤JIT

揭開PHP匯編的神秘面紗:從源構(gòu)建自定義PHP以獲得最佳性能 揭開PHP匯編的神秘面紗:從源構(gòu)建自定義PHP以獲得最佳性能 Jul 25, 2025 am 06:59 AM

匯編phomerceisnotn coresemencomeformostprojectsbutprovidesfuidsfuidsfudsfiidesfulstrolcontrolforperperance,minimalbloat,andspecificoptimization.2.itinvolvesConvertingPhpphpphp'scsourcececececececeodeintoIntoExecutables,允許customizationLikizationLikeStripingunusedunsuptipingunseftimpipingunseftimpippingunsippingsextensenions enablingCpuspucpu

從頭開始在AWS EC2上部署可擴展的PHP環(huán)境 從頭開始在AWS EC2上部署可擴展的PHP環(huán)境 Jul 26, 2025 am 09:52 AM

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

自動化PHP環(huán)境設置:將PHP集成到CI/CD管道中 自動化PHP環(huán)境設置:將PHP集成到CI/CD管道中 Jul 26, 2025 am 09:53 AM

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

故障排除常見的PHP安裝陷阱:診斷清單 故障排除常見的PHP安裝陷阱:診斷清單 Jul 26, 2025 am 09:50 AM

verifySystemRequirements and dipendenciesbyConfirmingoScompatiby andInstallingSenlingEssentialLibrariesandBuildTools,使用PackageManagerSlikeSlikeAptoryUmTosImplifyDependentyDependentymanagement.2.Checkphpphpphpphpphpphpphpconfigurationand and conconfigurationAndCompConfigurationAndCompilationErrateRrationRuntirNumentByRunningMinimal./confictecomma

See all articles