Mac M1Pro 安装 PHP 开发环境
source link: https://segmentfault.com/a/1190000041213085
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.
brew install [email protected] nginx
配置环境变量
vim ~/.zshrc
# PHP export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH" export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib" export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
配置完环境变量运行一下 source ~/.zshrc
如果担心错过什么提示可以运行 brew info [email protected]
配置文件夹开启 git 管理
cd /opt/homebrew/etc/php/7.4 # 用 git 管理 php 配置, 不然容易搞乱 git init && git add . git commit -m "feat: initial commit" cd /opt/homebrew/etc/nginx # 用 git 管理一下 nginx 配置, 不然容易搞乱 git init && git add . git commit -m "feat: initial commit"
创建 index.php
vim /opt/homebrew/var/www/index.php
<?php phpinfo();
修改 nginx 配置
vim /opt/homebrew/etc/nginx/nginx.conf
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 $document_root$fastcgi_script_name; include fastcgi_params; }
修改说明
1、index 行添加 index.php
2、取消 php 相关的注释, 把默认的 /scripts$fastcgi_script_name
修改为 $document_root$fastcgi_script_name
brew services restart [email protected] brew services restart nginx
访问 http://localhost:8080/index.php 就能看到 phpinfo 信息页
php 扩展
可以用 pecl 安装扩展, 不用手动去 php.ini 中开启
pecl install xdebug
idea 配置 xdebug
文件夹位置
nginx 路径:/opt/homebrew/var/www
nginx 配置文件:/opt/homebrew/etc/nginx/nginx.conf
nginx 默认端口是 8080 (80端口需要sudo)
php 配置文件:/opt/homebrew/etc/php/7.4/
php-fpm 默认监听 9000 端口
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK