准备所需安装包php
本次所选安装版本是:nginx1.11.5,php7.1.0,mysql5.7.16,固然能够根据喜欢的版本下载,为了方便管理,我在D盘下新建了wnmp文件夹,里面包含文件夹有mysql,php,nginx,www,www为存放项目文件夹。
Nginx: 前往nginx.org/en/download.html下载;
PHP:前往Windows.php.net/download下载 ,根据本身的电脑系统位数选择对应版本,顺便说下线程安全版(Thread Safe)和非线程安全版(Non Thread Safe),在Windows下是用FastCGI模式运行php,因此就不必使用线程安全检查,选用非线程安全版效率会高一些。
MySQL:前往dev.mysql.com/downloads/mysql下载,选择Windows版本。html
一 安装MySQLmysql
1.双击安装包进入安装界面,到第二步后建议选择custom(自定义)安装,这样就能够选择mysql文件和数据库文件的存放位置,否则会所有默认安装在C盘;
进入自定义以后只选择安装server就能够,由于其余用不到
点击advanced options选择安装在D:/wnmp/mysql中nginx
以后一直next或者execute,到设置账号密码这一步设置本身的密码就好了
以后仍是next或者execute,直到出现finished,点击,安装mysql完成。
二 安装PHPsql
1.将php压缩包解压到D盘新建的wnmp/php文件夹中; 2.将php文件夹中的php.ini-development,复制粘贴,将副本改成php.ini; 3.用记事本打开php.ini 查找到一下代码并将前面的分号去掉 ;extension_dir = "ext" ;cgi.force_redirect = 1 ;cgi.fix_pathinfo=1 ;fastcgi.impersonate = 1 ;cgi.rfc2616_headers = 0 改成: extension_dir = "D:/www/php/ext" cgi.force_redirect = 1 cgi.fix_pathinfo=1 fastcgi.impersonate = 1 cgi.rfc2616_headers = 0
三 安装Nginx数据库
1.将Nginx压缩包解压到D盘新建的wnmp/nginx文件夹中; 2.打开nginx/conf/nginx.conf进行配置 将 server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } # 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; #} } 改成: server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root D:/wnmp/www; 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; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 保存后双击nginx.exe就能够直接运行Nginx服务器了,打开浏览器输入localhost就能够看到欢迎页。
四 调试浏览器
1.打开命令提示符输入D:进入到D盘安全
D:\>cd wnmp/php D:\wnmp\PHP>php-cgi.exe -b 127.0.0.1:9000 -c php.ini 启动后再新打开一个命令提示符,输入:netstat -a:findstr "9000"查看9000端口是否被监听,若是是说明cgi运行成功。
2.在www目录下新建index.php <?php $con = mysqli_connect('localhost','root','root','test'); if($con){ echo '连接数据库成功!'; }else{ echo '连接数据库失败!'; } 运行以后输出下面结果,说明能够解析PHP文件且能够连接数据库。