Laravel 5.6项目部署至生产环境后无法显示页面求助
Hey there, let's work through this deployment problem—since your local setup runs flawlessly, the issue is almost definitely tied to a production-specific configuration, path mismatch, or permission oversight. Here's a step-by-step breakdown of what to check:
1. Verify index.php Paths Are Correct
This is the most common culprit when moving files to a non-standard directory structure. If your core Laravel files are in a folder next to the server's public directory (e.g., server public/ and Laravel core in laravel_app/), double-check the paths in public/index.php:
// Make sure these paths point to your actual Laravel core directory require __DIR__.'/../laravel_app/bootstrap/autoload.php'; $app = require_once __DIR__.'/../laravel_app/bootstrap/app.php';
Even a tiny typo in the directory name will cause a silent failure.
2. Double-Down on Directory Permissions
You mentioned setting permissions, but Laravel has strict requirements for writable directories. Run these commands from your Laravel core directory to ensure proper access:
# Set write permissions for storage and bootstrap/cache chmod -R 775 storage bootstrap/cache # Assign ownership to your web server user (adjust if using nginx instead of www-data) chown -R www-data:www-data storage bootstrap/cache
Some servers use nginx as the web user instead of www-data—confirm which one your host uses first.
3. Validate Web Server Configuration
For Nginx:
Ensure your server block points to the public directory and includes the correct rewrite rules:
server { listen 80; server_name your-domain.com; root /path/to/server/public; # This must point to the public folder location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # Match your PHP version fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } }
Don't forget to restart Nginx after making changes: sudo systemctl restart nginx
For Apache:
- Confirm
mod_rewriteis enabled:sudo a2enmod rewrite - Ensure the
AllowOverride Alldirective is set for your public directory in Apache's config (or .htaccess is allowed) - Make sure the
.htaccessfile from your localpublic/folder was copied to the server—missing this will break routing.
4. Check Server Error Logs
This is the fastest way to get concrete answers. Silent white screens almost always leave a clue in the logs:
- Apache logs: Typically at
/var/log/apache2/error.log - Nginx logs: Typically at
/var/log/nginx/error.log
Logs will tell you if a file is missing, permissions are wrong, or a PHP extension is missing (yes, even if your local setup has it—production servers might skip extensions likembstringoropenssl).
5. Ensure Your .env File Is Properly Configured
Don't just copy your local .env to production. Create a new one in your Laravel core directory with these critical settings:
APP_ENV=production APP_DEBUG=false # Set to true temporarily only if you need to see errors (then switch back!) APP_KEY=your-generated-key
Generate a new app key if you don't have one: php artisan key:generate (run this from your Laravel core directory on the server).
6. Clear Laravel Caches
Even without a database, Laravel caches config and views. Run these commands to reset everything:
php artisan config:clear php artisan cache:clear php artisan view:clear
Make sure you're running these from the Laravel core directory, and using the server's PHP executable (avoid using a local PHP version via SSH if it doesn't match the server's).
Start with checking the error logs first—they'll cut through the guesswork and point you directly to the problem.
内容的提问来源于stack exchange,提问作者Leon N

