我使用ubuntu 20, laravel项目运行使用php artisan serve但是当我使用这个URL访问这个网站时,laravel-local.com显示空白页
无法得到任何错误
网站
<VirtualHost *:80>
ServerAdmin admin@MyWebsite.com
DocumentRoot /var/www/html/laravel-local.com/public
ServerName laravel-local.com
<Directory /var/www/html/laravel-local.com/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What I tried
- 给予项目777访问权限
- 更改所有权
- 删除存储/框架内的文件夹
- 更改存储文件夹权限
- composer dump- auload, php artisan cache和config clear
- 删除公共文件夹 中的。htaccess文件
我尝试了以上所有步骤,仍然得到一个空白页
。目录下的htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
。公共文件夹中的htaccess
<IfModule mod_rewrite.c>
Options -Indexes
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
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>
网站
更新:你的vHost配置应该定义在"sites-enabled"对于实际应用的配置。从"sites-enabled"创建一个符号链接到"sites-available"中的实际配置文件。然后重新启动Apache。
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>
您不需要这样的.htaccess
文件(它需要在/public
目录上方的目录中),因为您已经在服务器配置中将/public
目录配置为DocumentRoot
。
如果您还删除了/public
子目录中的.htaccess
文件,那么这将导致重写循环(500错误)。
你只需要在文档根目录下的标准Laravel前端控制器(.htaccess
文件),即。在/public
子目录下。
然而,你应该定义DirectoryIndex
(如果还没有在服务器配置的某个地方设置),无论是在你的vHost (<Directory>
容器)或在你的主Laravel.htaccess
文件的顶部(在/public
文件夹内)。如果没有定义,那么对Laravel目录本身(主页)的请求将不会通过Laravel路由,并且可能会导致来自Apache的403 Forbidden响应(或者更糟,如果启用了Indexes
,则会显示目录列表)。
例如:
DirectoryIndex index.php