macbook(M1芯片)搭建php+nginx运行环境
-
macbook(M1芯片)搭建php+nginx运行环境
-
php
-
安装php
brew install php // 低版本php需要这样安装 brew install shivammathur/php/php@7.4
-
配置环境变量(低版本的php才需要)
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
-
刷新环境变量(低版本的php才需要)
source ~/.zshrc
-
php-fpm的使用
-
启动
sudo php-fpm
-
关闭
sudo kill -int [pid]
-
-
-
nginx
-
安装nginx
brew install nginx
-
配置nginx(
/opt/homebrew/etc/nginx/nginx.conf
)-
单个配置
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} # 配置子目录下的文件 include servers/*; # 配置子目录下的文件 include conf.d/*.conf; }
-
多个配置(这样可以避免修改默认文件,可以单独分开文件)
-
直接在servers文件加下创建一个文件(命名随便)
-
然后配置
server { listen 8888; server_name localhost; # 项目目录 root /opt/homebrew/var/www/1.4.0.20230711/public; location / { # 伪静态 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /Users/weiyonglin/Downloads/1.4.0.20230711/public; } // 配置解析php location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index indx.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $1; include fastcgi_params; } location ~ /\.ht { deny all; } }
-
-
-
启动nginx
sudo nginx
-
关闭nginx
sudo nginx -s stop
-
重启nginx
sudo nginx -s reload
-
nginx默认服务器路径
/opt/homebrew/var/www
-
-
-
fastadmin框架中
-
一定要记得给权限
chmod -R 777 /opt/homebrew/var/www/1.4.0.20230711
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!