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

Laravel 5.6新安装执行php artisan serve时server.php被删除致无法访问

Fixing Laravel 5.6 server.php Deletion & Permission Issues with php artisan serve

Hey there, that's a weird and frustrating hiccup—let's work through this step by step to get your Laravel setup back on track!

1. Fix Directory & File Permissions (The Root Cause)

This issue almost always boils down to misconfigured file permissions in your XAMPP htdocs folder. When you run php artisan serve, the process might be using a user account that doesn't have proper ownership, leading to accidental deletion of server.php and locked permissions when you try to recreate it.

  • First, stop your XAMPP Apache server if it’s running.

  • Open your terminal (Windows: CMD/PowerShell; Mac/Linux: Terminal) and navigate to your Laravel project directory:

    cd /path/to/xampp/htdocs/your-laravel-project-folder
    
  • For Mac/Linux users:

    • Set proper ownership for all project files (replace your-username with your actual system username):
      sudo chown -R your-username:staff .
      
    • Grant write access to Laravel’s critical directories:
      chmod -R 755 storage bootstrap/cache
      
  • For Windows users:

    • Right-click your Laravel project folder → Properties → Security tab → Edit.
    • Select your current user account, check the Full Control box under "Allow", then click Apply and OK. Ensure this change applies to all subfolders and files.
  • Now, recreate the server.php file in your project root. Use the default Laravel 5.6 server.php content if you don’t have a backup:

    <?php
    
    $uri = urldecode(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
    );
    
    // This file allows us to emulate Apache's "mod_rewrite" functionality from the
    // built-in PHP web server. This provides a convenient way to test a Laravel
    // application without having installed a "real" web server software here.
    if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }
    
    require_once __DIR__.'/public/index.php';
    

2. Run php artisan serve the Right Way

  • Mac/Linux users: Never run php artisan serve with sudo—this will make root the owner of files, leading to permanent permission locks. Always run it as your regular user account.
  • Alternatively, skip the built-in server entirely: Configure a virtual host in XAMPP’s httpd-vhosts.conf file pointing to your Laravel project’s public directory. This is more stable for local development and avoids permission quirks with the built-in PHP server.

3. Check for Antivirus/Firewall Interference

Some security tools might flag server.php as suspicious and delete it automatically. Check your antivirus’s quarantine or removed files list—if you find server.php there, restore it and add your Laravel project folder to the tool’s trusted list.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:40:28