You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用XAMPP与PHP时无法访问自定义脚本页面问题求助

Troubleshooting Your XAMPP PHP 404 Error

Hey there! Let's work through this step by step—totally get how frustrating it is when you're excited to run your first PHP script and hit a roadblock. Here are the most common fixes to try:

1. Double-Check Your File Path First

First things first: make sure your folder structure is exactly right. XAMPP looks for files inside the htdocs folder that comes with your installation. So your setup should be:

  • <XAMPP安装目录>/htdocs/scripts/ (this folder must sit directly inside htdocs)
  • <XAMPP安装目录>/htdocs/scripts/index.php (your PHP file lives here)

It’s a super common newbie mistake to accidentally place the scripts folder outside of htdocs (like in the XAMPP root folder instead)—double-check that first!

2. Watch Out for Case Sensitivity

If you’re on a Mac or Linux machine, file and folder names are case-sensitive. So if your folder is named Scripts (capital S) but you’re visiting localhost/scripts/, Apache will throw a 404. Even on Windows, it’s good practice to keep your URLs and folder names matching exactly to avoid issues later.

3. Restart Your Apache Server

XAMPP’s Apache doesn’t always pick up new folders immediately. Head over to your XAMPP Control Panel, stop the Apache service, wait 2 seconds, then start it again. This forces Apache to re-scan the htdocs directory, and it might fix the missing URL issue right away.

4. Verify Your PHP Code

Make sure your index.php has valid, error-free code. A tiny syntax mistake can sometimes cause unexpected behavior (though usually it’s a 500 error, not 404, but better safe than sorry!). Your code should look like this:

<?php
echo 'Hello World!';
?>
  • Use English quotation marks (not Chinese ones)
  • Don’t forget the semicolon at the end of the echo line
  • Make sure the <?php opening tag is present (without it, the server will just show raw text instead of executing PHP)

5. Test with a Root Folder File

To narrow down the issue, move your index.php directly into the htdocs folder (not inside scripts), then visit http://localhost/index.php.

  • If this works, the problem is definitely related to the scripts folder (either path, permissions, or case).
  • If it doesn’t work, check if PHP is enabled in XAMPP:
    • Open the XAMPP Control Panel and make sure the "PHP" module is checked/enabled
    • Create a phpinfo.php file in htdocs with <?php phpinfo(); ?>—if visiting localhost/phpinfo.php shows a PHP info page, PHP is working correctly.

6. Check Apache's Document Root Configuration (Advanced)

If none of the above works, verify that Apache is pointing to the correct htdocs folder. Open the httpd.conf file (you can find it in XAMPP’s Apache config menu) and look for these lines:

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">

Make sure both paths match your actual XAMPP htdocs location. Also, inside the <Directory> block, ensure you have:

AllowOverride All
Require all granted

These settings let Apache access subfolders like scripts without restrictions.


内容的提问来源于stack exchange,提问作者poppashingles

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:41:36