title: nginx yii2 tips 500 Internal Server Error when getenforce is enforcing
body: <p>I copied my site to Google Platform, it tips <code>500 Internal Server Error</code> (eg when I visit this page <a href="https://letsclassifieds.com/info/add" rel="nofollow noreferrer">https://letsclassifieds.com/info/add</a> ),But it runs ok on vultr and other services.</p>
  
  <h2>Directory /htdocs/flxx/basic/runtime is in mod 0777</h2>
  
  <pre><code>[root@instance-1 ~]# ll / | grep htdocs
  drwxr-xr-x.   6 www  apache   55 Apr 24 01:53 htdocs
  [root@instance-1 ~]# ll /htdocs/
  total 8
  drwxr-xr-x.  3 www apache   18 Apr 24 05:16 flxx
  drwxr-xr-x.  7 www apache   78 Apr 24 03:03 phpbids
  drwxr-xr-x. 12 www apache 4096 Apr 24 04:05 pma
  drwxr-xr-x.  3 www apache   39 Apr 24 05:20 uploads
  [root@instance-1 ~]# ll /htdocs/flxx/
  total 4
  drw-r--r--. 23 www apache 4096 Apr 24 06:44 basic
  [root@instance-1 ~]# ll /htdocs/flxx/basic/
  total 196
  drw-r--r--.  2 www apache   4096 Apr 24 06:39 actions
  drw-r--r--.  2 www apache     25 Apr 24 06:39 assets
  drw-r--r--.  4 www apache     80 Apr 24 06:41 commands
  drw-r--r--.  5 www apache     44 Apr 24 06:39 components
  -rw-r--r--.  1 www apache   1806 Apr 24 06:41 composer.json
  -rw-r--r--.  1 www apache 124826 Apr 24 06:44 composer.lock
  drw-r--r--.  6 www apache   4096 Apr 24 06:58 config
  drw-r--r--.  5 www apache   4096 Apr 24 06:41 controllers
  drw-r--r--.  4 www apache   4096 Apr 24 06:41 document
  drw-r--r--.  2 www apache     28 Apr 24 06:41 events
  drw-r--r--.  4 www apache   4096 Apr 24 06:41 helpers
  -rw-r--r--.  1 www apache   1622 Apr 24 06:39 LICENSE.md
  drw-r--r--.  9 www apache   4096 Apr 24 06:39 mail
  drw-r--r--.  3 www apache     18 Apr 24 06:39 messages
  drw-r--r--.  3 www apache     89 Apr 24 06:41 migrations
  drw-r--r--. 11 www apache   4096 Apr 24 06:39 models
  -rw-r--r--.  1 www apache   2699 Apr 24 06:39 README.md
  -rw-r--r--.  1 www apache   5049 Apr 24 06:39 requirements.php
  drwxrwxrwx.  3 www apache     49 Apr 24 08:19 runtime
  drw-r--r--.  2 www apache     42 Apr 24 06:41 shell
  drw-r--r--.  3 www apache     62 Apr 24 06:39 tests
  drw-r--r--.  2 www apache   4096 Apr 24 06:41 validators
  drw-r--r--. 27 www apache   4096 Apr 24 06:44 vendor
  drw-r--r--. 22 www apache   4096 Apr 24 06:39 views
  drw-r--r--.  9 www apache   4096 Apr 24 07:01 web
  -rw-r--r--.  1 www apache    697 Apr 24 06:39 yii
  -rw-r--r--.  1 www apache    515 Apr 24 06:39 yii.bat
  [root@instance-1 ~]#
  </code></pre>
  
  <h2>php-fpm error log</h2>
  
  <pre><code># /var/log/php-fpm/www-error.log
  
  Previous exception:
  yii\base\InvalidConfigException: The directory is not writable by the Web process: /htdocs/flxx/basic/web/assets in /htdocs/flxx/basic/vendor/yiisoft/yii2/web/AssetManager.php:215
  Stack trace:
  #0 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Object.php(107): yii\web\AssetManager-&gt;init()
  #1 [internal function]: yii\base\Object-&gt;__construct(Array)
  #2 /htdocs/flxx/basic/vendor/yiisoft/yii2/di/Container.php(375): ReflectionClass-&gt;newInstanceArgs(Array)
  #3 /htdocs/flxx/basic/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container-&gt;build('yii\\web\\AssetMa...', Array, Array)
  #4 /htdocs/flxx/basic/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container-&gt;get('yii\\web\\AssetMa...', Array, Array)
  #5 /htdocs/flxx/basic/vendor/yiisoft/yii2/di/ServiceLocator.php(135): yii\BaseYii::createObject(Array)
  #6 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Application.php(605): yii\di\ServiceLocator-&gt;get('assetManager')
  #7 /htdocs/flxx/basic/vendor/yiisoft/yii2/web/View.php(225): yii\base\Application-&gt;getAssetManager()
  #8 /htdocs/flxx/basic/vendor/yiisoft/yii2/web/View.php(285): yii\web\View-&gt;getAssetManager()
  #9 /htdocs/flxx/basic/vendor/yiisoft/yii2/web/AssetBundle.php(125): yii\web\View-&gt;registerAssetBundle('yii\\bootstrap\\B...')
  #10 /htdocs/flxx/basic/views/layouts/main.php(14): yii\web\AssetBundle::register(Object(yii\web\View))
  #11 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/View.php(328): require('/htdocs/flxx/ba...')
  #12 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/View.php(250): yii\base\View-&gt;renderPhpFile('/htdocs/flxx/ba...', Array)
  #13 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Controller.php(396): yii\base\View-&gt;renderFile('/htdocs/flxx/ba...', Array, Object(app\controllers\InfoController))
  #14 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Controller.php(382): yii\base\Controller-&gt;renderContent('&lt;div class="row...')
  #15 /htdocs/flxx/basic/actions/InfoListAction.php(158): yii\base\Controller-&gt;render('list', Array)
  #16 [internal function]: app\actions\InfoListAction-&gt;run('area', '1', '107', '0')
  #17 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)
  #18 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\Action-&gt;runWithParams(Array)
  #19 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller-&gt;runAction('list', Array)
  #20 /htdocs/flxx/basic/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module-&gt;runAction('info/list', Array)
  #21 /htdocs/flxx/basic/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application-&gt;handleRequest(Object(yii\web\Request))
  #22 /htdocs/flxx/basic/web/index.php(16): yii\base\Application-&gt;run()
  #23 {main}
  $_SERVER = [
      'USER' =&gt; 'apache',
      'HOME' =&gt; '/usr/share/httpd',
      'HTTP_IF_MODIFIED_SINCE' =&gt; 'Fri, 14 Apr 2017 09:33:39 GMT',
      'HTTP_ACCEPT_ENCODING' =&gt; 'gzip,deflate,br',
      'HTTP_USER_AGENT' =&gt; 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
      'HTTP_FROM' =&gt; 'googlebot(at)googlebot.com',
      'HTTP_ACCEPT' =&gt; 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
      'HTTP_CONNECTION' =&gt; 'Keep-alive',
  </code></pre>
  
  <h2>nginx error log</h2>
  
  <pre><code># /var/log/nginx/error.log
  
  2017/04/24 09:47:41 [crit] 12139#0: *1 stat() "/htdocs/flxx/basic/web/index.php" failed (13: Permission denied), client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1", host: "let
  sclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [crit] 12139#0: *1 stat() "/htdocs/flxx/basic/web/index.php" failed (13: Permission denied), client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1", host: "let
  sclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [crit] 12139#0: *1 stat() "/htdocs/flxx/basic/web/index.php" failed (13: Permission denied), client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1", host: "let
  sclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [crit] 12139#0: *1 stat() "/htdocs/flxx/basic/web/index.php" failed (13: Permission denied), client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1", host: "let
  sclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [crit] 12139#0: *1 stat() "/htdocs/flxx/basic/web/index.php" failed (13: Permission denied), client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1", host: "let
  sclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [error] 12139#0: *1 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/add HTTP/1.1",
   host: "letsclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  2017/04/24 09:47:41 [error] 12139#0: *1 testing "/htdocs/flxx/basic/web" existence failed (13: Permission denied) while logging request, client: 124.42.239.157, server: letsclassifieds.com, request: "GET /info/a
  dd HTTP/1.1", host: "letsclassifieds.com", referrer: "https://letsclassifieds.com/info/area-1-122-0/"
  </code></pre>
  
  <h1>Other Information</h1>
  
  <pre><code>[root@instance-1 basic]# getenforce
  Enforcing
  [root@instance-1 php-fpm.d]# grep -irnE "user|group" /etc/php-fpm.d/www.conf
  4:; Unix user/group of processes
  5:; Note: The user is mandatory. If the group is not set, the default user's group
  8:;user = apache
  9:user = www
  10:; RPM: Keep a group allowed to write in log dir.
  11:group = apache
  
  
  [root@instance-1 htdocs]# chmod -R 777 /htdocs/flxx/basic/web/assets/
  [root@instance-1 htdocs]# ll /htdocs/flxx/basic/web/assets/
  total 8
  drwxrwxrwx. 2 www root   41 Apr 24 08:18 15e6843e
  drwxrwxrwx. 2 www root 4096 Apr 24 08:16 3b2d7f45
  drwxrwxrwx. 2 www root   63 Apr 24 08:16 52081253
  drwxrwxrwx. 7 www root 4096 Apr 24 08:18 f015baee
  drwxrwxrwx. 5 www root   37 Apr 24 08:16 f3c7bc84
  [root@instance-1 ~]# grep -irn "user " /etc/nginx/nginx.conf
  5:user nginx;
  18:    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  [root@instance-1 ~]#
  [root@instance-1 ~]# curl -I https://letsclassifieds.com/info/add
  HTTP/1.1 500 Internal Server Error
  Server: nginx/1.10.2
  Date: Mon, 24 Apr 2017 10:15:51 GMT
  Content-Type: text/html; charset=utf-8
  Content-Length: 193
  Connection: close
  
  [root@instance-1 ~]#
  </code></pre>