php Laravel 空白白屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20678360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel blank white screen
提问by Mico
My laravel site was working before, I recently upgraded to Apache 2.4 and PHP 5.5.7.
我的 laravel 站点以前可以运行,我最近升级到 Apache 2.4 和 PHP 5.5.7。
Now I'm getting a white blank screen when I go to laravel.mydomain.com, nothing in apache error logs, routes and etc. should be fine as it worked before.
现在,当我访问 laravel.mydomain.com 时,我看到一个白色的空白屏幕,apache 错误日志、路由等中的任何内容都应该没问题,因为它以前可以正常工作。
.htaccess is loading as I get a 500 when I insert an invalid line to /var/sites/laravel/public/.htaccess.
.htaccess 正在加载,因为当我向 /var/sites/laravel/public/.htaccess 插入无效行时得到 500。
Heres my .htaccess:
这是我的 .htaccess:
$ cat /var/sites/laravel/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Heres my virtual host directive:
这是我的虚拟主机指令:
DocumentRoot "/var/sites/laravel/public"
ServerName laravel.mydomain.com
<Directory "/var/sites/laravel/public">
AllowOverride All
allow from all
Options +Indexes
Require all granted
</Directory>
And apachectl -S
和 apachectl -S
$ /usr/local/apache2/bin/apachectl -S
VirtualHost configuration:
*:* is a NameVirtualHost
default server mydomain.com (/usr/local/apache2/conf/extra/httpd-vhosts.conf:25)
port * namevhost mydomain.com (/usr/local/apache2/conf/extra/httpd-vhosts.conf:25)
port * namevhost laravel.mydomain.com (/usr/local/apache2/conf/extra/httpd- vhosts.conf:34)
ServerRoot: "/usr/local/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/usr/local/apache2/logs/error_log"
Mutex rewrite-map: using_defaults
Mutex default: dir="/usr/local/apache2/logs/" mechanism=default
PidFile: "/usr/local/apache2/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="daemon" id=1 not_used
Group: name="daemon" id=1 not_used
回答by fideloper
Apache
阿帕奇
Does this answerdescribe or help your situation? Upgrading to Apache 2.4 come with some changes in Apache configuration.
此答案是否描述或帮助您的情况?升级到 Apache 2.4 伴随着 Apache 配置的一些变化。
Laravel
Laravel
Are you checking Laravel's logs or Apache's logs?
你是查看 Laravel 的日志还是 Apache 的日志?
Since upgrading to Laravel 4.1, I've had white screen "errors" (WSOD) when the application could not write to the log location. I've always solved this by making the app/storage directory writable by Apache (either group writable to "www-data", "apache" or world-writable - that depends on your server setup.
自从升级到 Laravel 4.1 以来,当应用程序无法写入日志位置时,我遇到了白屏“错误”(WSOD)。我总是通过使应用程序/存储目录可由 Apache 写入来解决此问题(组可写入“www-data”、“apache”或世界可写入 - 这取决于您的服务器设置。
Web Server User
网络服务器用户
On Ubuntu/Debian servers, your PHP may be running as user "www-data". On CentOS/RedHat/Fedora servers, you PHP may be running as user "apache".
在 Ubuntu/Debian 服务器上,您的 PHP 可能以用户“www-data”的身份运行。在 CentOS/RedHat/Fedora 服务器上,您的 PHP 可能以用户“apache”的身份运行。
Make sure your files are owned by the user that is running PHP:
确保您的文件归运行 PHP 的用户所有:
# Debian/Ubuntu
$ sudo chown -R www-data /path/to/laravel/files
# CentOS/RedHat/Fedora
$ sudo chown -R apache /path/to/laravel/files
Note that you might not be running as user www-data or apache. It depends on your hosting and setup!
请注意,您可能不是以用户 www-data 或 apache 的身份运行。这取决于您的托管和设置!
Laravel 4
Laravel 4
# Group Writable (Group, User Writable)
$ sudo chmod -R gu+w app/storage
# World-writable (Group, User, Other Writable)
$ sudo chmod -R guo+w app/storage
Laravel 5+ (including 6)
Laravel 5+(包括 6 个)
# Group Writable (Group, User Writable)
$ sudo chmod -R gu+w storage
# World-writable (Group, User, Other Writable)
$ sudo chmod -R guo+w storage
#####
# The bootstrap/cache directory may need writing to also
##
# Group Writable (Group, User Writable)
$ sudo chmod -R gu+w bootstrap/cache
# World-writable (Group, User, Other Writable)
$ sudo chmod -R guo+w bootstrap/cache
回答by EddardOmeka
An update to fideloper's answer for Laravel 5 and its new file structure is:
fideloper 对 Laravel 5 及其新文件结构的回答的更新是:
$ sudo chmod -R o+w storage/
回答by Mukesh Chapagain
The following steps solved blank white screen problem on my Laravel 5.
以下步骤解决了我的 Laravel 5 上的空白白屏问题。
- Go to your Laravel root folder
- Give write permission to
bootstrap/cacheandstoragedirectories
- 转到您的 Laravel 根文件夹
- 授予对
bootstrap/cache和storage目录的写权限
sudo chmod -R 777 bootstrap/cache storage
sudo chmod -R 777 引导程序/缓存存储
- Rename
.env.exampleto.env - Generate application key with the following command in terminal/command-prompt from Laravel root:
- 重命名
.env.example为.env - 从 Laravel 根目录在终端/命令提示符中使用以下命令生成应用程序密钥:
php artisan key:generate
php工匠密钥:生成
This will generate the encryption key and update the value of APP_KEYin .envfile
这将生成加密密钥和更新的值APP_KEY在.env文件
This should solve the problem.
这应该可以解决问题。
If the problem still exists, then update config/app.phpwith the new key generated from the above artisan key generate command:
如果问题仍然存在,则config/app.php使用上述 artisan key generate 命令生成的新密钥进行更新:
'key' => env('APP_KEY', 'SomeRandomString'),to
'key' => env('APP_KEY', 'KEY_GENERATED_FROM_ABOVE_COMMAND'),
'key' => env('APP_KEY', 'SomeRandomString'),到
'key' => env('APP_KEY', 'KEY_GENERATED_FROM_ABOVE_COMMAND'),
回答by CG_DEV
Try this, in the public/index.php page
试试这个,在 public/index.php 页面
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set("display_errors", 1);
回答by Hassan Gilak
for anyone who get blank page even after making storage accessible for displaying errors put these two lines at first lines of public/index.php to see what is happening at least. for me this error was there :Class 'PDO' not found in /var/www/***/config/database.php on line 16
对于即使在使存储可访问以显示错误后仍获得空白页面的任何人,请将这两行放在 public/index.php 的第一行,以查看至少发生了什么。对我来说,这个错误是存在的:在第 16 行的 /var/www/***/config/database.php 中找不到 Class 'PDO'
error_reporting(E_ALL);
ini_set('display_errors', 1);
回答by Vikash
When I was new to Linux.I usually found this error with my Laravel Project. White errors means error, It may have some permission issue or error.
当我刚接触 Linux 时,我通常会在我的 Laravel 项目中发现这个错误。白色错误表示错误,它可能有一些权限问题或错误。
You just have to follow two steps, and will work like champ :)
你只需要遵循两个步骤,就会像冠军一样工作:)
(1) Give the permission. Run these command from root directory of your project
(1) 给予许可。从项目的根目录运行这些命令
(a) sudo chmod 777 -R storage
(b) sudo chmod bootstrap/cache
(2) If you cloned the project or pulled from github then run
(2)如果你克隆了项目或者从github拉取然后运行
composer install
(3) Configure your .env file properly, and your project will work.
(3) 正确配置你的 .env 文件,你的项目就可以运行了。
回答by Kamkat86
I was struggling with a similar issue on a CentOS server. Using php artisan serv and accessing it through port 8000 on the local machine worked fine but could not get my remote machines to load a particular view. I could return strings fine, and some views were loading. Chased my tail on permissions for a while before I finally realized it was an SELinux issue. I just set it from enforce to permissive and it worked. Hope that helps someone else out there that may be encountering the same issue.
我在 CentOS 服务器上遇到了类似的问题。使用 php artisan serv 并通过本地机器上的端口 8000 访问它工作正常,但无法让我的远程机器加载特定视图。我可以很好地返回字符串,并且正在加载一些视图。在我终于意识到这是一个 SELinux 问题之前,我在权限上追了一段时间。我只是将它从强制设置为许可,并且它起作用了。希望可以帮助其他可能遇到相同问题的人。
setenforce permissive
回答by qskane
In my case , I have installed laravelmany times, and I am sure that the folder write permission has been correctly given.
就我而言,我已经安装了laravel很多次,并且我确定已正确授予文件夹写入权限。
Like most of the answers above :
像上面的大多数答案一样:
sudo chmod 777 -R storage bootstrap
The mistake is that my nginx configuration comes from the official documentation.
错误是我的nginx配置来自官方文档。
I only modified the domain name after copying ,then I got a blank page.
I tried restarting nginxand php-fpm,but not work for me.
我只是复制后修改了域名,然后我得到了一个空白页。我试图重新启动nginx和php-fpm,但不是为我工作。
Finally, I added this line configuration to solve the problem.
最后,我添加了这个线路配置来解决问题。
location ~ \.php$ {
# same as documentation ...
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
I hope I can help others.
我希望我能帮助别人。
回答by Boris Tet?ev
I have also one more option why blank page issue may occur. If you are on production mode and if you cached your config files by php artisan (config:cache), try to delete cache file executing:
我还有一个选择为什么可能会出现空白页问题。如果您处于生产模式并且您通过 php artisan (config:cache) 缓存了配置文件,请尝试删除缓存文件执行:
php artisan config:clear
or delete it manualy (bootstrap/cache/config.php)
或手动删除(bootstrap/cache/config.php)
回答by Andrew
Running this command solved it for me:
运行此命令为我解决了它:
php artisan view:clear
I guess a blank error page was some how cached. Had to clear the caches.
我猜一个空白的错误页面是某种缓存方式。必须清除缓存。

