当前位置: 首页 > news >正文

PHPStudy2018环境部署全攻略

📋PHPStudy网站部署攻略

一、部署环境准备

1.1 软件清单
软件版本用途下载/安装方式
PHPStudy 20182018版集成环境(推荐)官网下载:https://www.xp.cn/download.html
Nginx1.15.11Web服务器(PHPStudy自带)PHPStudy集成
PHP5.6.27nts脚本解析器(PHPStudy自带)PHPStudy集成
MySQL5.6数据库(需单独切换)PHPStudy软件管理中安装5.6版本
HeidiSQL / phpMyAdmin-数据库管理工具PHPStudy自带phpMyAdmin
1.2 兼容性要点
  • PHP版本必须为5.6(网站基于ThinkPHP3.2.3开发)
  • MySQL必须用5.6(5.7以上可能存在兼容性问题)
  • Web服务器可选:最终采用Nginx(支持伪静态规则)

二、部署步骤

2.1 安装PHPStudy 2018
  1. 下载PHPStudy 2018版(不是8.1+版本)
  2. 安装路径:D:\phpStudy\PHPTutorial\(避免中文和空格)
  3. 启动后,在"软件管理"中安装MySQL 5.6
  4. 切换PHP版本为5.6.27nts
2.2 放置网站文件

网站根目录:D:\phpStudy\PHPTutorial\WWW\hn56at\

必须包含以下文件和目录:

  • index.php- 前台入口
  • admin.php- 后台入口
  • ThinkPHP/- 框架核心
  • Common/- 配置文件目录
  • Admin/- 后台模块
  • Index/- 前台模块
  • Uploads/- 附件目录(关键)
  • Public/- 静态资源目录
2.3 数据库配置
  1. 通过phpMyAdmin(http://localhost/phpMyAdmin/)创建数据库
  2. 导入网站数据文件xxx.sql
  3. 修改D:\phpStudy\PHPTutorial\WWW\hn56at\Common\Conf\config.php
'DB_HOST'=>'localhost','DB_NAME'=>'数据库名','DB_USER'=>'root','DB_PWD'=>'root',
2.4 PHP配置修改

编辑D:\phpStudy\PHPTutorial\php\php-5.6.27-nts\php.ini

; 关键1:禁用open_basedir限制(否则会报权限错误) ;open_basedir = /www/wwwroot/hn56at.com/:/tmp/:/proc/ ; 关键2:设置时区(消除警告) date.timezone = Asia/Shanghai ; 关键3:开启必要扩展 extension=php_mysql.dll extension=php_mysqli.dll extension=php_gd2.dll extension=php_curl.dll extension=php_mbstring.dll

重要:修改php.ini后必须重启PHP-CGI才能生效!

2.5 Nginx核心配置

文件位置:D:\phpStudy\PHPTutorial\nginx\conf\nginx.conf

worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; root "D:/phpStudy/PHPTutorial/WWW"; # ===== 1. 静态文件处理(优先级最高) ===== location /Uploads/ { alias D:/phpStudy/PHPTutorial/WWW/hn56at/Uploads/; expires 30d; access_log off; # 关键:alias替换路径,不加break可能导致后续匹配 break; } location /Public/ { alias D:/phpStudy/PHPTutorial/WWW/hn56at/Public/; expires 30d; access_log off; break; } location /uploadfile/ { alias D:/phpStudy/PHPTutorial/WWW/hn56at/uploadfile/; expires 30d; access_log off; break; } # ===== 2. 根目录下的伪静态请求 ===== location / { # 捕获伪静态URL重定向到子目录 if ($request_uri ~ "^/(list|show|article)-\d+-\d+\.html") { rewrite ^/(.*)$ /hn56at/$1 permanent; } try_files $uri $uri/ @rewrite; } location @rewrite { rewrite ^/(.*)$ /hn56at/index.php?s=$1 last; } # ===== 3. 子目录处理(核心伪静态规则) ===== location /hn56at/ { index index.php index.html; # 关键:文件不存在才重写到index.php if (!-e $request_filename) { rewrite ^/hn56at/(.*)$ /hn56at/index.php?s=$1 last; } } # ===== 4. 根目录跳转 ===== location = / { return 302 /hn56at/; } # ===== 5. PHP解析 ===== location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }

三、关键问题及解决方案

3.1 open_basedir限制(最坑)

现象:访问PHP文件报错open_basedir restriction in effect
解决:php.ini中注释掉open_basedir,并重启PHP-CGI
phpStudy内置PHP-CGI重启phpStudy即可达到重启PHP-CGI的效果

3.2 图片404问题

现象:HTML中图片路径为/Uploads/xxx.jpg,但文件实际在/hn56at/Uploads/
解决:用alias做路径映射,而不是root

location /Uploads/ { alias D:/phpStudy/PHPTutorial/WWW/hn56at/Uploads/; }
3.3 伪静态404问题

现象:访问/list-28-1.html报404
解决:在子目录中配置rewrite规则,并用!-e判断文件是否存在

3.4 子目录访问问题

现象:直接访问/hn56at/显示403
解决:添加index index.php index.html;指定默认首页

3.5 PHP-CGI不生效问题

现象:修改php.ini后配置不生效
解决:必须重启PHP-CGI进程,不能只重启Nginx

taskkill /F /IM php-cgi.exe cd /d D:\phpStudy\PHPTutorial\php\php-5.6.27-nts php-cgi.exe -b 127.0.0.1:9000 -c php.ini

四、测试与验证

4.1 访问测试
  • 首页跳转:http://localhost//hn56at/
  • 图片访问:http://localhost/Uploads/2024-09-03/xxx.jpg
  • 伪静态:http://localhost/hn56at/list-28-1.html
  • 后台:http://localhost/hn56at/admin.php
4.2 常用命令
# 测试Nginx配置 cd /d D:\phpStudy\PHPTutorial\nginx nginx -t # 重启Nginx nginx -s reload # 完全重启Nginx nginx -s stop && nginx # 查看错误日志 type D:\phpStudy\PHPTutorial\nginx\logs\error.log

五、注意事项总结

  1. PHP版本必须5.6,MySQL必须5.6
  2. open_basedir是最大的坑,修改后必须重启PHP-CGI
  3. 静态文件用alias而不是root
  4. 伪静态规则要放在子目录内处理,并判断文件是否存在
  5. location匹配顺序:静态文件 > 伪静态 > PHP解析
  6. 修改hosts文件做域名测试后,记得删除或注释掉,避免影响线上访问

六、线上迁移提示

部署到线上服务器时,需注意:

  • 线上环境通常也是Nginx + PHP5.6 + MySQL5.6
  • 将本地的Nginx配置适配到线上(修改root路径)
  • 数据库连接配置改为线上数据库信息
  • 上传目录(Uploads)需要设置写入权限
http://www.cnnetsun.cn/news/1360754.html

相关文章:

  • 中控SCADA-MQTT驱动采集与MQTT转发应用详解
  • mathtype中omml2mml缺失问题解决
  • 动力域-混动系统/动力域半实物仿真测试
  • 从 AI 终端爆发看人机交互演进:薄膜开关为何仍是工业控制的核心方案?
  • 小白入门:无刷直流电机BLDC,我从无人机开始学的那些事儿
  • 解决 ScrollView嵌套RecyclerView设置nestedScrollingEnabled=false数据显示不全问题
  • GNS3 入门指南
  • 并联机器人设计快速上手篇:利用iRobotCAM完成机器人夹爪的设计,无缝对接MuJoCo
  • 【2026年-11期】Where lies the future of humanity in the age of AI?
  • Chrome浏览器整页截图方法(MacOS)
  • 355. Java IO API -去除路径中的冗余信息
  • 面对大厂抄袭的指控,OpenClaw是否有足够的知识产权法律武器来保护自己?还是只能依靠舆论?
  • 康复训练 7
  • AI正在改变这10个行业,你的工作在其中吗?
  • 数字化时代,企业的商业模式建设
  • 计算机毕业设计之springboot基于web的新生报到系统设计与实现
  • 修改用户密码
  • 储能系统——04 升压换流一体机和箱变设计分析
  • 虚拟伴侣情感交互系统的压力测试框架与安全阀机制
  • 西门子 S7-1200PLC的RUNTIME指令怎么测量程序?
  • 预算有限怎么选?2026 三角洲行动游戏笔记本,华硕天选6Pro 酷睿版解析
  • 抽丝剥茧探穷境!一次数据库JSON字段的深度使用实践
  • Python+AI入门:避开90%新手坑,到底值不值花这个时间?
  • JavaScript基础课程十三、ES6+ 核心语法(三)——数组与对象高级方法
  • c++11的列表初始化及其底层原理
  • 企业私域运营全指南:从 0 到 10 万用户,可复制的全链路实操手册
  • 一个例子快速搞懂净现值(NPV)
  • 丑数1和2--动态规划法的一道不错的题
  • 水质五参数监测仪:精准洞察水体状况的“慧眼”
  • 帝国CMS编辑器如何解决Word文档中的公式粘贴后乱码问题?