title: How set an environment variable in PHP with Apache/FastCGI?
body: <p>I need to define an environment variable named <code>SQLANY17</code> and this variable  should be available in PHP (i.e. under "Environment" in the standard <code>phpinfo()</code> page). PHP is executed via FastCGI and I'm running CentOS 7 x64, Apache 2.4.6 and PHP 5.5.30.</p>
  
  <p>I've edited <code>/etc/httpd/conf.d/fcgid.conf</code> which already exists in my distribution. <a href="http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidinitialenv" rel="nofollow noreferrer">According to the documentation</a> an environment can be defined using FcgidInitialEnv.</p>
  
  <pre><code>&lt;IfModule mod_fcgid.c&gt;
    # ...
    FcgidInitialEnv SQLANY17 /opt/sqlanywhere17
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>However this doesn't work, even after a full machine reboot. Any ideas? I'm sure the <code>fcgid.conf</code> is correcly parsed because typing some random chars prevent the Apache server restart.</p>
  
  <p><a href="https://i.stack.imgur.com/kAHGg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kAHGg.png" alt="enter image description here"></a></p>
  
  <p>In my setup Nginx proxies requests to Apache This is <code>nginx.conf</code> for host example.com:</p>
  
  <pre><code>server {
      listen 192.168.1.131:80;
  
      server_name example.com;
      server_name www.example.com;
      server_name ipv4.example.com;
  
      client_max_body_size 128m;
  
      root "/var/www/vhosts/example.com/httpdocs";
      access_log "/var/www/vhosts/system/example.com/logs/proxy_access_log";
      error_log "/var/www/vhosts/system/example.com/logs/proxy_error_log";
  
      if ($host ~* ^www.example.com$) {
          rewrite ^(.*)$ http://example.com$1 permanent;
      }
  
      location / {
          proxy_pass http://192.168.1.131:7080;
          proxy_set_header Host             $host;
          proxy_set_header X-Real-IP        $remote_addr;
          proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header X-Accel-Internal /internal-nginx-static-location;
          access_log off;
      }
  }
  </code></pre>
  
  <p>And this is <code>httpd.conf</code> for the same host:</p>
  
  <pre><code>&lt;VirtualHost 192.168.1.131:7080 &gt;
      ServerName "example.com:80"
      ServerAlias "www.example.com"
      ServerAlias "ipv4.example.com"
      ServerAdmin "administrator@example.com"
      UseCanonicalName Off
  
      DocumentRoot "/var/www/vhosts/example.com/httpdocs"
      CustomLog /var/www/vhosts/system/example.com/logs/access_log
      ErrorLog "/var/www/vhosts/system/example.com/logs/error_log"
  
      &lt;IfModule mod_suexec.c&gt;
          SuexecUserGroup "example" "psacln"
      &lt;/IfModule&gt;
  
      &lt;IfModule mod_fcgid.c&gt;
          FcgidInitialEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/example.com/etc/php.ini
          FcgidInitialEnv PP_CUSTOM_PHP_CGI_INDEX plesk-php55-fastcgi
          FcgidMaxRequestLen 134217728
      &lt;/IfModule&gt;
  
      &lt;Directory /var/www/vhosts/example.com/httpdocs&gt;
          &lt;IfModule mod_fcgid.c&gt;
              &lt;Files ~ (\.php$)&gt;
                  SetHandler fcgid-script
                  FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
                  Options +ExecCGI
              &lt;/Files&gt;
          &lt;/IfModule&gt;
  
          Options -Includes -ExecCGI
      &lt;/Directory&gt;
  
      &lt;IfModule mod_rewrite.c&gt;
          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
          RewriteRule ^(.*)$ http://example.com$1 [L,R=301]
      &lt;/IfModule&gt;
  &lt;/VirtualHost&gt;
  </code></pre>