I am trying to install invoice ninja on a self hosted server running CentOS 7, Apache, PHP 7.1 and MySQL. Whenever i open the page i get the following error:
The stream or file “/var/www/html/ninja/storage/logs/laravel-error.log” could not be opened: failed to open stream: Permission denied
However, that file has infact been written to. I have tried changing ownership of the file/directories as well as even setting them to 777 and still the same error.
Any help would be greatly appreciated.
Most likely, the Apache user and the owner of /ninja/storage/
don’t match. Try ps aux | egrep ‘apache2 -k start’
to see what user Apache is running as. There should be one process under root (only used to open and bind the proper ports), and the others will be the actual Apache user. Then checkls -a /var/www/ninja | grep ‘storage’
to see who actually owns the folder.
By default, both should be listed as www-data:www-data
(user:group). If not, you can change it to match whatever Apache is running as. Then just make sure to set the permission back to 775 so nobody outside of www-data
(or whatever the user is) can make any changes.
Thanks for getting back to me. This is why I’m stumped. apache is running as root:
root 30305 0.0 0.1 112648 964 pts/0 S+ 19:44 0:00 grep -E --color=auto apache2 -k start
and storage is owned by root:root
drwxrwxrwx. 8 root root 4096 Sep 6 05:28 storage
I even set the directory recursively to 777, same issue.
I have also tried changing the ownership to apache:apache just incase.
Hrmm. Is that the only line that shows up? Because Apache shouldn’t be running as root at all. The root entry should only be what it uses for the initial startup when opening the ports in your conf file and binding them to the system’s IP address.
Here’s an example of what it should look like
username@NinjaServer:~$ ps aux | egrep 'apache2 -k start'
www-data 864 0.0 2.2 497784 45232 ? S 09:03 0:00 /usr/sbin/apache2 -k start
www-data 866 0.0 2.1 497188 43400 ? S 09:03 0:00 /usr/sbin/apache2 -k start
www-data 867 0.0 2.4 576168 49704 ? S 09:03 0:00 /usr/sbin/apache2 -k start
www-data 868 0.0 1.8 497292 38212 ? S 09:03 0:00 /usr/sbin/apache2 -k start
www-data 869 0.0 2.0 499508 42300 ? S 09:03 0:00 /usr/sbin/apache2 -k start
root 1690 0.0 1.4 489732 29644 ? Ss Sep10 1:03 /usr/sbin/apache2 -k start
www-data 3163 0.0 0.8 492064 17720 ? S 18:52 0:00 /usr/sbin/apache2 -k start
username 4026 0.0 0.0 14428 1092 pts/0 S+ 22:09 0:00 grep -E --color=auto apache2 -k start
www-data 21566 0.0 2.7 505948 56316 ? S 06:25 0:00 /usr/sbin/apache2 -k start
www-data 21567 0.0 2.0 499356 41240 ? S 06:25 0:00 /usr/sbin/apache2 -k start
www-data 21568 0.0 0.9 492192 19040 ? S 06:25 0:00 /usr/sbin/apache2 -k start
www-data 21570 0.0 0.9 492152 18944 ? S 06:25 0:00 /usr/sbin/apache2 -k start
Maybe try egrep '(apache|httpd)' instead of 'apache2 -k start' when running
ps aux`?
Might be easier to visualize with htop.

Here it shows root as the user that initially loaded Apache, but www-data as the actual user that it’s running under.
using egrep '(apache|httpd)'
i get
root 830 0.0 3.6 618076 37288 ? Ss Sep16 0:11 /usr/sbin/httpd -DFOREGROUND
apache 1025 0.0 1.2 618472 12564 ? S Sep16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1026 0.0 1.2 618472 12868 ? S Sep16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1036 0.0 1.2 618472 12576 ? S Sep16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2352 0.0 1.2 618472 12560 ? S Sep16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2640 0.0 1.2 618472 12560 ? S Sep17 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3036 0.0 1.2 618472 12552 ? S Sep17 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3037 0.0 1.2 618472 12552 ? S Sep17 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3038 0.0 1.1 618472 11960 ? S Sep17 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3039 0.0 1.2 618472 12564 ? S Sep17 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3313 0.0 1.1 618472 11968 ? S 10:12 0:00 /usr/sbin/httpd -DFOREGROUND
root 3404 0.0 0.0 112648 976 pts/0 R+ 12:55 0:00 grep -E --color=auto (apache|httpd)
Looks like your install went and made a new user for ‘apache’ instead of the default ‘www-data’. Try chown -R apache:apache /var/www/ninja/storage/
. That should set ownership of the entire storage folder (laravel logs included) to the apache user. Then chmod 775 -R /var/www/ninja/storage/
should set it to where the apache user and group has full permissions, while the rest of the users have write-permissions disabled on that directory.