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

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.php and 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 .env configuration:Double-check that your .env file 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:

  1. Place your Laravel code in xamp\htdocs\sample
  2. Copy .env.example in the project root to a new file named .env, then edit it with your database info and APP_URL
  3. Open your terminal, navigate to the project directory (cd xamp\htdocs\sample), then install dependencies (use install instead of update to avoid version conflicts):
    composer install
    
  4. Generate your app key (as mentioned earlier):
    php artisan key:generate
    
  5. Run database migrations if you have migration files set up:
    php artisan migrate
    
  6. Clear all caches to ensure fresh config/routes are loaded:
    php artisan cache:clear
    php artisan config:clear
    
  7. If your app uses file storage, create a symbolic link to make public files accessible:
    php artisan storage:link
    
  8. Start the development server:
    php artisan serve
    
  9. Visit http://localhost:8000 in 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:33:37