2

I have a VirtualHost which direct many subdomains to the same directory.

  • moscow.myapp.com
  • paris.myapp.com

All those websites run on the same application. The only thing I need to change from a subdomain to another is the php setting date.timezone.

I am not able to touche the application code. I am looking for a way to do so directly in the vHost.

Is it possible ? How would you do ?

Thank you very much;

  • If you have a VirtualHost entry for each city you can use the [`php_admin_value`](http://php.net/manual/en/configuration.changes.php) directive to configure a setting specifically for that virtual host. – HBruijn Oct 15 '15 at 13:27
  • I would prefer to keep one vhost for all sites since the timezone is the only param to change. Is there any kind of variable like $subdomain which could help to include extra settings file ? – Paul Etienney Oct 15 '15 at 13:54
  • You can touch the application code, then. That way, you don't have to make any new VirtualHost. – Michael Hampton Oct 15 '15 at 14:13

1 Answers1

1

I have tried and researched a way to set the php_admin_value based on a lookup table or a environment variable (set by SetEnvIf) and setting the variable with php_value, but found nothing that would probably suit you (having all configuration in one VirtualHost).

As a last resort I could advice you to a devious plan, hiding some code...

With the php configuration directive auto_prepend_file you could execute some code before actually starting a script. There you can do a lookup based on the virtual host, or use a variable set by SetEnvIf.

Apache VirtualHost config:

SetEnvIfNoCase Host "^sandbox.coolhaven.info$" TZ=Europe/Moscow
SetEnvIfNoCase Host "^sandbox2.coolhaven.info$" TZ=Europe/Paris

php_value auto_prepend_file /var/www/misc/timezone_injector.php

/var/www/misc/timezone_injector.php

<?php date_default_timezone_set($_ENV["TZ"]);

Of course, the SetEnvIf statements could be moved to a switch statement in your php code.

Your application developer could suspect something happened before their code because the timezone_injector.php will show up in stack traces. But this could be a solution if you have a obfuscated or strict licensed PHP applications you are not able to touch due to non technical reasons.

Joffrey
  • 2,021
  • 1
  • 12
  • 14
  • I was thinking about injecting a script before the index.php but I did not know the auto_prepend_file setting. I will try this today. Thank you very much. – Paul Etienney Oct 16 '15 at 06:46