WNMP环境搭建步骤
三大件安装
Nginx安装
- 下载地址:http://nginx.org/en/download.html
- 选择稳定版本:
- 下载文件名称:nginx-1.16.1.zip
- 解压压缩包,并进入目录,比如D:\wnmp\nginx
- 运行nginx.exe
- 打开浏览器,地址栏输入:localhost,回车
出现该页面,则安装成功。
PHP安装
- 下载地址:https://windows.php.net/download#php-7.4
- 选择非线程安全版本
- 下载文件:php-7.4.1-nts-Win32-vc15-x64.zip
- 解压压缩包,并进入目录,比如:D:\wnmp\php
- 打开cmd,运行命令php -v
出现该页面,则安装成功。
MySQL安装
- 下载地址:https://dev.mysql.com/downloads/mysql/
- 选择 下载-> No thanks, just start my download.
- 下载文件:mysql-8.0.18-winx64.zip
- 解压压缩包,为后续配置做准备
三大件配置
Nginx配置
- 备份conf目录(比如D:\wnmp\nginx\conf)下nginx.conf文件
- 修改nginx.conf文件,部分注释内容未贴出来
#user nobody;
worker_processes 1;
http {
server {
listen 80;
server_name localhost;
location / {
root D:/wnmp/www/localhost;
index index.html index.htm index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root D:/wnmp/www/localhost;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
PHP配置
- 修改D:\wnmp\php目录下php.ini-development为php.ini,
- 仅展示部分配置,其余根据项目需要自行修改配置
[PHP]
; 1
extension_dir = "D:\wnmp\php\ext"
; 2
enable_dl = On
; 3
cgi.force_redirect = 0
; 4
cgi.fix_pathinfo=1
; 5
fastcgi.impersonate = 1
; 6
cgi.rfc2616_headers = 1
; 7
extension=php_mysqli.dll
; 8
date.timezone = Asia/Shanghai
MySQL配置
- MySQL安装目录D:\wnmp\mysql-8.0.18-winx64修改my.ini文件(如无,则手动添加)
[mysqld]
# set basedir to your installation path
basedir=D:\\wnmp\\mysql-8.0.18-winx64
# set datadir to the location of your data directory
datadir=D:\\wnmp\\mysql-8.0.18-winx64\\data
- 详细配置可参考该文档MySQL配置部分:https://blog.csdn.net/lylfv/article/details/82284750
三大件联调
PHP连接Nginx
- 创建目录D:\wnmp\www\localhost
- 新建文件phpinfo.php,内容如下
<?php
phpinfo();
- 开启PHP进程(注意:cmd需要以管理员权限运行)
d:\wnmp\php>php-cgi.exe -b 127.0.0.1:9000 -c php.ini
- 开启Nginx
d:\wnmp\nginx>start nginx.exe
- 打开浏览器,输入http://localhost/phpinfo.php,查看页面展示
至此,则表示PHP和Nginx连接成功。
PHP连接MySQL
- 开启MySQL
d:\wnmp>net start mysql
- 编写脚本test_mysql.php,内容如下:
<?php
$servername = "localhost";
$username = "root";
$password = "phpphp";
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
- 打开浏览器,输入,查看页面展示
至此,则表示PHP和MySQL连接成功。
常用脚本和命令
下面两个脚本** start_nginx.bat和 stop_nginx.bat**用于快捷启动、停止Nginx&PHP服务。
start_nginx.bat
@echo off
REM set PHP_FCGI_CHILDREN=5
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
D:\wnmp\nginx\RunHiddenConsole "D:\wnmp\php\php-cgi.exe" -b 127.0.0.1:9000 -c "D:\wnmp\php\php.ini"
echo Starting nginx...
D:\wnmp\nginx\RunHiddenConsole "D:/wnmp/nginx/nginx.exe" -p "D:/wnmp/nginx/"
stop_nginx.bat
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
常用命令
- 查看进程
tasklist /fi "imagename eq nginx.exe"
tasklist /fi "imagename eq php-cgi.exe"
netstat -ano | findstr "3306"
- Nginx重载配置
nginx -s reload
- Nginx优雅关闭
nginx -s quit
- Nginx帮助命令
nginx -h
- 关闭MySQL服务
net stop mysql
来源:CSDN
作者:Empty-Filled
链接:https://blog.csdn.net/lylfv/article/details/103918976