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

Laravel新项目首次运行正常,二次运行出现文件无法打开报错

Fixes for the "Missing server.php" Error in Laravel

Hey there, let's figure out why your Laravel project is throwing that missing server.php error after working fine the first time. I've run into this a few times myself, so here are the go-to fixes that usually resolve it:

  • Check if server.php actually exists in your project root
    Accidental deletions happen to the best of us! Head to your project folder (D:[path] as noted in your error) and double-check if server.php is present. If it's gone, you have two quick fixes:

    1. Create a new server.php file in the root and paste this default Laravel content:
      <?php
      
      $uri = urldecode(
          parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
      );
      
      // Emulate Apache's "mod_rewrite" for the built-in PHP server
      if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
          return false;
      }
      
      require_once __DIR__.'/public/index.php';
      
    2. Grab a fresh copy of server.php from a new Laravel project (created with laravel new temp-project) and copy it into your existing project root.
  • Verify your server's document root is set correctly
    Since your error mentions XAMPP, make sure your Apache virtual host or local server setup points to the public folder of your Laravel project—not the root folder. The server.php file is only needed for the built-in PHP server (php artisan serve); pointing directly to public avoids relying on it entirely and is the recommended setup for Apache/Nginx.

  • Fix Windows file permissions (if applicable)
    Windows can sometimes mess up file permissions after the first run. Right-click your project folder, go to Properties > Security, and ensure your user account has full read/write access to all files and subfolders.

  • Clear Laravel's cache (just in case)
    Odd behavior can sometimes stem from cached configs. Open your terminal, navigate to your project root, and run these commands:

    php artisan cache:clear
    php artisan config:clear
    
  • Make sure you're running the server from the right directory
    If you're using php artisan serve, double-check that you're executing the command from the root folder of your Laravel project—not the public folder or any subdirectory. Running it from the wrong place will make PHP look for server.php in the wrong location.

If none of these work, check if your project path has special characters or spaces (Windows hates those!). For example, D:\My Cool Laravel Project might cause issues—try renaming it to D:\MyCoolLaravelProject if that's the case.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:14:24