macbook(M1芯片)搭建php+nginx运行环境

  1. macbook(M1芯片)搭建php+nginx运行环境

    1. php

      1. 安装php

        brew install php
        // 低版本php需要这样安装
        brew install shivammathur/php/php@7.4
        
      2. 配置环境变量(低版本的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
        
      3. 刷新环境变量(低版本的php才需要)

        source ~/.zshrc
        
      4. php-fpm的使用

        1. 启动

          sudo php-fpm
          
        2. 关闭

          sudo kill -int [pid]
          
    2. nginx

      1. 安装nginx

        brew install nginx
        
      2. 配置nginx(/opt/homebrew/etc/nginx/nginx.conf)

        1. 单个配置

          #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;
          }
          
          
        2. 多个配置(这样可以避免修改默认文件,可以单独分开文件)

          1. 直接在servers文件加下创建一个文件(命名随便)

          2. 然后配置

            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;
                }
            
            }
            
      3. 启动nginx

        sudo nginx
        
      4. 关闭nginx

        sudo nginx -s stop
        
      5. 重启nginx

        sudo nginx -s reload
        
      6. nginx默认服务器路径

        /opt/homebrew/var/www
        
  2. fastadmin框架中

    1. 一定要记得给权限

      chmod -R 777 /opt/homebrew/var/www/1.4.0.20230711
      
posted @ 2024-03-24 16:26  xiaowei123456  阅读(397)  评论(0编辑  收藏  举报