Nginx

無法寫入記憶體目錄 Symfony 3.1

  • September 17, 2018
/var/log/nginx/app.local_error.log:

2018/09/13 11:25:20

$$ error $$20627#0:*18 FastCGI 在標準錯誤中發送:“PHP 消息:PHP 致命錯誤:未擷取的 RuntimeException:無法寫入 /var/www 中的記憶體目錄 (/var/www/app.local/var/cache/prod) /app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:563 堆棧跟踪: /var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(476): Symfony\Component\HttpKernel\Kernel->buildContainer()

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(117): Symfony\Component\HttpKernel\Kernel->initializeContainer()

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(166): Symfony\Component\HttpKernel\Kernel->boot() 3 /var/www/app. local/web/app.php(18): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))

{main} 投入

/var/www/app.local/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php 在第 563 行”,同時從上游讀取響應標頭,客戶端:127.0.0.1,伺服器:app.local,請求:“GET / HTTP/1.1”,上游:“fastcgi://unix:/var/run/php-fpm/php-fpm.sock:”,主機:“app.local”

[user@localhost app.local]$ ls -la
total 2080
drwxrwxrwx.  11 user user    4096 Sep 13 09:09 .
drwxrwxrwx.   6 user user      70 Sep 13 08:17 ..
drwxrwxrwx.   4 user user    4096 Sep 13 08:17 app
drwxrwxrwx.   2 user user      47 Sep 13 08:37 bin
-rwxrwxrwx.   1 user user     639 Sep 13 09:15 bower.json
-rwxrwxrwx.   1 user user      66 Sep 13 08:17 .bowerrc
-rwxrwxrwx.   1 user user    3612 Sep 13 08:17 composer.json
-rwxrwxrwx.   1 user user  144489 Sep 13 08:17 composer.lock
-rwxrwxrwx.   1 user user 1875611 Sep 13 08:22 composer.phar
drwxrwxrwx.   8 user user    4096 Sep 13 08:17 .git
-rwxrwxrwx.   1 user user     391 Sep 13 08:17 .gitignore
-rwxrwxrwx.   1 user user    5586 Sep 13 08:17 gulpfile.js
-rwxrwxrwx.   1 user user    1065 Sep 13 08:17 LICENSE
drwxrwxrwx. 548 user user   16384 Sep 13 09:15 node_modules
-rwxrwxrwx.   1 user user     965 Sep 13 08:17 package.json
-rwxrwxrwx.   1 user user     978 Sep 13 08:17 phpunit.xml.dist
-rwxrwxrwx.   1 user user   10647 Sep 13 08:17 README.md
drwxrwxrwx.   3 user user      34 Sep 13 08:17 src
drwxrwxrwx.   2 user user      21 Sep 13 08:17 upload
drwxrwxrwx+   4 user user (or nginx)      85 Sep 13 08:37 var
drwxrwxrwx.  38 user user    4096 Sep 13 08:37 vendor
drwxrwxrwx.   5 user user    4096 Sep 13 09:16 web

CentOS 7.2.511 Nginx 1.8.0 PHP 7.0.31 Symfony 3.1

試過但得到了相同的結果

我該如何解決這個錯誤?

將記憶體目錄的安全上下文設置為public_content_rw_t

chcon -R -t public_content_rw_t /var/www/aapp.local/var/cache/prod

然後 selinux 將允許對該目錄進行寫訪問。你必須對 symfony 日誌目錄做同樣的事情。

通過禁用 SELinux 解決。解決方案https://linuxize.com/post/how-to-disable-selinux-on-centos-7/

引用自:https://serverfault.com/questions/930794