简体   繁体   中英

Laravel blank white screen

My Laravel site was working before, I recently upgraded to Apache 2.4 and PHP 5.5.7.

Now I'm getting a white blank screen when I go to laravel.mydomain.example , nothing in Apache error logs, routes and etc. should be fine as it worked before.

.htaccess is loading as I get a 500 when I insert an invalid line to /var/sites/laravel/public/.htaccess .

Heres my .htaccess :

$ cat /var/sites/laravel/public/.htaccess
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [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.example
<Directory "/var/sites/laravel/public">
    AllowOverride All
    allow from all
    Options +Indexes
    Require all granted
</Directory>

And apachectl -S

$ /usr/local/apache2/bin/apachectl -S
VirtualHost configuration:
*:*                    is a NameVirtualHost
     default server mydomain.example (/usr/local/apache2/conf/extra/httpd-vhosts.conf:25)
     port * namevhost mydomain.example (/usr/local/apache2/conf/extra/httpd-vhosts.conf:25)
     port * namevhost laravel.mydomain.example (/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

Apache

Does this answer describe or help your situation? Upgrading to Apache 2.4 come with some changes in Apache configuration.

Laravel

Are you checking Laravel's logs or Apache's logs?

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.

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

Make sure your files are owned by the user that is running 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!

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)

# 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

fideloper 对 Laravel 5 的回答及其新文件结构的更新是:

$ sudo chmod -R o+w storage/

Try this, in the public/index.php page

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set("display_errors", 1);

The following steps solved blank white screen problem on my Laravel 5.

  • Go to your Laravel root folder
  • Give write permission to bootstrap/cache and storage directories

sudo chmod -R 777 bootstrap/cache storage

  • Rename .env.example to .env
  • Generate application key with the following command in terminal/command-prompt from Laravel root:

php artisan key:generate

This will generate the encryption key and update the value of APP_KEY in .env file

This should solve the problem.

If the problem still exists, then update config/app.php with the new key generated from the above artisan key generate command:

'key' => env('APP_KEY', 'SomeRandomString'),

to

'key' => env('APP_KEY', 'KEY_GENERATED_FROM_ABOVE_COMMAND'),

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

error_reporting(E_ALL);
ini_set('display_errors', 1);

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

or delete it manualy (bootstrap/cache/config.php)

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.

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.

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

(a) sudo chmod 777 -R storage
(b) sudo chmod bootstrap/cache

(2) If you cloned the project or pulled from github then run

composer install

(3) Configure your .env file properly, and your project will work.

Facing the blank screen in Laravel 5.8. Every thing seems fine with both storage and bootstrap folder given 777 rights. On

php artisan cache:clear

It shows the problem it was the White spaces in App Name of .env file

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.

setenforce permissive

In my case , I have installed laravel many times, and I am sure that the folder write permission has been correctly given.

Like most of the answers above :

sudo chmod 777 -R storage bootstrap

The mistake is that my nginx configuration comes from the official documentation .

I only modified the domain name after copying ,then I got a blank page. I tried restarting nginx and php-fpm ,but not work for me.

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.

它显示问题是 .env 文件的应用程序名称中的空格

In general if Laravel showing you white page without error first thing looking in the .evn file for error my wrong was.

The problem was in .env file in APP_NAME

Just i replaced

APP_NAME=My Project Name 

to

APP_NAME="My Project Name"

It took me almost 2 hour to solve this problem. These are reasons find out in answers:

  • Remove space in .env file
  • Rewrite .htaccess
  • chmod 777 storage / bootstrap folder
  • Remove vendor folder and run composer install again
  • Restart apache/nginx server
  • php artisan view:clear
  • php artisan cache:clear
  • php artisan route:clear

I tried everything but it still doesn't working.

Turn out the default port for apache/nginx server is not PORT 80. When you installed webpack, it may be changed because of corrupting with Skype or system services. So instead of access to yoursite.test on localhost , you must use yoursite.test:85 which 85 is the default PORT of apache/nginx server.

I have some issues to setup it in a Vagrant machine. Whats really works for me was execute a:

chmod -R o+w app/storage/

from inside the Vagrant machine.

Reference: https://laracasts.com/lessons/vagrant-and-laravel

Another thing that may cause the WSOD is missing the 'return' keyword, as in:

return View::make('yourview');

as opposed to

View::make('yourview');

Sometimes it's because laravel 5.1 require PHP >= 5.5.9. Update php will solve the problem.

对我来说很奇怪,但就我而言,我必须清除 laravel 的缓存才能解决问题。

Blank screen also happens when your Laravel app tries to display too much information and PHP limits kick in (for example displaying tens of thousands of database records on a single page). The worst part is, you won't see any errors in the Laravel logs. You probably won't see any errors in the PHP FPM logs as well. You might find errors in your http server logs, for example nginx throws something like FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of XXX bytes exhausted .

Short tip: add ->limit(1000) where 1000 is your limit, on your query object.

I also faced same issue after doing composer update

I tried installing composer required monolog/monolog too but didn't work.

Then I removed the /vendor directory and ran composer install and worked as per normal.

basically it must have reverted my monolog and other stable packages version back to previous. so better not to composer update

what I noticed comparing both the /vendor folders and found those classes files under /vendor/monolog/monolog/src/Handler were missing after composer updated.

use this .htaccess to solve

Options +ExecCGI
addhandler x-httpd-php5-cgi .php
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# 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]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

There might be a lot of reasons behind the blank screen without errors. I have faced this problem many times whenever I want to upload laravel project in shared hosting.

Reason: Incorrect PHP Version

In my case, issue was because of incorrect php version. I had php 7.1 version in local computer where as in shared hosting cpanel, there was php 5.6 version. Switching up the version from 5.6 to 7.1 worked for me.

You can change php version in cpanel from multiphp manager available in cpanel home page.

Sometimes in route.php you may have

Route::get('/{id}', 'Controller@show'..

written before

Route::get('/add', 'Controller@add'..

It can be empty method Controller::show() when you begin to develop your controller from scratch. In this case you will get empty blank page when requesting /add url. It happens because the request was handled by /{id} route, and its method returns nothing.

Just try to place /add route before /{id}

Make sure that there are no typos in your .env file. This was the cause of a blank screen with me.

Nothing got logged to screen nor logfiles or nginx logs. Just a blank screen.

Other problem with the same behavior is use Laravel 3 with PHP 5.5.x. You have to change some laravel function's name "yield() because is a reserved word in php 5.5

如果您忘记将以下代码放在handle函数的末尾,原因可能是Middleware

return $next($request);

I was also getting same error when I start first time on laravel + Ubuntu 14.04 I just right click on bootstrap and storage folder >>> properties >>>permission>> Others Access >>> change it to "Create and delete files" Change permission for enclosed files

Thank you

Got this from the Laravel forums, but if you recently upgraded Laravel versions AND PHP versions AND are running nginx, make sure you have changed your nginx configuration file to reflect the new PHP version. For instance:

In your nginx site config file (here: /etc/nginx/sites-available), change

fastcgi_pass unix:/var/run/php5-fpm.sock;

to

fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;

I have same issue. I already change chmod folder for Storage folder. fill database settings in .env, but didn't fix the problem. I used Laravel 5.5 and I used PHP 5.6, to fix it I went to (cpanel->PHP Selector) and I changed to PHP 7.1 And the issue is done.

On normal cases errors should be logged Unless

Script can't write to log file

  • check it's path
  • permissions

Or error occurred on higher level check app server logs like Appache ||Nginx

Or it's resources limits Like PHP ini settings

memory_limit
max_input_time
max_execution_time

Or OS limit's and so on

In addition to Permission problems in storage and cache folder and php version issues, there could be another reasons to display blank page without any error message.

For example, I had a redeclare error message without any log and with blank white page. There was a conflict between my own helper function and a vendor function.

I suggest as a starting point , run artisan commands. for example:

php artisan cache:clear

If there was a problem, it will prompted in terminal and you've got a Clue and you can google for the solution.

I hit this problem when I tried to run a Laravel 5.8 app on my server, uploading from local development using Vagrant Homestead. After a while I figured out that the dev subdomain on the live server I was running was somehow set to PHP 5.6.

cPanel > MultiPHP Manager > Set to PHP 7.2

fixed this for me. Hope this might help someone.

in my case, the BLANK WHITE SCREEN issue was as simple as a typo or wrong character on the env file. I was implementing socialite, so when I was setting up the .env credentials for Google+ like this:

G+_CLIENT_ID = Your G+ Client ID
G+_CLIENT_SECRET = Your G+ Client secret
G+_REDIRECT = 'http://localhost:8000/callback/google'

But, the .env file can't use the '+' sign, so I have to make this correction:

GOOGLE_CLIENT_ID = Your G+ Client ID
GOOGLE_CLIENT_SECRET = Your G+ Client secret
GOOGLE_REDIRECT = 'http://localhost:8000/callback/google'

I hope this help you find a dumb error...

In my case, restarting apache fixed the problem. for Ubuntu / Debian:

sudo service apache2 restart

This changes works for my localhost Ubuntu server 14.xx setting

# Apply all permission to the laravel 5.x site folders     
$ sudo chmod -R 777 mysite

Also made changes on site-available httpd setting Apache2 settings

Add settings:

Options +Indexes +FollowSymLinks +MultiViews
Require all granted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM