简体   繁体   中英

Laravel 5.6 - permission denied on logs/laravel.log ubuntu xenial 16.04

Have visited topics on this before to no avail - struggling to get rid of a permissions error "Failed to open stream" on logs/laravel.log, the only thing that works at the moment is setting directory permissions to 777, that of course in a live server production environment is extremely bad practice.

I've followed practically every tutorial, like this one for example is the most recent I've come across:

https://vijayasankarn.wordpress.com/2017/02/04/securely-setting-file-permissions-for-laravel-framework/

and this

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

Generally speaking, some checks I've carried out include checking ownership/groups by running

ps aux | egrep '(apache|httpd)'

which returns the following results

root      6723  0.0  0.4  77944  4880 ?        Ss   14:53   0:00 /usr/sbin/apache2 -k start
www-data  6726  0.0  0.6 432716  6708 ?        Sl   14:53   0:00 /usr/sbin/apache2 -k start
www-data  6727  0.0  0.6 432772  6696 ?        Sl   14:53   0:00 /usr/sbin/apache2 -k start
ubuntu    6874  0.0  0.0  12948   948 pts/0    S+   15:07   0:00 grep -E --color=auto (apache|httpd)

So I know my server is owned by www-data - even performing sudo chgrp changes such as ubuntu:www-data had no effect.

I had the same problem in local environment. On production, my blade template is practically rendered as raw text content as opposed to displaying the Laravel error page - assuming it's because the bootstrap/cache (which I've also modified permissions and ownership for) is being unable to be written to/partially written to.

I've also noted that a lot of tutorials mention bootstrap/cache being within the /storage folder but in newer Laravel versions this seems to have moved to /project-directory/bootstrap as opposed to /project-directory/storage/bootstrap etc.

I'm running Ubuntu Xenial 16.04 on an Amazon AWS instance.

Any help would be thoroughly appreciated.

So as @Bart has led me to figure out. The problem here was a mixture of two things. First was indeed the permissions error, which seems to have been fixed by chmod the whole project directory to 755 or 775 after chgrp to www-data - see comments in original question for guidance on this.

Second due to the fact that I had to reinstall apache at some point after removing it from my original lamp-server installation due to some bad configs, this for some reason, caused my PHP to become disabled on my server and the php files for apache (which I found out were called php.mod and php.load) had gone missing. It was either this or the initial switch and upgrade to 7.2 disabled my PHP (this seems to be a documented Ubuntu bug, reference here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=893481 ).

Apache had no mention of any PHP files within it's mods-enabled or mods-available folders. So I followed the guide here to get this up and running but changed the variables to match my current PHP version which is 7.2 and point it to libphp7.2.so .

https://digitizor.com/how-to-fix-module-php5-does-not-exist-error-in-apache-linux/

I also came across some mcrypt related errors for my config, mainly due to the fact that mcrypt is no longer supported on 7.2 as it is no longer maintained and they are phasing it out to make a move towards libsodium, but there were still some dependencies on it I believe. I installed this via pecl using php-pear.

There were a tonne of other things that were awry that I couldn't possibly document, I highly recommend to anyone reading this, follow a good guide in accordance to your OS and try not to go back/modify your initial core LAMP/WAMP/MAMP etc. setup too much like I did (I think the manual removal of apache2 via purge and then re-install triggered the server side issues to begin with).

Once my PHP was enabled, the text no longer was outputting raw and the permissions changes must have worked as I now see the Laravel default welcome page.

Also on any new installs on "naked" servers - please double check that PHP is enabled for the server system you are using, along with PHP rewrite, mbstring, dev and CLI mods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM