Windows部署Nginx1.27+PHP8.3+MySQL8.0学习笔记

千千 发布于 2025-03-04 142 次阅读


前往 nginx: download 下载在Nginx1.27 for windows

解压到目标目录修改配置文件conf/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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.php 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;
        }
# ====================================================

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

}

前往 PHP for Windows:二进制文件和源版本 下载PHP8.3 for windows版本

下载Zip

在指定目录解压,将php.ini-development复制一份为php-ini,将cgi.fix_pathinfo=1取消注释

CMD使用php-cgi -b 127.0.0.1:9000启动PHP

CMD Nginx使用nginx

OKya~完成,寥寥草草,反正是自己看

啊~又来了,继续安装MySQL吧

前往 MySQL :: Download MySQL Community Server (Archived Versions) 下载8.0的MySQL

下载安装后解压到指定目录

在解压的目录下创建my.ini

内容如下

  [mysqld]
  # 设置3306端口
  port=3306
  # 【重点修改】设置mysql的安装目录
  basedir=D:\Server\mysql-8.0.40-winx64
  # 【重点修改】设置mysql数据库的数据的存放目录
  datadir=D:\Server\mysql-8.0.40-winx64\data
  # 允许最大连接数
  max_connections=200
  # 允许连接失败的次数。
  max_connect_errors=10
  # 服务端使用的字符集默认为utf8mb4
  character-set-server=utf8mb4
  # 创建新表时将使用的默认存储引擎
  default-storage-engine=INNODB
  # 默认使用“mysql_native_password”插件认证
  #mysql_native_password
  default_authentication_plugin=mysql_native_password
  [mysql]
  # 设置mysql客户端默认字符集
  default-character-set=utf8mb4
  [client]
  # 设置mysql客户端连接服务端时默认使用的端口
  port=3306
  default-character-set=utf8mb4

初始化MySQL,CMD运行mysqld --initialize --console,结果如下

D:\Server\mysql-8.0.40-winx64\bin>  mysqld --initialize --console
2025-03-04T02:34:57.417645Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2025-03-04T02:34:57.417854Z 0 [System] [MY-013169] [Server] D:\Server\mysql-8.0.40-winx64\bin\mysqld.exe (mysqld 8.0.40) initializing of server in progress as process 2276
2025-03-04T02:34:57.456913Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-03-04T02:34:57.835975Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-03-04T02:35:01.549419Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: EeOKgrt2/9Z/
2025-03-04T02:35:01.866835Z 6 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'

这里会产生一个初始化密码,需要记住咯,不然...我也不知道会咋样

这里注册服务和开启服务,CMD继续运行

  mysqld --install
  net start mysql

这里可以设置MySQL root密码啦

mysql -u root -p
# 输入刚刚的初始化密码
alter user 'root'@'localhost' identified by 'NewPassword';

好啦~寥寥草草的又完成了~

飞萤扑火,向死而生
最后更新于 2025-03-04