Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 not getting any error logs

I installed Laravel 5 on a new VPS, I was running everything fine but I noticed I wasn't getting any Laravel errors the system would only fire a server 500 error at me which is no help when debugging my code.

When I looked in the laravel storage/log it was empty which was strange because I had set the correct file permissions of 777.

So how do I get laravel logs? Why aren't they being written to my storage/log file.

like image 316
archvist Avatar asked Mar 20 '16 11:03

archvist


People also ask

How do I enable error reporting in Laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.

Where is the Laravel error log?

By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel.

What is log :: info in Laravel?

By default, Laravel is configured to create daily log files for your application which are stored in the storage/logs directory. You may write information to the log like so: Log::info('This is some useful information. '); Log::warning('Something could be going wrong.

What is error log in Laravel?

Logging is an important mechanism by which system can log errors that are generated. It is useful to improve the reliability of the system. Laravel supports different logging modes like single, daily, syslog, and errorlog modes. You can set these modes in config/app. php file.


1 Answers

If you've set your file permissions correctly on the /storage file directory and you're running on a VPS not shared hosting you might want to check your apache log, inside var/log/apache2/error.log

Here you might just see a line that read something along the lines of /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Well this is strange because you have the correct file permissions...

Let's start by SSH'ing into your VPS head to the directory where laravel is installed normally cd /var/www/html

In here if you run ls -l You should get some results similar to this image below: enter image description here

Notice how we've been accessing the site as the root user, this is our problem and we can confirm this by running ps aux | grep apache2

enter image description here

You can see here apache2 is running as the user www-data, which is normal for apache. Which means when our laravel installation trys to move files either using ->move() or just trying to write the log file it fails as the www-data user doesn't have permission. So you can change to this www-data user by running: chown -R www-data:www-data * (shorthand for same user/group chown -R www-data. *)

Now if you run ls -l in your www/html directory you should see root user changed to www-data:

enter image description here

This means were now editing the files as the www-data user which has permission, so any changes you make via SFTP should reflect this user change. Fixed!

Edit - This is the first time I answered my own question hopefully it's okay.

like image 172
archvist Avatar answered Sep 18 '22 00:09

archvist