Laravel 5.1现有源码部署后仅显示默认页,求正确部署方案
解决Laravel仅显示默认页面的问题
Hey there, let's work through why your Laravel app is stuck on the default welcome page. First, I'll list the key steps you might have missed, then walk you through a complete, reliable local deployment flow for XAMPP.
一、你可能遗漏的核心操作
- 生成应用密钥:Laravel relies on an app key to encrypt sessions and sensitive data—without it, your custom content might fail to load properly. Run this command:
php artisan key:generate - Clear all caches:Old cached config/routes can prevent your new code from taking effect. Clear them with these commands:
php artisan cache:clear php artisan config:clear php artisan route:clear php artisan view:clear - Check your route definitions:Open
routes/web.phpand make sure your custom app routes are set up correctly. If the default welcome route is still there, it'll override your content. For example, if your homepage uses a controller:// Replace the default welcome route with your own Route::get('/', [HomeController::class, 'index']); - Verify
.envconfiguration:Double-check that your.envfile has the right settings:APP_URL=http://localhost:8000 # Also confirm your database credentials are correct and the database exists DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_db_name DB_USERNAME=root DB_PASSWORD=your_db_password
二、完整的XAMPP本地部署步骤
Follow this step-by-step flow to get your app running:
- Place your Laravel code in
xamp\htdocs\sample - Copy
.env.examplein the project root to a new file named.env, then edit it with your database info andAPP_URL - Open your terminal, navigate to the project directory (
cd xamp\htdocs\sample), then install dependencies (useinstallinstead ofupdateto avoid version conflicts):composer install - Generate your app key (as mentioned earlier):
php artisan key:generate - Run database migrations if you have migration files set up:
php artisan migrate - Clear all caches to ensure fresh config/routes are loaded:
php artisan cache:clear php artisan config:clear - If your app uses file storage, create a symbolic link to make public files accessible:
php artisan storage:link - Start the development server:
php artisan serve - Visit
http://localhost:8000in your browser—you should now see your custom app content instead of the default welcome page.
A quick side note: If you wanted to use XAMPP's Apache server instead of php artisan serve, you'd need to set up a virtual host pointing to sample/public (not the root sample folder). But since you're using the serve command, this isn't necessary right now.
内容的提问来源于stack exchange,提问作者Cherry g
相关产品推荐
相关产品推荐

