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

Laravel 5.5项目上传共享服务器失败,求助解决方法

Troubleshooting Laravel 5.5 Deployment on Shared Hosting

Hey there, let's work through this deployment issue together—you're already on the right track by separating your core Laravel files from the public web root, so let's tackle the common snags that might be holding you back.

1. Double-Check Your index.php Paths

First, confirm you've updated the two critical paths in public_html/index.php correctly. They should point directly to your mascotas folder like this:

// Autoloader
require __DIR__.'/../mascotas/vendor/autoload.php';

// Bootstrap the app
$app = require_once __DIR__.'/../mascotas/bootstrap/app.php';

Double-check the folder name spelling (mascotas) and make sure it’s truly at the same level as public_html (not nested inside it). If your hosting uses a quirky directory structure (like public_html inside a www folder), you might need to adjust the path to ../../mascotas instead—use FTP to verify the exact layout.

2. Fix Folder Permissions

Laravel needs write access to two key folders to function properly:

  • mascotas/storage
  • mascotas/bootstrap/cache

If you have SSH access, run these commands from your user root directory:

chmod -R 755 mascotas/storage mascotas/bootstrap/cache

If you’re using FTP, right-click each folder, set permissions to 755 (use 775 if 755 doesn’t work—avoid 777 unless absolutely necessary, as it’s a security risk).

3. Don’t Forget the .env File

Copy your project’s .env file into the mascotas folder (it’s often excluded from zip exports or git pushes, so you might have missed it). Update these critical values:

  • APP_URL: Set to your actual domain (e.g., http://yourdomain.com)
  • Database credentials (DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD): Match your hosting provider’s database details exactly.

Without this file, Laravel will default to invalid settings and throw random errors.

4. Clear Laravel Caches (Critical for 5.5)

Older Laravel versions like 5.5 hold onto local cache data that breaks on the server. Here’s how to clear it:

  • With SSH: Navigate to the mascotas folder and run:
    php artisan config:clear
    php artisan cache:clear
    php artisan route:clear
    
  • Without SSH: Manually delete all files inside mascotas/bootstrap/cache (leave .gitignore if it exists).

5. Verify PHP Version Compatibility

Laravel 5.5 requires PHP 7.0.0 or higher. To check your server’s version:

  1. Create a file public_html/phpinfo.php with this content:
    <?php phpinfo(); ?>
    
  2. Visit http://yourdomain.com/phpinfo.php and look for the PHP version line.
  3. If it’s too low, use your hosting control panel to switch to a supported version (most hosts let you do this in a "PHP Settings" section).

6. Ensure mod_rewrite is Enabled

If you’re getting 404 errors for routes (but the homepage loads), mod_rewrite might be disabled. Most shared hosts enable it by default, but if not:

  • Check your hosting control panel for an Apache settings option to turn it on.
  • Or, contact your host’s support team to enable it.

Also, make sure your public_html/.htaccess file has the default Laravel rules (replace it if needed):

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

7. Check Server Error Logs

If none of the above works, dig into the server’s error logs—they’ll tell you exactly what’s wrong. Look for:

  • An "Error Logs" section in your hosting control panel.
  • A file named error_log inside public_html.

Logs might show missing files, permission issues, or database connection failures—this is the fastest way to pinpoint the problem.


内容的提问来源于stack exchange,提问作者Felipe Castillo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:24:11