Приложение Slim 3 php не работает на CentOS nginx доступ запрещен, возможно, из-за функции session_start () - PullRequest
0 голосов
/ 23 июня 2018

В последнее время я боролся за установку последней версии nginx 1.14, php 7.2.5 и mariaDB 10.3.7 на CentOS 7 в виртуальной машине MacOS.

Наконец-то работает php, я уже успешно протестировал php_info(), index.php, testDBconnection.php и даже перенаправил в папку /public.

Однако при копировании моего приложения Slim 3 в папку я получаю эту ошибку:

доступ запрещен

Я получаю доступ к журналу через # tail /var/log/nginx/error.log, и вывод выглядит следующим образом:

PHP message: PHP Warning:  session_start(): Failed to read session data: files (path: /var/opt/remi/php72/lib/php/session) in /usr/share/nginx/html/slim3.local/bootstrap/app.php on line 5" while reading response header from upstream, client: 192.168.1.71, server: slim3.local, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "slim3.local"
2018/06/23 01:27:40 [error] 2514#2514: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  session_start(): open(/var/opt/remi/php72/lib/php/session/sess_1ncvjg5us9384bs0m6vo0m46k7, O_RDWR) failed: Permission denied (13) in /usr/share/nginx/html/slim3.local/bootstrap/app.php on line 5
PHP message: PHP Warning:  session_start(): Failed to read session data: files (path: /var/opt/remi/php72/lib/php/session) in /usr/share/nginx/html/slim3.local/bootstrap/app.php on line 5" while reading response header from upstream, client: 192.168.1.71, server: slim3.local, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "slim3.local"

Строка 5 файла app.php: session_start();

Более того, странно видеть IP-адрес http://192.168.1.71/, когда он на самом деле http://192.168.1.76/

Я изменил разрешения в /var/opt/remi/php72/lib/php для папок session, opcache, & wsdlcache с помощью следующей команды:

# chown nginx:nginx /var/opt/remi/php72/lib/php/session

Я перезапустил все:

# systemctl restart php72-php-fpm # systemctl restart nginx

Также я попробовал:

# grep session.save_path  /etc/opt/remi/php72/php.ini
;     session.save_path = "N;/path"
;     session.save_path = "N;MODE;/path"
;session.save_path = "/tmp"
;       (see session.save_path above), then garbage collection does *not*

Я перезагружаю страницу "http://slim3.local" и все равно получаю такую ​​же access denied ошибку!

(

# ls -la 

возвращает

# ls -lah /var/opt/remi/php72/lib/php/
total 0
drwx------. 5 nginx nginx 53 jun 19 19:51 .
drwxr-xr-x. 7 root  root  71 jun 19 19:51 ..
drwx------. 3 nginx nginx 46 jun 25 19:02 opcache
drwxrwx---+ 2 nginx nginx 84 jun 25 19:02 session
drwx------. 2 nginx nginx  6 may 23 01:59 wsdlcache

файл www.conf

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]
...
; RPM: apache user chosen to provide access to the same directories as httpd
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group = nginx
...
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511

; 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 = nobody
;listen.group = nobody
;listen.mode = 0660
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
...
; See warning about choosing the location of these directories on your system
; at http://php.net/session.save-path
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/opt/remi/php72/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/opt/remi/php72/lib/php/wsdlcache
php_value[opcache.file_cache]  = /var/opt/remi/php72/lib/php/opcache

В файле php.ini я получил:

...
cgi.fix_pathinfo=1
...
session.save_path = "/var/opt/remi/php72/lib/php/session"
...

nginx default.conf file:

server {
    listen   80;
    server_name  localhost;
    root /usr/share/nginx/html;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # 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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
 # 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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files      $uri = 404;
        include        /etc/nginx/fastcgi_params;
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

my nginx virtual.conf

server {
        server_name slim3.local;
        root /usr/share/nginx/html/slim3nc.local/public;#without this line, it throws NOT FOUND

        location / {
             index index.html index.htm index.php;
        }

    location ~ \.php$ {
             try_files      $uri = 404;
             include        /etc/nginx/fastcgi_params;
             root           /usr/share/nginx/html/slim3nc.local/public;#Esta carpeta influye más
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             #include /etc/nginx/fastcgi_params;
             #fastcgi_pass 127.0.0.1:9000;
             #fastcgi_index index.php;
             #fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/slim3nc.dev$fastcgi_script_name;
        }
}

и команда

# lsattr /var/opt/remi/php72/lib/php/session

возвращает

---------------- /var/opt/remi/php72/lib/php/session/sess_1ncvjg5us9384bs0m6vo0m46k7
---------------- /var/opt/remi/php72/lib/php/session/sess_923979fqgr7r807majmn114vuk

Тестирование сестатуса

# sestatus

Возвращает

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

И если я подам заявку

# setenforce 0

возвращается

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

Более того, я попытался изменить настройки в пути для кэша прямо в настройках контейнера Slim3, и ничего не работает: (

$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig(__DIR__ . '/../resources/views', [
        'cache' => false,/*__DIR__ .'/../cache/views', *//* todo 'path/to/cache' on production, we need to set up a directory to cache the views*/
        'debug' => false, /*todo Turn this off in production*/
    ]);

    ...

    return $view;
};

Я все еще получаю сообщение на пустой странице

доступ запрещен

Это тонкое веб-приложение, которое я получил, не работает ни на одном сервере: CentOS 7 Production, Laravel Hometead, Ubuntu 16, ... оно просто не работает !!! Чего мне не хватает?

Как мне это исправить ??

-> Пока что я использую Laravel ...

...