Laravel 在共享主机服务器上 returns 错误 500
Laravel on a shared hosting server returns error 500
我使用的是共享托管服务器,我安装了我的第一个 Laravel 5.4 应用程序,一切仍然正常。几天前,我在不同域但同一台服务器上安装了另一个 Laravel 5.4 应用程序,但是当我尝试访问 URL 时,我得到 500 INTERNAL SERVER ERROR
。
下面是我的 .htaccess
代码
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
</IfModule>
我也尝试了以下,但同样的错误:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [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>
您将不应该做的所有内容都移到了 public_html
文件夹中。只有 /public
内的文件需要在 public_html
中,因此名称为 public
。 Laravel 文件应该放在更高的目录中,它不能从 public.
访问
- 使用 Softaculous 安装 Laravel,或在
/home/username/laravel
中通过 SSH 使用 composer
- 将
/home/username/public_html
文件夹中的所有内容移动到
/home/username/laravel
- 将
/home/username/laravel/public
中的所有内容移动到 /home/username/public_html
并在移动后删除 public 文件夹。
- 编辑此文件:
/home/username/public_html/index.php
- 改为
require '/home/username/laravel/vendor/autoload.php';
- 改为
$app = require_once '/home/username/laravel/bootstrap/app.php';
保存此文件并关闭 window。
编辑此文件:/home/username/laravel/server.php
改为:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
将 username
替换为您的主机用户名。 :)
我使用的是共享托管服务器,我安装了我的第一个 Laravel 5.4 应用程序,一切仍然正常。几天前,我在不同域但同一台服务器上安装了另一个 Laravel 5.4 应用程序,但是当我尝试访问 URL 时,我得到 500 INTERNAL SERVER ERROR
。
下面是我的 .htaccess
代码
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
</IfModule>
我也尝试了以下,但同样的错误:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [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>
您将不应该做的所有内容都移到了 public_html
文件夹中。只有 /public
内的文件需要在 public_html
中,因此名称为 public
。 Laravel 文件应该放在更高的目录中,它不能从 public.
- 使用 Softaculous 安装 Laravel,或在
/home/username/laravel
中通过 SSH 使用 - 将
/home/username/public_html
文件夹中的所有内容移动到/home/username/laravel
- 将
/home/username/laravel/public
中的所有内容移动到/home/username/public_html
并在移动后删除 public 文件夹。 - 编辑此文件:
/home/username/public_html/index.php
- 改为
require '/home/username/laravel/vendor/autoload.php';
- 改为
$app = require_once '/home/username/laravel/bootstrap/app.php';
保存此文件并关闭 window。
编辑此文件:
/home/username/laravel/server.php
改为:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) { return false; } require_once '/home/username/public_html/index.php';
composer
将 username
替换为您的主机用户名。 :)