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



digioleg54
User

Apr 11, 2017, 12:20 PM


Views: 10456
How to set up %ENV on Apache

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


Views: 10448
Re: [digioleg54] How to set up %ENV on Apache

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


Views: 10446
Re: [FishMonger] How to set up %ENV on Apache

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


Views: 10442
Re: [digioleg54] How to set up %ENV on Apache

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


Views: 10440
Re: [digioleg54] How to set up %ENV on Apache


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


Views: 10435
Re: [FishMonger] How to set up %ENV on Apache

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


Views: 10432
Re: [digioleg54] How to set up %ENV on Apache

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


Views: 10428
Re: [digioleg54] How to set up %ENV on Apache

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


Views: 10406
Re: [FishMonger] How to set up %ENV on Apache

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


Views: 10403
Re: [digioleg54] How to set up %ENV on Apache

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


Views: 10401
Re: [FishMonger] How to set up %ENV on Apache

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


Views: 10397
Re: [digioleg54] How to set up %ENV on Apache

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