Mac Brew安装PHP运行环境
1、安装homebrew
ruby -e "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install](https://raw.githubusercontent.com/Homebrew/install/master/install))”
brew常用命令
brew update #更新brew可安装包,建议每次执行一下
brew search php55 #搜索php5.5
brew tap josegonzalez/php #安装扩展<gihhub_user/repo>
brew tap #查看安装的扩展列表
brew install php55 #安装php5.5
brew remove php55 #卸载php5.5
brew upgrade php55 #升级php5.5
brew options php55 #查看php5.5安装选项
brew info php55 #查看php5.5相关信息
brew home php55 #访问php5.5官方网站
更换科大源「国外源慢可以更换」
替换brew.git:
cd "$(brew --repo)"
git remote set-url origin [https://mirrors.ustc.edu.cn/brew.git](https://mirrors.ustc.edu.cn/brew.git)
//替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin [https://mirrors.ustc.edu.cn/homebrew-core.git](https://mirrors.ustc.edu.cn/homebrew-core.git)
1.重置源
cd "$(brew --repo)"
git remote set-url origin [https://github.com/Homebrew/brew.git](https://github.com/Homebrew/brew.git)
//重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin [https://github.com/Homebrew/homebrew-core.git](https://github.com/Homebrew/homebrew-core.git)
安装完成后查看brew help看到已安装完成
2、安装Nginx
//查看版本已有版本
brew search Nginx
//『在此安装的nginx1.17.6版本』
brew install nginx
安装完成后如下代码
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you dont want/need a background service you can just run:
nginx
文件目录:/usr/local/var/www
配置文件:/usr/local/etc/nginx/nginx.conf
虚拟配置:/usr/local/etc/servers/
后台启动:brew services start nginx
验证nginx启动成功:http://localhost:8080(8080端口不需要sudo即可)
3、安装MySQL
brew search mysql
安装MySQL5.7
brew install mysql@5.7
We've installed your MySQL database without a root password. To secure it run:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have mysql@5.7 first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql@5.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
To have launchd start mysql@5.7 now and restart at login:
brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@5.7/bin/mysql.server start
==>Summary🍺 /usr/local/Cellar/mysql@5.7/5.7.28: 318 files, 232.5MB, built in 17 minutes 31 seconds
PHP安装
brew install php@7.2
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
sudo chmod 777 /private/etc/php-fpm.conf
更改配置文件
vim /etc/php-fpm.d/php-fpm.conf
pid = /Users/Monkees/Documents/log/run/php-fpm.pid
error_log = /Users/Monkees/Documents/log/php-fpm.log
启动: php-fpm
停止: sudo killall php-fpm
开机启动
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
编译安装 PHP 扩展的方法参考
创建 config-file-scan-dir 指定的目录:
mkdir -p /Library/Server/Web/Config/php
源码编译安装 php 扩展
这里以 php_discuz 扩展 ([https://github.com/potterhe/php_discuz)https://github.com/potterhe/php_discuz%5Bhttps://github.com/potterhe/php_discuz)] 为例,介绍编译安装扩展的步骤。
假如扩展源码在 /Users/lzwme/php_discuz 目录,进入该目录并编译:
$ ./configure
$ make
扩展编译后,默认会存储在 /Users/Mookeens/php_discuz/modules/discuz.so。将扩展配置到 php 自动加载配置的目录中:
$ echo "extension=/Users/lzwme/php_discuz/modules/discuz.so" > /Library/Server/Web/Config/php/discuz.ini
测试验证是否成功
$ php -i|grep discuz
discuz support => enabled
执行测试用例
$ php -f /Users/lzwme/php_discuz/discuz.php
使用 brew 安装 php 扩展
以安装 phpredis 为例:
查看 php 版本
$ php -v
PHP 5.5.36 (cli) (built: May 29 2016 01:07:06)
根据 php 版本安装对应版本的扩展
$ brew install homebrew/php/php55-redis --build-from-source
Nginx新建 server
在 /usr/local/etc/nginx/servers/ 目录中新建的配置文件,都会被 nginx.conf 加载。
cd /usr/local/etc/nginx/servers
vi localhost-80.conf
在其中输入 server 配置。参考:
server {
listen 80;
root /Users/lzwme/test;
server_name localhost;
index index.html index.htm index.php;
# 方便本地测试,开启目录浏览遍历
location / {
autoindex on; # 开启目录浏览功能
autoindex_exact_size off; # 关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b
autoindex_localtime on; # 开启以服务器本地时区显示文件修改日期
}
location ~ .php$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现