关于php搭建wp的一些注意事项以及解决方法,记录一下,方便回溯

一、php配置环境的时候有两个注意事项:第一,端口。第二,版本。

端口问题就是创建的网站要和nginx的端口要一致,否则会报504,505等超时网关问题。
版本问题就是wordpress不支持PHP7.4版本以下的,但是太高,比如8.2版本会导致打开网页的时候404,
404 Not Found nginx/1.15.11
在版本问题中还有一点,搭建好网站之后wp会提示版本PHP版本过低,此问题和提高版本至8.2有冲突,但是8.0没有试过,所以先不提。
电脑突然关机,再次开机打开网站wp可能会导致报错,如下
Warning: mysqli_query(): (HY000/1194): Table 'wp_options' is marked as crashed and should be repaired in D:\phpstudy_pro\WWW\dwkj.com\wp-includes\class-wpdb.php on line 2353
随便点击网站的某个地方会有提示:
To allow use of this page to automatically repair database problems, please add the following line to your wp-config.php file. Once this line is added to your config, reload this page. define('WP_ALLOW_REPAIR', true);
意思就是找到wp-config.php的文件加上define('WP_ALLOW_REPAIR', true);按如上操作说明后,后退一步会出现如下画面,第一个按钮是修复,第二个按钮是修复优化。修复成功后记得将这行代码注释或者删除

局部截取_20260902_153640
点击第二个按钮后,自己会修复并且优化
局部截取_20260902_154000
按如上所说,刚加的代码省略或者删除即可

二、在对着教程配置环境的时候要注意以下问题:教程是Apache+M,但我们实际上用Nginx+M

所以在启动服务的时候会到这种错误:
nginx: [emerg] unknown directive "<IfModule" in D:/phpstudy_pro/WWW/duwokeji.con/nginx.htaccess:6
根因:Nginx 不支持 Apache 的 .htaccess 语法(如 、RewriteRule 等)。phpStudy 中的 nginx.htaccess 文件仅用于存放转换后的 Nginx 规则,不能直接复制 Apache 配置。
解决方法:清空 D:/phpstudy_pro/WWW/duwokeji.con/nginx.htaccess 文件内容,填入以下标准的 ThinkPHP/Laravel 伪静态规则(根据实际框架选择,此处以最常见的 TP6/Laravel 为例):
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }
再次重启服务即可成功。

三、PHP创建网站的时候报错:nginx: [emerg] CreateFile() "D:/phpstudy_pro/WWW/ceshi1/nginx.htaccess" failed (2: The system cannot find the file specified) in D:\phpstudy_pro\Extensions\Nginx1.15.11/conf/vhosts/ceshi1_80.conf:20

根因:Nginx 配置文件 ceshi1_80.conf 中引用了伪静态文件 nginx.htaccess,但该文件在站点根目录下不存在。
解决方法:在站点目录 D:/phpstudy_pro/WWW/ceshi1/ 下新建一个空的 nginx.htaccess 文件,或根据需求写入伪静态规则。
‌方案一:创建空文件(快速恢复启动)‌ 方案一我试过,不管用
powershell New-Item -Path "D:\phpstudy_pro\WWW\ceshi1\nginx.htaccess" -ItemType File -Force
‌方案二:若需 ThinkPHP/Laravel 等框架伪静态,写入以下内容‌
nginx if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; }
操作后重启 Nginx 服务即可。

四、使用方案一重启Nginx服务会报另一种错误

nginx: [emerg] unexpected end of file, expecting ";" or "}" in D:/phpstudy_pro/WWW/ceshi1/nginx.htaccess:2
解决方案就是方案二

说明:要是不想报错就在创建网站的时候不要删除nginx.htaccess文件

![局部截取_20260905_104623]

五、502和504

局部截取_20260905_104836

局部截取_20260905_104757
搭建好的网站切换8.0=>404
局部截取_20260905_105622

posted @ 2026-09-02 15:48  璟君  阅读(1)  评论(0)    收藏  举报