Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Setting Environment Variables

New Here ,
May 16, 2006 May 16, 2006
Greetings,

My ColdFusion application has to act slightly differently depending on whether it is on the live server or the develop server. The solution that I'm familiar with from other web development platforms is to set an environment variable on the server, which will be accessible from my CFM templates.

Can this be done through the ColdFusion Administrator? If not, can I set a variable from Apache (using 1.3)?

If someone point me in the right direction, I would be most grateful. I've been scouring google and forums for days and have found very little.

Thanks,
Nicholas
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2006 May 18, 2006
The way I do this is by creating a page called Application.cfm. The Application page, by default, is executed before every ColdFusion page. In the Application.cfm you can define whatever environment variables you want and then you will only have to change this page's content depending on what platform you are in.

Hope this helps.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2006 May 18, 2006
Thanks for the response, but that won't work for me.

I'm using version control (Subversion. And you should use it, too), which means all the code for the entire project has to be exactly the same on both live and development servers.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 18, 2006 May 18, 2006
cgi.SERVER_NAME is something you could use.

<cfif cgi.SERVER_NAME eq "liveservername">
... set live parameters
<cfelse>
... set dev/staging/etc parameters
</cfif>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2006 May 18, 2006
Yeah, that was my backup plan. I'm still looking for the right way to do it. Maybe setting an environment variable is not the right way, but there has to be a good way to do this! Other people must encounter this problem on a regular basis. Or mabye ColdFusion developers don't use version control.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 18, 2006 May 18, 2006
nicholas,

I use version control, and I use the cgi.SERVER_NAME method. There's a single Application.cfm file. In that file, for any server-specific variables, I wrap them in the <cfif...> I posted in my first message.

You were asking about how to set an environment variable that you could access from your CFM templates. With cgi.SERVER_NAME, you don't _need_ to set an environment variable, because it's already set. And it's something you can use.

Another way would be to set a java environment variable in the jvm.config file, then use java calls to pull that out.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2006 May 18, 2006
LATEST
Kronin,
Thanks for your help. It looks like I'm going to have to check the server name, like you suggested. Although it still seems like a hack to me (read: not ideal), the more I think about it, the more acceptable that solution is (or maybe I get more desperate as time goes on).

Thanks a lot for your help. I'm sorry for using a condescending tone in my previous message.

Best of luck,
Nicholas
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources