CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to set up %ENV on Apache

 



digioleg54
User

Apr 11, 2017, 12:20 PM

Post #1 of 12 (4556 views)
How to set up %ENV on Apache Can't Post

I have apache web server, which is on Linux. I need to set up %ENV for it. How can I do it?


FishMonger
Veteran / Moderator

Apr 11, 2017, 1:26 PM

Post #2 of 12 (4548 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

Your question as stated doesn't make much sense. You need to provide more info on what you're needing to accomplish.

Are you trying to configure apache which is done via the http.conf file, or are you needing to set some specific environment variables in your perl script?


digioleg54
User

Apr 11, 2017, 1:37 PM

Post #3 of 12 (4546 views)
Re: [FishMonger] How to set up %ENV on Apache [In reply to] Can't Post

I don't even know if %ENV exists in apache. My simple script is not working

#!/usr/bin/dwebenv perl

use strict;

foreach my $key (sort keys (%ENV)) {
print "$key = $ENV{$key}\n";
}

give internal error.
In old script (2000)
I found

my($lib_path,$data_path);
BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}

(($ENV{_DATA_DIR}||"") eq "") && ($ENV{_DATA_DIR}=(q{/appdata/dw18637/cgi-data}));
(($ENV{_LOG_DIR}||"") eq "") && ($ENV{_LOG_DIR}=$ENV{_DATA_DIR}.(q{/web_log}));

and so on. That is why I ask if I have to add some paths, into %ENV, or on Apache it exists and I cannot change it?
Now you got enough info, or need more?


FishMonger
Veteran / Moderator

Apr 11, 2017, 1:45 PM

Post #4 of 12 (4542 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

Are you running it as a CGI script, or from the console? If running as a CGI script, then you need to output the content type header prior to anything else, otherwise you'll get an internal server error.


(This post was edited by FishMonger on Apr 11, 2017, 1:45 PM)


FishMonger
Veteran / Moderator

Apr 11, 2017, 1:47 PM

Post #5 of 12 (4540 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post


Quote
I don't even know if %ENV exists in apache.


It doesn't. %ENV is a perl hash which apache doesn't know anything about it.

CGI Environment Variables
http://www.cgi101.com/book/ch3/text.html


(This post was edited by FishMonger on Apr 11, 2017, 1:55 PM)


digioleg54
User

Apr 11, 2017, 1:56 PM

Post #6 of 12 (4535 views)
Re: [FishMonger] How to set up %ENV on Apache [In reply to] Can't Post

I am running it from internet explorer, which link to our apache server

As I understand, the tam, which prepare server for us had some set up for $ENV:
SetEnv DWEB_SITE_ID dw18637
SetEnv DWEB_SITE_PATH /vhosts/dw18637
SetEnv DWEB_TMPDIR /vhosts/dw18637/tmp_cgi
SetEnv TMPDIR /vhosts/dw18637/tmp_cgi
SetEnv ORACLE_HOME /alt/dw18637/oracle
SetEnv TNS_ADMIN /vhosts/dw18637/content/current/contentsys/compiled/oracle
SetEnv FREETDSCONF /vhosts/dw18637/etc/freetds.conf


That is what they gave it to us.


FishMonger
Veteran / Moderator

Apr 11, 2017, 2:12 PM

Post #7 of 12 (4532 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

Those are shell commands that assign environment variables. If the server admins setup you account correctly, then perl will import those vars into the %ENV hash without you needing to do anything. If they didn't set it up correctly, you'll need to manually assign those items in the %ENV hash.

e.g.,

Code
$ENV{'DWEB_SITE_ID'}   = 'dw18637'; 
$ENV{'DWEB_SITE_PATH'} = '/vhosts/dw18637';



FishMonger
Veteran / Moderator

Apr 11, 2017, 2:50 PM

Post #8 of 12 (4528 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

Another option would be to set the env vars in an htaccess file instead of httpd.conf (which is where the server admins would configure it). It appears that the syntax is the same as the shell.

https://httpd.apache.org/docs/2.4/env.html
https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv


(This post was edited by FishMonger on Apr 11, 2017, 2:51 PM)


digioleg54
User

Apr 13, 2017, 5:39 AM

Post #9 of 12 (4506 views)
Re: [FishMonger] How to set up %ENV on Apache [In reply to] Can't Post

Could you please tell me:
Do I have to make a special script, where have line:

SetEnv DTE_WORKING_DIR /export/hone/sh

Or there is another way to do it on Apache? I already have Env.pm package. Should I use it and how?

Thanks


FishMonger
Veteran / Moderator

Apr 13, 2017, 6:08 AM

Post #10 of 12 (4503 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

You can use an appache .htaccess file, as I already mentioned.

https://httpd.apache.org/docs/2.4/howto/htaccess.html
http://www.htaccess-guide.com/


digioleg54
User

Apr 13, 2017, 6:50 AM

Post #11 of 12 (4501 views)
Re: [FishMonger] How to set up %ENV on Apache [In reply to] Can't Post

I found the script, which allowed me to catch all in %ENV.

#!/usr/bin/dwebenv perl

print "Content-type: text/html\n\n";
print "<font size=+1>Environment</font>\n";

foreach (sort keys %ENV) {
print "<b>$_</b>: $ENV{$_}<br>\n";
}

1;


FishMonger
Veteran / Moderator

Apr 13, 2017, 7:13 AM

Post #12 of 12 (4497 views)
Re: [digioleg54] How to set up %ENV on Apache [In reply to] Can't Post

Which is a bad rewrite of the example I pointed you to 2 days ago.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives