1. 程式人生 > 其它 >mac m1 pro 搭建php環境

mac m1 pro 搭建php環境

下載homebrew

檢視本地是否有安裝php

terminal執行php -v檢視

如果有,檢視安裝位置

whereis php

啟動/停止本地php

啟動:php-fpm

停止:pkill php-fpm

用homebrew下載php

用homebrew下載nginx

修改php配置

修改Nginx配置

#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;

        # 預設網站根目錄(www目錄)
        # root         /opt/homebrew/var/www/;
        root         /Users/mingwei/Documents/open-source-mall/yoshop2.0/public/;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            # root   html;
            index  index.php 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
        #
        # PHP 指令碼請求全部轉發到 FastCGI處理. 使用FastCGI協議預設配置.
        # Fastcgi伺服器和程式(PHP,Python)溝通的協議.
        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;
           # 引入fastcgi的配置檔案
           include        fastcgi_params;
        #    include        /opt/homebrew/etc/nginx/fastcgi_params;

           #So if your app has an upload dir "/images/" then insert if ($uri !~ "^/images/") before fastcgi_pass, as so:
           if ($uri !~ "^/images/") {
               fastcgi_pass 127.0.0.1:9000;
            }
        }


        # 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/*;
}

  

在Nginx站點目錄放置一個php檔案

<?php
	phpinfo();
?>

  

啟動php

啟動nginx

homebrew基本操作

brew services start/restart/stop nginx/php

brew info nginx