phpstudy应该是比较常用的php环境配置软件,一般前端开发不需要了解太多服务器知识的时候,可以选择集成的配置环境。下面就来操作一下windows下的虚拟主机配置。
环境:windows7,64bit
配置步骤:
1、从官网下载最新版的phpstudy,已集成php7.3+,mysql5.7+
phpstudy官网传送门
2、一键启动选择wnmp,如图
3、创建网站
我的测试域名写tui,端口80,php选择7.3+,其他默认
4、绑定hosts
Hosts文件路径 C:\Windows\System32\drivers\etc
增加127.0.0.1 tui
5、打开nginx配置文件,修改vhost文件,我的文件为 tui_80.conf 文件参考为如下内容
server {
listen 80;
server_name tui;
root "D:/phpstudy_pro/WWW/tui/public";#此处改为本地对应目录
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
error_page 404 /index.php;
#access_log /tmp/nginx.access.log;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
6、增加数据库并导入数据
7、在phpstudy启动wnmp ,浏览器中页面打开
http://tui
以上为win搭建wnmp过程。
By the way,现在很多公司开发,为了统一环境,都会使用docker环境,有兴趣的建议了解一下。