mlusas's avatar

Fixing HTTP ERROR 500 (nginx) for every Laravel route

I am getting an error of:

The page isn’t working is currently unable to handle this request. HTTP ERROR 500

When going to http://

I've switched my servers from Ubuntu 14.04 (on DigitalOcean) to Ubuntu 16.04 (on Linode). I used Rocketeer to deploy. While on my previous servers, everything worked. But for some reason, Laravel is not even giving me practical errors to solve. The route is be hitting is; Route::get('/', 'MainWebController@index');

However, if I go to http:///images/pinpoint.png, I can see the image. So it seems the routes are not working for some reason, and Laravel is not sending down useful errors, even though .env is set with: APP_ENV=production APP_DEBUG=true

I appreciate any help you can offer to get Laravel working correct. Thank you,

0 likes
9 replies
mlusas's avatar

Oh, and I forgot to mention, but I was running php5 before, and am now running php7, just in case that makes a difference.

usama.ashraf's avatar

Try putting this in your conf at location:

try_files $uri $uri/ /index.php$is_args$args;

Then restart Nginx of course.

mlusas's avatar

@usama.ashraf Thank you for the quick reply. I just tried changing that in my conf file, and it had no effect. I previously had

try_files $uri $uri/ /index.php?$query_string;

which worked on my previous server. However, I just looked in my /var/log/nginx/error.log file, and found this:

2016/07/14 07:36:38 [error] 19569#19569: *65 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/www/<domain.com>/production/releases/2$
Stack trace:
#0 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13762): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13522): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13620): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)
#3 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13315): Monolog\Logger->error(Object(UnexpectedValueException), Array)
#4 /var/www/cos...
PHP message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/www/<domain.com>/production/releases/20160714071609/storage/logs/laravel.log" could not be opened: failed to$
Stack trace:
#0 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13762): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13522): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/compiled.php(13620): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#3 /var/www/<domain.com>/production/releases/20160714071609/bootstrap/cache/com

I'm just starting to investigate what this could be pointing to. Any immediate thoughts when you see this?

mlusas's avatar

Update, but still not working:

sudo chown www-data:deploy <laravel_directory>/storage/logs/laravel.log

has brought back "Whoops, looks like something went wrong." errors. But still no actual errors to review. But I may be on to a fix.

usama.ashraf's avatar
php artisan cache:clear
php artisan clear-compiled
sudo chmod -R 777 storage
composer dump-autoload
php artisan optimize
4 likes
mlusas's avatar

@usama.ashraf Woohoo!!!!! Awesome. That got me a step closer. Now I'm trying to overcome an issue that seems to have a simple fix...but looks are deceiving:

RuntimeException in EncryptionServiceProvider.php line 45:
No supported encrypter found. The cipher and / or key length are invalid.

I've run

php artisan key:generate
sudo chown root:deploy -h .env

And the .env file was updated correctly. But it seems like it's able to read the .env file. Also, www-data is in the deploy group. Any thoughts?

usama.ashraf's avatar

Make sure you have all these:

  • OpenSSL PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
1 like
mlusas's avatar
mlusas
OP
Best Answer
Level 4

Woohoo!!! And @usama.ashraf shoots and scores! Laravel is working properly now. Thank you so much for the quick turnaround and help. I actually made you a fun meme, and then realized that the image embedding is no longer available on these threads. :(

Here's the final code that got everything working:

sudo gpasswd -a www-data deploy
sudo chown www-data:deploy <laravel_directory>/storage/logs/laravel.log
sudo chown root:deploy -h <laravel_directory>/.env
sudo chown www-data:deploy -R <laravel_directory>/bootstrap

php artisan key:generate
php artisan cache:clear
php artisan clear-compiled

sudo chmod -R 777 <laravel_directory>/storage
sudo chmod -R 775 <laravel_directory>/bootstrap

composer dump-autoload
php artisan optimize

sudo apt-get install php-tokenizer
sudo apt-get install php-mbstring
sudo apt-get install php-openssl
sudo systemctl restart php7.0-fpm

Then.... magic!

2 likes

Please or to participate in this conversation.