【问题标题】:How to upload the laravel project on cpanel?如何在cpanel上上传laravel项目?
【发布时间】:2026-01-14 12:30:02
【问题描述】:

如何仅使用 .Htaccess 文件在 cpanel 上上传 larval 项目。我已经看到了更多的例子,但没有正常工作。这是抛出错误是此页面无法正常工作。我将我的项目放在http://www.domainname.com/laravelproject 中。在这里面,我们更改了 public 文件夹中的 index.php 文件。

文件是这个-

<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>

public/index.php

require __DIR__.'/../filename/vendor/autoload.php';
$app = require_once __DIR__.'/../filename/bootstrap/app.php';

【问题讨论】:

  • 谢谢你,但我想把我的项目放在 Public_html 文件夹而不是这个文件夹之外

标签: laravel cpanel


【解决方案1】:

根据我目前的经验,当您完成项目编码时

  1. 在 public_html 之外创建一个文件夹。你可以称它为“项目”

  2. 复制所有项目文件并上传到创建的项目文件夹中。

  3. 在你的 laravel 项目中打开 public 文件夹,将包括 .htaccess 和 index.php 文件在内的所有文件复制到 public_html 文件夹中。

  4. 然后打开 index.php 文件并将以下内容更改为指向您创建的项目文件夹。

    define('LARAVEL_START', microtime(true));

    需要DIR.'/../project/vendor/autoload.php';

    $app = require_once DIR.'/../project/bootstrap/app.php';

    $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

    $response = $kernel->handle( $request = 照亮\Http\Request::capture() );

    $response->send();

    $kernel->terminate($request, $response);

【讨论】:

    【解决方案2】:
    in your case, http://www.domainname.com/laravelproject   
    
    1. create a folder name "project"  outside of the public_html and place all the laravel files inside it. 
    
    2. also create a folder name laravelproject inside public_html/laravelproject. 
    
    3. then open the laravel public folder inside "project" folder and copy all the files to the public_html/laravelproject. 
    
    4. open index.php inside public_html/laravelproject and change the  
    
      require DIR.'/../../project/vendor/autoload.php';
      $app = require_once DIR.'/../../project/bootstrap/app.php';
    
      or
    
      require DIR.'/../project/vendor/autoload.php';
      $app = require_once DIR.'/../project/bootstrap/app.php';
    

    【讨论】: