7

I've been using MediaTemple's GridService as a production environment for a couple of relatively lightweight PHP sites. The process of setting up testing and staging environments is kind of cumbersome and leads to staff taking shortcuts, so I'm trying to put together a quality control environment that provides a similar environment to GridService but that allows me to hook it more closely to our automated deployment process (provisioning new environments in GridService requires you to use the web interface; mod_vhost_alias would just allow us to create directories that are subdomains of our test url).

I am very, very close, but encountered an issue - with PHP running as CGI, apache automatically prepends REDIRECT_ to any variables I set in .htaccess (remember, I'm simulating GridService) using SetEnv. For example:

.htaccess

SetEnv HTTP_TEST_VAR "Some Value"

PHP

echo getenv('HTTP_TEST_VAR'); // prints ""
echo getenv('REDIRECT_HTTP_TEST_VAR'); // prints "Some Value"

This wouldn't be a big deal (we could code around it), except that it doesn't happen in GridService, and I really would prefer to have identical code paths (adding switching logic to the code would defeat the point of all the work we've done to get configuration out of the codebase).

For the rest of the background, I'm using a brand new (2 weeks old) (ve) instance running Ubuntu, got apache and all dependencies from apt, and built PHP (5.3.15) using the configure string from a <?php phpinfo() ?> on GridService, minus db4 support.

I would really appreciate any help. Thanks!

Kurt
  • 73
  • 1
  • 3
  • does your .htaccess contain any RewriteRule that would change the URL and thus trigger an internal redirect? – Charon ME Jun 16 '20 at 08:42

2 Answers2

5

Don't know will it be a good solution, but PHP running in FastCGI mode (mod_fastcgi) runs OK with SetEnv variables without prepending it with REDIRECT_.

Had the same issue with PHP running in CGI mode, solved by switching to FastCGI.

Andrei Mikhaltsov
  • 2,987
  • 1
  • 22
  • 31
  • Thanks Andrei - I was beginning to suspect that might work. It wasn't really easy to find documentation on this feature. I'll give it a shot and see what I find. – Kurt Aug 16 '12 at 17:10
  • I am running with Apache 2.4 + mod_fastcgi + php-fpm, it still happens, I think the cause is because the 'Alias' directive, but have no idea how to make it work without this directive. – weynhamz Dec 14 '17 at 04:14
2

I don't think you can change this behaviour with php-cgi as in effect it is a redirect. Note though that the php getenv() function return value

Returns the value of the environment variable varname, or FALSE if the environment variable varname does not exist.

so you can easily construct a function that returns the value whether it's REDIRECT_ or not.

user9517
  • 114,104
  • 20
  • 206
  • 289