Laravel Logs generated by crontab permission denied

I had a problem with logs being generated by crontab not being accessible by my server user.  The reason was that the crontab was being run by the ec2-user and the apache user is the user the web application uses to access an hit logs and such on the server.  The was especially bothersome since I have some custom logging being generated by my ap (Login metrics and such).  Anytime the log was generated by the cron then the log was inaccessible.

Solution

In order for my log to have the correct permissions I had to run the cron with that user.  That meant I had to create a crontab specifically for that user (I had no idea the crontab had a user!).  In this instance I needed a cron job being run by the apache user.  To create an apache user crontab run:

sudo crontab -u apache -e

This will bring up a crontab that is executed by user apache.

In my instance I wanted a cron job executing the laravel scheduler

 * * * * * cd /var/www/html/project_folder && php artisan schedule:run >> /dev/null 2>&1

What this gave me was a log created by the apache user which the app could then access.

You may also like...