Solved

PHP Environment Variables when moving website from Unix/Apache to Windows/IIS

Posted on 2009-07-16
6
887 Views
Last Modified: 2013-12-13
I'm trying to port an existing website from a Unix/Apache shared hosting environment (hosted on fluidhosting.com) to a Windows/IIS 7 shared hosting environment (hosted on aplus.net). How would I go about translating the following .htaccess file contents:

SetEnv XML_PARSER_CLASS /hsphere/local/home2/cpacweb/lib/GreenTree/Util/XMLParser.php
SetEnv CONFIG_CLASS /hsphere/local/home2/cpacweb/lib/GreenTree/Util/Config.php
SetEnv CONFIG_FILE /hsphere/local/home2/cpacweb/etc/production.xml

Specifically, I'm looking for the steps to properly set the above environment variables, which are referenced on nearly every webpage on the website. Based off my website directory configuration, I think I can correctly replace the "/hsphere/local ..." with "D:\inetpub\virtual ... \wwwroot" location.

In the UNIX environment, doing a "echo getenv('XML_PARSER_CLASS');" would output a string. Doing it in the Windows environment outputs nothing.

The attached phpinfo.pdf file contains information for the Windows/IIS environment.
PHPinfo.pdf
0
Comment
Question by:satellitea105
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:yfastud
ID: 24875690
On Windows, use $_SERVER instead
0
 

Author Comment

by:satellitea105
ID: 24878309
Thanks for the information. However, where I would place the $_SERVER variables such that it would be seen from every single webpage?

In other words, the following exists everywhere in my code:

include_once(getenv('XML_PARSER_CLASS'));

Where would I place the $_SERVER so that every single .php file would see that the XML_PARSER_CLASS variable = '/hsphere/local/home2/cpacweb/lib/GreenTree/Util/XMLParser.php'?
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24879557
Unfortunately, from my research, there is no equivalent on IIS unless you install a 3rd party module. For example: http://www.helicontech.com/ape/doc/mod_env.htm and for this you either need admin rights to the server or you need to get the admin to install it.

Without this you are probably talking about a lot or work modifying the scripts so that they will work cross platform. There are many things that work on Apache that to not work on IIS. Another example is the server variable $_SERVER['DOCUMENT_ROOT']. This does not exist on IIS and you must use an alternate means to obtain the value.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 8

Expert Comment

by:yfastud
ID: 24883406
@ Hube02
the author meant to use Apache on Win

@ satellitea105
instead getenv('XML_PARSER_CLASS') did you try this $_SERVER['XML_PARSER_CLASS'] ?
0
 
LVL 18

Accepted Solution

by:
Hube02 earned 125 total points
ID: 24883598
>>> I'm trying to port an existing website from a Unix/Apache ....... to a Windows/IIS 7 ....... <<<<

I think I got that.

The goal is to not rewrite all of the script so that they can continue to use:

include_once(getenv('XML_PARSER_CLASS'));

If you are suggesting this:

$_SERVER['XML_PARSER_CLASS'] = 'some value here';

this does not work, this simple test shows this:

<?php
      
      $_SERVER['XML_PARSER_CLASS'] = 'test';
      echo '('.getenv('XML_PARSER_CLASS').')';
      
?>

The above will echo an empty set of parenthesis ()

This means that he would need to call a configuration script to set the server variable and then edit all instances where the getenv.... is used to get that value set using $_SERVER

the .htaccess method does this without the need to call a configuration file, it simply make the value available.

Another possibility might be to use a configuration file to set environment variables:

<?php
      
      putenv('XML_PARSER_CLASS=path');
      echo '('.getenv('XML_PARSER_CLASS').')';
      
?>

This works, but will still require calling the configuration file from every page of the site thus needing to edit every page on the site. However, depending on php.ini settings, this could fail as well if safe_mode is set to on (which is the case on many shared hosting environments. The following is a snippet from php.ini:

=================
; Setting certain environment variables may be a potential security breach.
; This directive contains a comma-delimited list of prefixes.  In Safe Mode,
; the user may only alter environment variables whose names begin with the
; prefixes supplied here.  By default, users will only be able to set
; environment variables that begin with PHP_ (e.g. PHP_FOO=BAR).
;
; Note:  If this directive is empty, PHP will let the user modify ANY
; environment variable!
safe_mode_allowed_env_vars = PHP_
==================

The .htaccess method is like a global configuration and makes it possible to not need to set these variables withing PHP iteslf or to call configuration script to do the work, and will work no matter what the setting in php.ini.


0
 
LVL 18

Expert Comment

by:Hube02
ID: 24885794
@satellitea105:

Just out of curiosity, what path did you decide to take.
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whitelisting IP's in .htaccess? 2 24
How can I send attachment with mail 5 26
Considerations PHP using multiple locations 9 34
Services disabled 1 31
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question