WNMP 环境配置

WNMP 环境配置

下载

  1. Nginx
  2. PHP
  3. MySQL

Nignx

  1. 解压 Nignx 到 D:\DevEnv\Nignx
  2. 运行 D:\DevEnv\Nignx 下的 nginx.exe
  3. 打开浏览器访问 http://localhosthttp://127.0.0.1

nginx.png

  1. 配置
D:\DevEnv\Nignx\nginx.cof
1
2
3
4
location / {
root D:/WNMP/www; #指定站点根目录为D:/wnmp/www
index index.php index.html index.htm; #添加index.php,优先解析php文件
}

再往下,找到如下内容,取消注释

D:\WNMP\Nignx\nginx.cof
1
2
3
4
5
6
7
8

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

然后将 root html; 更改为 root D:/wnmp/www; 再将 /scripts 改为 $document_root,这里的”$document_root”就是前面 “root” 所指定的站点路径

D:\WNMP\Nignx\nginx.cof
1
2
3
4
5
6
7
location ~ \.php$ {
root D:/WNMP/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

常用命令

1
2
3
4
nginx -s stop	快速关闭Nginx
nginx -s quit 优雅的关闭Nginx
nginx -s reload 更改配置,使用新配置启动新工作进程,正常关闭旧工作进程
nginx -s reopen 重新打开日志文件

MySQL

复制my-default.ini文件,并重命名为my.ini。再打开my.ini,取消 basedir 和 datadir 注释,并指定具体路径:

1
2
basedir = "D:/wamp/mysql/"
datadir = "D:/wamp/mysql/data/"

以管理员身份打开一个DOS窗口,切换到bin目录(必须),

1
2
3
4
d:                                         # 切换到D
cd d:\wnmp\mysql-5.7.17-winx64\bin # 切换到bin目录
mysqld -install # 安装MySQL服务
mysqld --initialize --user=root --console # 初始化MySQL,生成data目录和root密码,5.7版本之后必须要有这个命令

最后那条命令会生成一个临时密码,如下:

1
2019-12-23T07:55:56.279880Z 1 [Note] A temporary password is generated for root@localhost: o*%_kb(k_1<V

再启动MySQL:

1
net start mysql

临时密码只能登陆后修改密码,不能进行其他操作。使用下面的命令修改

1
mysql_secure_installation

其他版本修改密码

PHP

  1. 解压 PHP 到 D:\DevEnv\PHP
  2. 修改配置,将 D:\PHP\php.ini-development 改为 php.ini,取消下面注释
D:\PHP\php.ini
1
2
3
4
5
6
7
8
9
;extension=mysql
;extension=mysqli
;enable_dl = Off,改为 enable_dl = On
;fastcgi.impersonate = 1
;extension=curl
;extension=gd2
;extension=mbstring
;extension=mysqli
;extension=mysql

;再修改

1
2
3
4
;extension_dir = "ext" 改为 extension_dir = "D:\wnmp\php\ext"
;date.timezone = 改为date.timezone = Asia/Shanghai
;cgi.force_redirect = 1 改为cgi.force_redirect = 0
;cgi.rfc2616_headers = 0 改为 cgi.rfc2616_headers = 1
  1. 配置 PHP,使其能与 Nginx 配合,取消下面的注释

    1
    ;cgi.fix_pathinfo=1
  2. 启动PHP

    1
    D:\WNMP\php\php-cli.exe -b 127.0.1.1:9000 -c D:\WNMP\php\php.ini

脚本

stat.bat
1
2
3
4
5
6
7
8
9
10
11
12
@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5

REM 每个进程处理的最大请求数,或设置为Windows环境变量
set PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI...
D:/wnmp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php/php.ini

echo Starting nginx...
D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
stop.bat
1
2
3
4
5
6
7
8
9
@echo off

echo Stopping nginx...
taskkill /F /IM nginx.exe > null

echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > null

exit

环境变量

环境变量Path里面增加 MySQL、Nginx、PHP 执行文件的路径

1
;D:\wnmp\mysql\bin;D:\wnmp\nginx;D:\wnmp\php;

整体测试

  • 测试 PHP
D:\WNMP\nginx\html
1
2
3
<?php
phpinfo();
?>

浏览器访问 http://localhost/phpinfo.php

  • 测试 Mysql
D:\WNMP\nginx\html
1
2
3
4
5
6
7
<?php 
if (mysqli_connect("localhost","root","root")) {
echo "Mysql connect successful!";
}else{
echo "Mysql connect error...";
}
?>

  PHPWin

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×