.htaccess 服务器错误500服务器错误

7xzttuei  于 2022-11-16  发布在  其他
关注(0)|答案(3)|浏览(228)

我已经上传了我的laravel项目文件夹到cpanel主机中。我已经在这里做了很多例子,但是仍然得到了著名的500内部错误。这是我所做的:
我已经在我的laravel项目中分离了public文件夹,并将其放入我的public_html文件夹。我已经将我的laravel项目的其余部分放入了myapp文件夹。
到我的public_html文件夹中,我修改了下面这几行:

require __DIR__.'/../myapp/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../myapp/bootstrap/app.php';

这是我的.env文件:

APP_NAME=Driveostle
APP_ENV=local
APP_KEY=base64:xxx
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://www.driveostle.ma

这是我的.htaccess文件:

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

    RewriteEngine On

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

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

这是我的server.php文件:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

我仍然得到HTTP错误500后,键入我的域名。
在这里搜索后,我发现有人要求通过添加以下代码来编辑.htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

我得到的错误是不同的:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@driveostle.ma to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

另外,我的PHP选择器版本在Cpanel中,我已经选择了7.1版本。
在我的composer.json文件中:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "mews/purifier": "^2.0"
    },
...

我不知道什么是错过了我的配置,这是我第一次主持一个laravel网站,我希望我已经张贴的元素会给予你一个想法,我错过了什么.
如果你需要任何文件内容,我会很高兴地张贴它。
谢谢你

z6psavjg

z6psavjg1#

我已经在共享主机(cPanel)上部署了很多次Laravel应用程序,我创建了一个文档,这样我就可以帮助我的开发伙伴,试试这个
Deploying your Laravel Application to a Shared Hosting (cPanel)

ifsvaxew

ifsvaxew2#

我可能会晚到这一点,但为未来的参考,你可以检查php版本,并尝试改变它

ar5n3qh5

ar5n3qh53#

我遇到了同样的情况,我不得不将以下代码添加到AppServiceProvider Boot 部分:

public function boot()
    {
        $this->app->bind('path.public', function() {
        return base_path().'/../public_html';
        });
    }

我希望这对任何有同样问题的人有帮助。

相关问题