Laravel 5.6新安装执行php artisan serve时server.php被删除致无法访问
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-folderFor Mac/Linux users:
- Set proper ownership for all project files (replace
your-usernamewith your actual system username):sudo chown -R your-username:staff . - Grant write access to Laravel’s critical directories:
chmod -R 755 storage bootstrap/cache
- Set proper ownership for all project files (replace
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.phpfile in your project root. Use the default Laravel 5.6server.phpcontent 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 servewithsudo—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.conffile pointing to your Laravel project’spublicdirectory. 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

