Inspired by Laravel, bugged by file permission

Before it worked and the light came up, It was first like a darkside to troubleshoot, I had to change ownership of the new Laravel project to :www-data with

# chown -R :www-data /var/www/html/player/

This was done after I had used:

# chmod -R 775 /var/html/player/storage/*

And:

# chmod -R 775 /var/html/player/vendor/*

If I had earlier stumbled upon this exact configuration in the Laravel 5.0 documentation where this is written (even though I was working with 5.2), I would have saved a lot of time and not (learn the hard way) to check the simplest of information.

Laravel may require some permissions to be configured: folders within storage and vendorrequire write access by the web server.

I was although able to finally hit the nail on the head to break the deadlock when I navigated through some Stackoverflow‘s questions and answers searching the above sentence on Google, but was able to find it here and just at the end of this.
Okay, not to give the scenario of what happened, what I faced and how I was able to get it done:

The /player directory is the directory where the Laravel boilerplate and directives are for the music player project idea I conceived and since I just began with Laravel, I find it interesting to never do a normal php project again therefore, I chose to do it again. What am I doing again? It is to create a new Laravel project.

Having gone through the rigor of getting out of my comfort zone of writing php without frameworks, I realize I could have learnt a lot of things and made my development life easier and fantastic with using a good framework like Laravel (even though I had a taste of this with Ruby on Rails). Much has been said about this framework already by friends and so I decided to try it out.

To cut the story short, I managed to get my first Laravel project running which I named blog because I was following the courses Introduction to Laravel 5.2 from a Udemy tutorial I found on Youtube. Now it was time to unleash the beast and simply make my office period more interesting with my own personalized and customized music player after I had followed the Laravel 5.2 documentation to install using Composer and had created an Apache configuration file as well, then to access my new http://player.mine URL became a bit of work. What here did I do wrong?

Even though I had done an update with composer update and had set my configuration for Apache to use my Laravel’s project /public directory, yet it would not work. The next thing I tried was setting the same server name in my /etc/hosts file with:

127.0.0.1 localhost
127.0.0.1 player.mine

This resulted in a blank page (testing on Mozilla Firefox). Even though I checked if there were errors in my Apache configuration and also ensure I enabled with a2ensite player.conf yet It was to no avail. The major mistake I did was to not check the log. I came to my senses then checked Apache’s error log: there I found this error being thrown the last times I had loaded the page:

 

HP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/html/player/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/html/player/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /var/www/html/player/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /var/www/html/player/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /var/www/html/player/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\\Logger->addRecord(400, Object(UnexpectedValueException), Array)\n#3 /var/www/html/player/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\\Logger->error(Object(UnexpectedValueException), Array)\n#4 /var/www/html/player/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\\Log\\Writer->writeLog('error', Object(UnexpectedValueException in /var/www/html/player/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

So I realized that the issue was file permission for the Laravel project.

I wouldn’t say this is the perfect solution to this issue because I have seen some other several suggestions of how it could be fixed but by this experience it is most likely one of it. If you have any supposed better way out you can help suggest in the the comment.

Thanks for reading 🙂

This is #tobisoft #omisakinoluwatobisamuel