

Mac 下 Homebrew 搭建 PHP 开发环境
source link: https://sevming.github.io/Mac/mac-homebrew-php.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Mac 下 Homebrew 搭建 PHP 开发环境
发表于 2021-07-13
| 分类于 Mac
brew install php
# 启动
brew services start [email protected]
# 重启
brew services restart [email protected]
# 查看安装好的php路径
brew --prefix [email protected]
# 配置 /usr/local/etc/php/7.4/php-fpm.conf
pid = /usr/local/var/run/php74-fpm.pid
error_log = /Users/sev/Development/logs/php74-fpm.log
vim ~/.bash_profile
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
# 注意:source ~/.bash_profile, 关闭窗口后就失效, 配置打开终端就生效
vim ~/.zshrc
# 在文件尾部添加一行
source ~/.bash_profile
redis 扩展
# 下载 Redis 包并解压
phpize
./configure --with-php-config=/usr/local/opt/[email protected]/bin/php-config
make
make install
# /usr/local/etc/php/7.4/conf.d/ext-redis.ini
extension=redis.so
# 查看是否安装
php -m | grep redis
替换默认 PHP
vim ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php7.4.12/bin:$PATH
source ~/.bash_profile
# 替换后,PHP 命令行响应慢(原因:尝试执行 DNS 查找本地计算机的主机名)
# 查看 Mac 名称:系统偏好设置 -> 共享 -> sevdeiMac.local
# 配置 hosts,加入以下两行代码
127.0.0.1 sevdeiMac.local
::1 sevdeiMac.local
Nginx
brew install nginx
# 查看配置是否正常
sudo nginx -t
# 启动
sudo nginx
# 重启
sudo nginx -s reload
配置
/usr/local/etc/nginx/nginx.conf
pid /usr/local/var/run/nginx.pid;
access_log /Users/sev/Development/logs/nginx_access.log;
error_log /Users/sev/Development/logs/nginx_error.log;
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
include /Users/sev/Development/nginx/conf.d/*.conf;
配置 sock 连接 PHP, 方便支持 PHP 多版本
# 配置 /usr/local/etc/nginx/nginx.conf
# 配置用户/组(与 php 运行的用户/组 一致)
user sev staff;
location ~ \.php$ {
root html;
fastcgi_pass /usr/local/var/run/php74-fpm.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 配置 /usr/local/etc/php/7.4/php-fpm.d/www.conf
; listen = 127.0.0.1:9000
listen = /usr/local/var/run/php74-fpm.sock
# 重启 Nginx 和 PHP 服务
Redis
brew install redis
# 启动
brew services start redis
# 通过配置文件启动 nginx
redis-server /usr/local/etc/redis.conf
# 配置 /usr/local/etc/redis.conf
daemonize yes
requirepass 123456
# 开机自启配置
cp /usr/local/Cellar/redis/6.2.4/homebrew.mxcl.redis.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
MySQL
brew install [email protected]
# 启动数据库
brew services start [email protected]
# 默认无密码
vim ~/.bash_profile
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
# 运行
source ~/.bash_profile
# 修改密码
mysql -u root -p
use mysql;
UPDATE user SET authentication_string=password('123456') WHERE user='root';
FLUSH PRIVILEGES;
# 提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
SET GLOBAL validate_password_policy=LOW;
SET GLOBAL validate_password_length=6;
Recommend
-
24
« back — written by Brent on November 26, 2020 Upgrade to PHP 8 with Homebrew on Mac ...
-
8
我所使用的操作系统是 Mac OS X Yosemite,自带 Apache 和 PHP,所以不用安装,只需稍微修改一下配置文件即可。 启动 Apache 打开终端,输入 sudo apachectl start 后即可启动 Apache。访问 http://localhost/ 会看...
-
12
« back — written by Brent on November 28, 2019 Upgrade to PHP 7.4 with Homebrew on Mac ...
-
22
« back — written by Brent on March 21, 2019 Upgrade to PHP 7.3 with Homebrew on Mac ...
-
7
« back — written by Brent on November 28, 2019 Upgrade to PHP 7.4 with Homebrew on Mac ...
-
15
« back — written by Brent on March 21, 2019 Upgrade to PHP 7.3 with Homebrew on Mac ...
-
11
« back — written by Brent on November 26, 2021 Upgrade to PHP 8.1 with Homebrew on Mac ...
-
9
在 Mac 上使用 Homebrew 升级PHP到 PHP 8.1 发布:3个月前 更新:3个月前...
-
3
« back — written by Brent on November 01, 2022 U...
-
3
使用 Homebrew 升级 首先确保 brew 是最新的: brew update 接下来,升级PHP。您可以使用内置的 php 配方,但我建议使用shivammathur/homebrew-php。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK