希望对PHP学习有帮助
准备?作
- nginx的安装
nginx下载链接:http://nginx.org/en/download.html
打开如下图
- php的安装
php下载链接:https://www.php.net/downloads.php
打开如下图
点击进入详细信息
(nginx下php是以FastCGI的?式运?,所以我们下载?线程安全也就是nts的
php包)
安装过程
nginx是绿?软件,解压后,双击nginx.exe就可以运?了
我把nginx放在了 C:/wnmp/nginx/
双击后在刘浏览器打开 http://127.0.0.1 即可以看到欢迎??
PHP也是绿?软件,下载zip安装包解压即可
我的PHP放置的?录为:C:/wnmp/php7.3环境配置
准备?个?件夹,作为我们环境的运??录,这个在下?会多次?到,我的运
??录是 C:/wnmp/www
打开 C:/wnmp/nginx/conf/nginx.conf,找到这个配置块
location / {,
root html;
index index.html index.htm;
}
修改为下?这样:
location / {,
root C:/wnmp/www;
index index.html index.htm;
}
再找到这个配置块
#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; 改为C:/wnmp/www;
再把/scripts改为$document_root,这?的$document_root就是指前
?“root”所指的站点路径改完如下:
location ~ .php$ {
root C:/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;
}
在php根?录下找到php.ini-development?件,复制?份在当前?录并且重命
名为php.ini
用记事本打开php.ini,找到 “;cgi.fix_pathinfo=1”,去掉全?的分号,也就是说打
开这条注释。
最终运行
打开nginx
这个没啥好说的,双击nginx.exe就打开了,上?已经提到了
打开fastcgi
在命令?中,cd到php的?录,然后执?如下命令:
php-cgi.exe -b 127.0.0.1:9000 -c php.ini
在 C:/wnmp/www 下新建?个info.php?件,输?如下内容:
<?php
echo phpinfo();
打开浏览器,输? http://127.0.0.1/info.php
在这?,我简单说说配置的原理,因为nginx是?个反向代理的web服务器,因
此它其实必须依赖?个真正的web服务器才能执?动态的??内容,因此这?
php就是使?fastcgi来充当这个真正的web服务器,它运?在9000端?上,这
也是为什么nginx.conf中有这样?句fastcgi_pass 127.0.0.1L9000;,知道这个原
理后,下?的思路就很明确了,打开fastcgi,然后再打开nginx就?了
本文暂时没有评论,来添加一个吧(●'◡'●)