Nginx Centos7 Laravel 5 can't write to log files [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I got a brand new Centos 7 server and would like to install laravel + nginx
I added Remi repo for PHP5.6
Also added epel
yum update
yum install nmap rsync nano wget curl
yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
nano /etc/yum.repos.d/remi.repo
yum install nginx
systemctl start nginx
systemctl enable nginx
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
#PHP
yum install php php-mysql php-fpm php-dom php-mcrypt php-mbstring
nano /etc/php.ini
cgi.fix_pathinfo=0
nano /etc/php-php.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
systemctl start php-fpm
systemctl enable php-fpm
The NGINX server is working, and phpinfo(); is looking good too.
inside /etc/nginx/nginx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
#root /usr/share/nginx/html;
root /usr/share/nginx/html/lv/public;
index index.php index.html index.htm
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Inside /usr/share/nginx/html/lv I have installed alaravel 5 project via git.
[root#213 lv]# ls -la
total 164
drwxr-xr-x. 11 nginx nginx 4096 Jan 28 02:19 .
drwxr-xr-x. 3 root root 4096 Jan 28 02:17 ..
drwxrwxr-x. 15 nginx nginx 4096 Oct 21 10:44 app
-rw-rw-r--. 1 nginx nginx 1635 Aug 19 08:57 artisan
drwxrwxr-x. 2 nginx nginx 39 Nov 28 01:22 bootstrap
-rw-rw-r--. 1 nginx nginx 1007 Aug 19 08:57 composer.json
-rw-rw-r--. 1 nginx nginx 107281 Aug 19 08:57 composer.lock
drwxrwxr-x. 2 nginx nginx 4096 Aug 19 08:57 config
drwxrwxr-x. 4 nginx nginx 52 Aug 19 08:57 database
-rw-rw-r--. 1 nginx nginx 503 Aug 19 08:57 gulpfile.js
-rw-rw-r--. 1 nginx nginx 79 Aug 19 08:57 package.json
-rw-rw-r--. 1 nginx nginx 87 Aug 19 08:57 phpspec.yml
-rw-rw-r--. 1 nginx nginx 729 Aug 19 08:57 phpunit.xml
drwxrwxr-x. 4 nginx nginx 4096 Nov 28 01:03 public
-rw-rw-r--. 1 nginx nginx 1724 Aug 19 08:57 readme.md
drwxrwxr-x. 5 nginx nginx 42 Aug 19 08:57 resources
-rw-rw-r--. 1 nginx nginx 561 Aug 19 08:57 server.php
drwxrwxrwx. 6 nginx nginx 76 Aug 19 08:57 storage
drwxrwxr-x. 2 nginx nginx 47 Aug 19 08:57 tests
drwxrwxr-x. 29 nginx nginx 4096 Aug 19 08:57 vendor
[root#213 lv]# cd storage
[root#213 storage]# ls -la
total 12
drwxrwxr-x. 6 nginx nginx 76 Aug 19 08:57 .
drwxr-xr-x. 11 nginx nginx 4096 Jan 28 02:19 ..
drwxrwxr-x. 2 nginx nginx 23 Aug 19 08:57 app
drwxrwxr-x. 3 nginx nginx 21 Aug 19 08:57 documents
drwxrwxr-x. 5 nginx nginx 62 Aug 19 08:57 framework
-rwxrwxr-x. 1 nginx nginx 11 Aug 19 08:57 .gitignore
drwxrwxrwx. 2 nginx nginx 4096 Jan 27 14:01 logs
logs is empty.
I still get the following the error:
PHP message: PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/usr/share/nginx/html/lv/storage/logs/laravel-2016-01-28.log" could not be opened: failed to open stream: Permission denied' in /usr/share/nginx/html/lv/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:95
Stack trace:
#0 /usr/share/nginx/html/lv/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88): Monolog\Handler\StreamHandler->write(Array)
#1 /usr/share/nginx/html/lv/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)
#2 /usr/share/nginx/html/lv/vendor/monolog/monolog/src/Monolog/Logger.php(269): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#3 /usr/share/nginx/html/lv/vendor/monolog/monolog/src/Monolog/Logger.php(545): Monolog\Logger->addRecord(400, 'exception 'Symf...', Array)
#4 /usr/share/nginx/html/lv/vendor/larav
So I ran whoami.php which has `echo shell_exec('whoami');' in it, and the user is nginx.
So I don't get the problem

I found the problem
SELinux was turned on:
nano /etc/sysconfig/selinux
set to disabled

Related

Php with Nginx - 403 Forbidden

I want to run project yii2(advanced template) with nginx. I use virtualbox with vagrant(ubuntu 16.04, php 5.6).
I have following settings in my Nginx file:
vhost1.conf
server {
listen *:80;
server_name frontend.test;
client_max_body_size 128m;
root /var/www/frontend/web/;
index index.php;
access_log /var/log/nginx/vhost1.access.log;
error_log /var/log/nginx/vhost1.error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
I have following structure project with permission:
vagrant#machine1]-[/var/www]-[git master]
$ ls -la frontend/
total 68
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 ./
drwxrwxr-x 1 vagrant vagrant 4096 Jul 9 16:14 ../
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 assets/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 bootstrap/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 components/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 config/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 controllers/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 data/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 helpers/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 messages/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 models/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 modules/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 runtime/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 validators/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 views/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 web/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 widgets/
nginx error logs output:
2018/07/09 21:42:36 [error] 23865#23865: *1 directory index of "/var/www/frontend/web/" is forbidden, client: 192.168.56.1, server: b2bfrontend.test, request: "GET / HTTP/1.1", host: "b2bfrontend.test"
If I run b2bfrontend.test I get an error - 403 Forbidden
Just fix location from:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
to:
location / {
try_files $uri /index.php$is_args$args;
}
reason: it tries to go $uri/ which is /var/www/frontend/web/ (since it exists) and to do directory indexing which seems like not allowed.
message already says it:
directory index of "/var/www/frontend/web/" is forbidden
I uncommented this line and now it works:
fastcgi_pass unix:/var/run/php5-fpm.sock;
In my case I have Debian 9 so this I changed it a bit:
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
My complete code is:
location ~ \.(php|twig)$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
Your nginx server is most probably running either under user nginx or www-data while your files have vagrant:vagran ownership. Check what's the user under which nginx is running and change the ownership of your files accordingly. Also, if you use php-fpm for php, check your php-fpm configuration and see what user is defined there as well.

CentOS, Nginx: 403 Forbidden in Laravel's folder

I use laravel new test to establish the Laravel project and move all directories into /usr/share/nginx/html/, the default root directory of Nginx.
In order to check if the config of nginx is correct, I simply the config, trun on autoindex, and put index,html into /usr/share/nginx/html/test/public/, the location of index.php of laravel.
defaul.conf of nginx
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html/test;
index index.html index.htm index.php;
location / {
autoindex on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
When I access the index.html by localhost/public/, nginx returns me 403. I copy index.html into a new folder named /usr/share/nginx/html/test/public_b, and try to access the new index.html by localhost/public_b/. Nginx returns me the correct content! It is like a miracle. The stats of my directories as the follows.
$ll /usr/share/html/test
total 432
drwxrwxr-x. 6 nginx nginx 84 Feb 26 15:39 app
-rw-rw-r--. 1 nginx nginx 1686 Feb 26 15:39 artisan
drwxrwxr-x. 3 nginx nginx 34 Feb 26 15:39 bootstrap
-rw-rw-r--. 1 nginx nginx 1512 Feb 26 15:39 composer.json
-rw-rw-r--. 1 nginx nginx 145089 Feb 26 15:39 composer.lock
drwxrwxr-x. 2 nginx nginx 247 Feb 26 15:39 config
drwxrwxr-x. 5 nginx nginx 72 Feb 26 15:39 database
-rwxrwxr-x. 1 nginx nginx 13 Feb 26 17:46 index.html
-rw-rw-r--. 1 nginx nginx 1150 Feb 26 15:39 package.json
-rw-rw-r--. 1 nginx nginx 1040 Feb 26 15:39 phpunit.xml
drwxr-xr-x. 4 root root 116 Feb 26 18:05 public
drwxr-xr-x. 2 root root 24 Feb 26 17:50 public_c
drwxrwxr-x. 5 nginx nginx 45 Feb 26 15:39 resources
drwxrwxr-x. 2 nginx nginx 75 Feb 26 16:50 routes
-rw-rw-r--. 1 nginx nginx 563 Feb 26 15:39 server.php
drwxr-xr-x. 5 nginx nginx 46 Feb 26 15:39 storage
drwxrwxr-x. 4 nginx nginx 83 Feb 26 15:39 tests
drwxrwxr-x. 37 nginx nginx 4096 Feb 26 15:40 vendor
-rw-rw-r--. 1 nginx nginx 549 Feb 26 15:39 webpack.mix.js
-rw-rw-r--. 1 nginx nginx 258941 Feb 26 15:39 yarn.lock
$ ll /usr/share/nginx/html/test/public
total 12
drwxrwxr-x. 2 nginx nginx 21 Feb 26 15:39 css
-rw-rw-r--. 1 nginx nginx 0 Feb 26 15:39 favicon.ico
-rwxr-xr-x. 1 root root 13 Feb 26 17:49 index.html
-rw-rw-r--. 1 nginx nginx 1823 Feb 26 15:39 index.php
drwxrwxr-x. 2 nginx nginx 20 Feb 26 15:39 js
-rw-rw-r--. 1 nginx nginx 24 Feb 26 15:39 robots.txt
$ ll /usr/share/nginx/html/test/public_c/
total 4
-rwxr-xr-x. 1 root root 13 Feb 26 17:50 index.html
I have read a lot of relative questions and pages, but nothing help against this problem. What is wrong in my actions or settings?
Update
Thanks #Adam Kozlowski. I tried chmod 777 public -R and changing owner to both of root and nginx, but the problem was not solved.
I found the problem: SELinux blocked Nginx to access the folders.
$ ls /usr/share/nginx/html/test/ -Z
drwxr-xr-x. root root unconfined_u:object_r:config_home_t:s0 public
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 public_c
Only the files with the tag, httpd_sys_content_t, can be accessed by HTTP.
Command:
chcon -R -t httpd_sys_content_t /usr/share/nginx/html/test
And I also need to add httpd_sys_rw_content_t to /usr/share/nginx/html/test/storage to let Laravel work.
Command:
chcon -R -t httpd_sys_rw_content_t/usr/share/nginx/html/test/storage
Referring Permissions Issue with Laravel on CentOS
Set proper permission for directory, as a root user:
chmod a+rwx directory-name -R

nginx configuration for Wordpress in subdirectory of Rails app in same server

I keep getting the "File not found" error when I try to access example.com/blog, and in /var/log/nginx/error.log :
FastCGI sent in stderr: "Primary script unknown" while reading
response header from upstream
Here is my nginx configuration:
upstream example {
server unix:/home/deployer/example/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com;
client_max_body_size 4G;
keepalive_timeout 10;
error_page 500 502 503 504 /500;
root /home/deployer/example/current/public;
try_files $uri/index.html $uri.html $uri #example;
location #example {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://example;
}
location /blog {
root /var/www/example_blog;
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /blog/index.php?q=$1 last;
}
location ~ .php(?|$) {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
location = /50x.html {
root html;
}
location = /404.html {
root html;
}
location #503 {
error_page 405 = /system/maintenance.html;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name assets.example.com;
client_max_body_size 4G;
keepalive_timeout 10;
root /home/deployer/example/current/public;
location = /404.html {
root html;
}
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}
Processes of PHP-FPM and nginx:
$ ps aux | grep nginx
root 31590 0.0 0.0 32420 948 ? Ss 16:27 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 31593 0.0 0.1 32868 3596 ? S 16:27 0:00 nginx: worker process
deployer 32052 0.0 0.0 14224 936 pts/0 S+ 16:33 0:00 grep --color=auto nginx
$ ps aux | grep php
root 31656 0.0 1.4 356016 29892 ? Ss 16:27 0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 31659 0.0 0.2 356016 5880 ? S 16:27 0:00 php-fpm: pool www
www-data 31660 0.0 0.4 356344 8424 ? S 16:27 0:00 php-fpm: pool www
deployer 32059 0.0 0.0 14224 956 pts/0 S+ 16:33 0:00 grep --color=auto php
Permissions on the wordpress directory:
drwxrwsr-x 5 www-data www-data 4096 Jun 1 00:13 example_blog/
Permissions on the files in Wordpress:
drwxrwsr-x 5 www-data www-data 4096 Jun 1 00:13 ./
drwxr-xr-x 10 deployer deployer 4096 Jun 1 16:32 ../
-rw-r--r-- 1 www-data www-data 418 Sep 25 2013 index.php
-rw-r--r-- 1 www-data www-data 19935 Jan 3 02:51 license.txt
-rw-r--r-- 1 www-data www-data 7433 Jan 12 01:46 readme.html
-rw-r--r-- 1 www-data www-data 5447 Sep 28 2016 wp-activate.php
drwxr-sr-x 9 www-data www-data 4096 May 17 05:50 wp-admin/
-rw-r--r-- 1 www-data www-data 364 Dec 19 2015 wp-blog-header.php
-rw-r--r-- 1 www-data www-data 1627 Aug 29 2016 wp-comments-post.php
-rw-r--r-- 1 www-data www-data 3136 Jun 1 00:13 wp-config.php
-rw-r--r-- 1 www-data www-data 2853 Dec 16 2015 wp-config-sample.php
drwxrwsr-x 5 www-data www-data 4096 Jun 1 00:05 wp-content/
-rw-r--r-- 1 www-data www-data 3286 May 25 2015 wp-cron.php
drwxr-sr-x 18 www-data www-data 12288 May 17 05:50 wp-includes/
-rw-r--r-- 1 www-data www-data 2422 Nov 21 2016 wp-links-opml.php
-rw-r--r-- 1 www-data www-data 3301 Oct 25 2016 wp-load.php
-rw-r--r-- 1 www-data www-data 33939 Nov 21 2016 wp-login.php
-rw-r--r-- 1 www-data www-data 8048 Jan 11 13:15 wp-mail.php
-rw-r--r-- 1 www-data www-data 16255 Apr 7 02:23 wp-settings.php
-rw-r--r-- 1 www-data www-data 29896 Oct 19 2016 wp-signup.php
-rw-r--r-- 1 www-data www-data 4513 Oct 15 2016 wp-trackback.php
-rw-r--r-- 1 www-data www-data 3065 Sep 1 2016 xmlrpc.php
In /etc/php/7.0/fpm/pool.d/www.conf:
user = www-data
group = www-data
listen.owner = nginx
listen.group = nginx
;listen.mode = 0660
Have been googling and tried various ways, but still couldn't get it passed this error.
The problem is that location /blog { root /var/www/example_blog; ... places the files in /var/www/example_blog/blog/.
root is applicable only when the file path is constructed by concatenating the $document_root with the URI. Otherwise you need to rewrite the URI or use an alias directive. See this document for details.
The alias directive can be implemented like this:
location = /blog { rewrite ^ /blog/ last; }
location ^~ /blog/ {
alias /var/www/example_blog/;
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /blog/index.php?q=$1 last;
}
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
Use the ^~ modifier to avoid any ambiguity with other regular expression location blocks at the same level. See this document for details.
To avoid problems with URIs such as /blogx, use a trailing / on both the location and the alias. And add an exact match location to handle /blog.

Nginx + php-fpm output in log: [error] failed (13: Permission denied), also nginx and php-fpm running as user vagrant

Nginx returns in browser the page
403 Forbidden
Is it my data:
/etc/nginx/sites-enabled/lar.template
upstream phpapp {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name www.lar.app lar.app;
root /home/vagrant/lar/public;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass phpapp;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /var/log/nginx/lar_error.log;
access_log /var/log/nginx/lar_access.log;
}
/etc/nginx/nginx.conf
user vagrant;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.*;
}
/etc/opt/remi/php71/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = vagrant
; RPM: Keep a group allowed to write in log dir.
group = vagrant
listen = 127.0.0.1:9000
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = vagrant
listen.group = vagrant
$ ls -l /home/vagrant/lar
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 app
-rwxrwxr-x. 1 vagrant vagrant 1646 дек 3 09:03 artisan
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 bootstrap
-rw-rw-r--. 1 vagrant vagrant 1283 дек 3 09:03 composer.json
-rw-rw-r--. 1 vagrant vagrant 124490 дек 3 09:15 composer.lock
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 config
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 database
-rw-rw-r--. 1 vagrant vagrant 558 дек 3 09:03 gulpfile.js
-rw-rw-r--. 1 vagrant vagrant 401 дек 3 09:03 package.json
-rw-rw-r--. 1 vagrant vagrant 930 дек 3 09:03 phpunit.xml
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 public
-rw-rw-r--. 1 vagrant vagrant 1918 дек 3 09:03 readme.md
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 resources
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 routes
-rw-rw-r--. 1 vagrant vagrant 563 дек 3 09:03 server.php
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 storage
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:03 tests
drwxrwxr-x. 1 vagrant vagrant 4096 дек 3 09:15 vendor
ps -aux | grep php
root 1080 0.0 1.9 578248 37264 ? Ss 09:40 0:01 php-fpm: master process (/etc/opt/remi/php71/php-fpm.conf)
vagrant 2334 0.0 0.5 578248 9752 ? S 09:40 0:00 php-fpm: pool www
vagrant 2335 0.0 0.5 578248 9752 ? S 09:40 0:00 php-fpm: pool www
vagrant 2336 0.0 0.5 578248 9752 ? S 09:40 0:00 php-fpm: pool www
vagrant 2337 0.0 0.5 578248 9752 ? S 09:40 0:00 php-fpm: pool www
vagrant 2338 0.0 0.5 578248 9756 ? S 09:40 0:00 php-fpm: pool www
vagrant 6838 0.0 0.0 112672 972 pts/0 D+ 11:53 0:00 grep --color=auto php
ps -aux | grep nginx
root 1617 0.0 0.0 47792 1232 ? Ss 09:40 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
vagrant 1618 0.0 0.1 48328 2240 ? S 09:40 0:00 nginx: worker process
vagrant 6840 0.0 0.0 112672 976 pts/0 R+ 11:55 0:00 grep --color=auto nginx
lar_error.log
2016/12/03 09:40:54 [error] 1618#1618: *1
"/home/vagrant/lar/public/index.php" is forbidden (13: Permission
denied), client: 192.168.5.1, server: www.lar.app, request: "GET /
HTTP/1.1", host: "lar.app" 2016/12/03 09:40:54 [error] 1618#1618: *1
open() "/home/vagrant/lar/public/favicon.ico" failed (13: Permission
denied), client: 192.168.5.1, server: www.lar.app, request: "GET
/favicon.ico HTTP/1.1", host: "lar.app" 2016/12/03 09:40:54 [error]
1618#1618: *1 open() "/home/vagrant/lar/public/favicon.ico" failed
(13: Permission denied), client: 192.168.5.1, server:
$ groups vagrant
vagrant: vagrant nginx apache
What is the cause here? Thanks in advance

nginx serving 404 pages

EDIT: Based on #Devons advice I ran the following commands with no errors (found in this post):
$ sudo find /var/public/www -type d -exec chmod 755 {} +
$ sudo find /var/public/www -type f -exec chmod 644 {} +
But when I list the files inside www the permissions still look wrong. What am I doing wrong? Thanks!
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:45 app
-rwxrwx--- 1 root vboxsf 1646 Aug 28 12:45 artisan
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 bootstrap
-rwxrwx--- 1 root vboxsf 1201 Aug 28 12:45 composer.json
-rwxrwx--- 1 root vboxsf 105046 Aug 28 12:55 composer.lock
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:45 config
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 database
-rwxrwx--- 1 root vboxsf 503 Aug 28 12:45 gulpfile.js
-rwxrwx--- 1 root vboxsf 159 Aug 28 12:45 package.json
-rwxrwx--- 1 root vboxsf 87 Aug 28 12:45 phpspec.yml
-rwxrwx--- 1 root vboxsf 899 Aug 28 12:45 phpunit.xml
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 public
-rwxrwx--- 1 root vboxsf 1928 Aug 28 12:45 readme.md
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 resources
-rwxrwx--- 1 root vboxsf 567 Aug 28 12:45 server.php
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 storage
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 tests
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:56 vendor
This is my first time with nginx and cannot get laravel welcome page to show. I am using ubuntu 14.04 and VBox 5.
I have my server configured in /var/nginx/sites-enabled/default as
server {
listen 80 default_server;
charset utf-8;
server_name doimain.app www.domain.app;
root /var/www/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Inside /var/www/public I can list the laravel public folder files
$ ls -l /var/www/public
total 3
-rwxrwx--- 1 root vboxsf 0 Aug 28 12:45 favicon.ico
-rwxrwx--- 1 root vboxsf 1786 Aug 28 12:45 index.php
-rwxrwx--- 1 root vboxsf 24 Aug 28 12:45 robots.txt
But I get 404 when I go to domain.app. The nginx error log shows:
2015/08/28 14:29:35 [crit] 1487#0: *14 stat() "/var/www/public/index.php" failed (13: Permission denied), client: 10.0.0.18, server: domain.app, request: "GET / HTTP/1.1", host: "domain.app"
I have tried without success the following:
Ensure www-data owns the folder structure /var/www
$ sudo chown www-data:www-data /var/www
Changed access rights to /var/www
$ sudo chmod -R 0755 /var/www
Thanks!
The public directory is owned by root and is not readable to others. You either need to change the ownership to www-data or chmod all of the folder and files. The folder should be 0755 and files be 0644 for most configurations. You can leave it how you have it if the files are owned by the same user running nginx and php (I assume www-data).
Changing the ownership of /var/www by itself does nothing, you have to change all the folders and files in the web directory.
You can chmod and chown recursively with the -R flag.
chown -R www-data:www-data /var/www/public
Solved it by addig www-data user to vboxsf group and restarting the server.
$sudo usermod -G vboxsf -a www-data

Categories