Laravel 5 not getting any error logs

archvist picture archvist · Mar 20, 2016 · Viewed 10.1k times · Source

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.

Answer

archvist picture archvist · Mar 20, 2016

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.