nginx symfony2 permission denied

Pagina: 1
Acties:

  • Hopscotch
  • Registratie: September 2015
  • Laatst online: 28-09-2021
Ik krijg het maar niet voor elkaar om een nieuw symfony2 project via nginx te benaderen. Ik blijf een error krijgen in de error log:
code:
1
2
2015/09/30 13:01:30 [error] 12424#0: *8 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
Unable to open primary script: /var/www/fitness/web/app.php (Permission denied)" while reading response header from upstream, client: 127.0.0.1, server: fitness.loc, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "fitness.loc"

De symfony webserver starten via php app/console server:run gaat wel goed en dan kom ik ook op de startpagina van het nieuwe symfony project.

Het merkwaardige is dat het me wel lukt om een losse php pagina te maken. Ik heb in /var/www/nginxtest het bestand index.php en ik kan in de browser gewoon naar nginxtest.loc en de file wordt goed uitgevoerd.

Maar als ik bijna dezelfde configuratie gebruik voor mijn gecreëerde symfony project dan krijg ik de foutmelding. mijn symfony project staat in /var/www/fitness.

Beide directories hebben hebben dezelfde eigenaar en rechten (nginx:nginx 775 voor dirs en 664 voor files) de user staat ook voor zowel nginx als php-fpm ingesteld op nginx.

De config voor de virtual hosts:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
server {
    server_name fitness.loc;
    root /var/www/fitness/web;
    index app.php;

    error_log /var/log/nginx/fitness_error.log;
    access_log /var/log/nginx/fitness_access.log;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

server {
    server_name nginxtest.loc;
    root /var/www/nginxtest;
    index index.php

    error_log /var/log/nginx/nginxtest_error.log;
    access_log /var/log/nginx/nginxtest_access.log;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Ik heb ook de standaard config van de site van symfony geprobeerd, maar die werkte ook niet.
Ik gebruik Centos 6.

  • Heli0s
  • Registratie: April 2002
  • Laatst online: 06-04 15:07

Heli0s

Liberate tuteme ex inferis

Wat zijn de permissies die ingesteld staan voor je php5-fpm.sock? Wie is de eigenaar en groep van de /var/www/fitness/web dir?

The fear that keeps me going and going and going. Is the same fear that brings me to my knees


  • Hopscotch
  • Registratie: September 2015
  • Laatst online: 28-09-2021
code:
1
srw-rw----.  1 nginx     nginx        0 Sep 30 01:28 php5-fpm.sock
code:
1
drwxr-xr-x.  3 nginx nginx 4.0K Sep 30 11:11 web
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@xxxxx web]# ls -lah
total 60K
drwxr-xr-x. 3 nginx nginx 4.0K Sep 30 11:11 .
drwxr-xr-x. 7 nginx nginx 4.0K Sep 30 00:37 ..
-rw-r--r--. 1 nginx nginx 1.2K Sep 25 13:37 app_dev.php
-rw-r--r--. 1 nginx nginx  11K Sep 25 13:37 apple-touch-icon.png
-rw-r--r--. 1 nginx nginx 1014 Sep 25 13:37 app.php
drwxr-xr-x. 2 nginx nginx 4.0K Sep 30 00:37 bundles
-rw-r--r--. 1 nginx nginx 5.7K Sep 25 13:38 config.php
-rw-r--r--. 1 nginx nginx 6.4K Sep 25 13:37 favicon.ico
-rw-r--r--. 1 nginx nginx 3.3K Sep 25 13:37 .htaccess
-rw-r--r--. 1 nginx nginx  106 Sep 25 13:37 robots.txt
-rwxrwxrwx. 1 nginx nginx   20 Sep 30 01:21 test.php

  • mvdster
  • Registratie: Januari 2008
  • Laatst online: 28-08 15:42
SELinux?
getenforce om de status hier te bepalen en daarna doe eens een ls -Z van /var/www/fitness/web

  • Hopscotch
  • Registratie: September 2015
  • Laatst online: 28-09-2021
Is een goede verdachte en ik snap er vaak niet veel van.
code:
1
2
3
4
5
6
7
8
9
[root@xxxxxxxx web]# ls -Z
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 app_dev.php
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 apple-touch-icon.png
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 app.php
drwxr-xr-x. nginx nginx unconfined_u:object_r:user_tmp_t:s0 bundles
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 config.php
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 favicon.ico
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 robots.txt
-rwxrwxrwx. nginx nginx unconfined_u:object_r:user_tmp_t:s0 test.php

getenforce geeft bij deze dir "enforcing" net als bij de test dir, de test dir heeft wel iets anders:
code:
1
2
[root@xxxxxxxx nginxtest]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.php

Als ik het goed gelezen heb worden door SELinux geblokkeerde dingen gelogd en kan je die terug zien met aureport, maar deze geeft niks:
code:
1
2
3
4
5
6
7
[root@xxxxxxxx nginxtest]# aureport -a

AVC Report
========================================================
# date time comm subj syscall class permission obj event
========================================================
<no events of interest were found>

  • mvdster
  • Registratie: Januari 2008
  • Laatst online: 28-08 15:42
Je SELinux context op de files / directories zijn niet goed.
Je kunt deze met chcon -t httpd_sys_content_t <file / directory> aanpassen.

  • Hopscotch
  • Registratie: September 2015
  • Laatst online: 28-09-2021
Het werkt!
Super bedankt, ga morgen maar eens wat meer lezen over deze materie, heb weleens eerder ruzie met SELinux gehad.
Pagina: 1