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.
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.
By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/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.
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.
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:
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
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With