homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Perl and Apache
configuring Apache to execute Perl script
nyteshade




msg:4437581
 4:52 pm on Apr 5, 2012 (gmt 0)

Apache scares me! Every time I have to tinker with it I'm afraid I'll break it. I considered myself thankful that I got PHP and virtual hosting up and running. Now I want to learn Perl and here I am again, stuck. I've read the Apache docs on directives and I think I know what Perl script requires but when I try to execute the following script then I get a 404 not found error:


#!c:\Dwimperl\perl\site\bin\perl.exe
print "Content-type: text/html; charset=iso-8859-1\n\n";
print "<phtml>";
print "<body>";
print "Test Page";
print "</body>";
print "</html>";


The file is located in
C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin. If I place it in the htdocs directory then the browser simply displays the content of the file instead of executing it!

These are the changes to httpd.conf file I made after installing Perl:


#changes I made to my httpd.conf
#these are in top-down order

#defaults
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

#altered defaults for Perl
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
# add FollowSymLinks +ExecCGI for Perl to execute outside of cgi-bin
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>

#directive to id cgi-bin
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin"
</IfModule>

#permissions for cgi-bin
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

#add handler to execute .cgi .pl outside of cgi-bin
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#out of desperation! also altered the
#the Options above to make this work, but it doesn't!
AddHandler cgi-script .cgi .pl
</IfModule>


None of what I tried above works so I thought maybe I needed to change my httpd-vhosts.conf to include the new directives:


NameVirtualHost *:80


<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>

<Directory "C:/vHosts/rcs.meinsandkasten.com/web">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>


...that doesn't work, but it doesn't blow up, everything still works except Perl. Help! thanks all.

no, it does blow up when I make changes to my httpd-vhosts.conf file, the includes fail, so I'm removing those changes... arrrgh!

 

nyteshade




msg:4437769
 11:17 pm on Apr 5, 2012 (gmt 0)

My error log contains:

[Thu Apr 05 19:05:07 2012] [error] [client 127.0.0.1] Options ExecCGI is off in this directory: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/test.pl


So I'm back at [httpd.apache.org ] that seems to say change

#permissions for cgi-bin
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
AllowOverride None
#Options None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>


...but still get the same error... trudging on...

enigma1




msg:4437871
 9:04 am on Apr 6, 2012 (gmt 0)

Can you try with a totally different folder and see if it works?

C:/Program Files/Apache Software Foundation/Apache2.2/test

It maybe something that overrides it.

Another thing you could test is to use the location directive at the end of the httpd.conf. If it works it surely something else that overrides it.

<Location /test>
Options +ExecCGI
</Location>

nyteshade




msg:4437895
 10:32 am on Apr 6, 2012 (gmt 0)

enigma: I've tried your suggestions and the error log tells me file not found. Here's my httpd.conf file, it's still about the same as when I installed Apache2.2, save for the PHP module. I'm simply trying to run the default Perl file printenv.pl with no success.

The Perl file:

#!c:/Dwimperl/perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}


The httpd.conf file:


ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.2"

Listen *:80

LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>
</IfModule>

ServerAdmin me@myemail.com

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

#default
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

#server root permissions
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
Options Indexes FollowSymLinks MultiViews +Includes
Order allow,deny
Allow from all
</Directory>

#valid index pages
<IfModule dir_module>
DirectoryIndex index.php index.html index.shtml
</IfModule>

#deny visitor access to .htaccess
#<FilesMatch "^\.ht">
# Order allow,deny
# Deny from all
# Satisfy All
#</FilesMatch>

ErrorLog "logs/error.log"

LogLevel warn

<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access.log" common
</IfModule>

#cgi executable dir
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin"
</IfModule>

#cgi-bin permissions
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
Options +ExecCGI
AllowOverride None
Order deny,allow
Deny from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi .pl
AddHandler server-parsed .shtml
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>

Include conf/extra/httpd-vhosts.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

#PHP5
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"


I've seen similar posts regarding permissions on the cgi-bin but those folks are not under WinXP SP3 like me, that didn't stop me from trying their suggestions; still no joy. Apache though has been patient and forgiving yet a hard task-master.... trudging on.

phranque




msg:4437918
 11:24 am on Apr 6, 2012 (gmt 0)

you're always better off using no blanks and all lower case in file and directory names, but that's another discussion.

you need to put the script in C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/test.pl

and then assuming the hash bang line in the script is correct...
#!c:/Dwimperl/perl/bin/perl.exe


and you have this in the httpd.conf file:

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin"
<Directory C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin >
SetHandler cgi-script
Options ExecCGI
</Directory>


and then your requested url should be http://example.com/cgi-cin/test.pl

enigma1




msg:4437934
 12:04 pm on Apr 6, 2012 (gmt 0)

Well I didn't changed anything about the cgi-bin on a default apache 2.2 install. I installed the strawberry perl and the printenv.pl runs ok on winxp using [localhost...]

The script alias is in by default in the alias_module. Not sure about the backslashes you use though. When I configured the server I used forward slashes everywhere and in the pl hash line.

nyteshade




msg:4437977
 2:13 pm on Apr 6, 2012 (gmt 0)

phranque: I tried the following with your suggestions:


#cgi executable dir
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
</IfModule>

#cgi-bin permissions
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/">
SetHandler cgi-script
Options ExecCGI
</Directory>


What I discovered when viewing the error.log was that I needed to append a forward slash at the end of the directory path; but still no joy:

[Fri Apr 06 09:24:20 2012] [error] [client 127.0.0.1] client denied by server configuration: C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/test.pl


I've tried placing the <Directory /...></Directory> just before loading the PHP module just in case something in the <IfModule mime_module> was overriding the directive, still not working.

enigma: thanks for the link, I understand now that the correct URL is localhost/cgi-bin/test.pl ... still no joy.

I have tried:


#cgi executable dir
<IfModule alias_module>
ScriptAlias /test/ "C:/Program Files/Apache Software Foundation/Apache2.2/test/"
</IfModule>

#cgi-bin permissions
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/test/">
SetHandler cgi-script
Options ExecCGI
</Directory>


Using your suggestion to create a new folder called test; the error.log reflects:

[Fri Apr 06 09:32:05 2012] [error] [client 127.0.0.1] client denied by server configuration: C:/Program Files/Apache Software Foundation/Apache2.2/test/test.pl


The so called 'shebang' line in my Perl script reflects the exact location of perl.exe; I made sure by copying the path straight from internet.exe which is

C:\Dwimperl\perl\bin


and the path to my cgi-bin is:

C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin


...and changing the '\' to '/' before using them. I'm being as careful and concise as I can cause I don't want you folks to get anxious that I'm not paying attention to your suggestions, and I do appreciate the help; still reading the Apache documentation and looking for answers. It's something to do with how permissions are being applied I think. When I read about linux issues regarding this those folks are able to alter permissions on directories that are not available to winXP users it seems.

Also, I don't think the spaces in the path are an issue as long as the path is enclosed with quotes?

What is standing out in the error message is "client denied by server configuration", so I'm thinking that the 'shebang' line is ok else Perl interpreter would issue a warning?

enigma1




msg:4437993
 3:16 pm on Apr 6, 2012 (gmt 0)

If you comment out the cgi-bin permissions section do you still get the client denied error?

nyteshade




msg:4438036
 4:09 pm on Apr 6, 2012 (gmt 0)

Yes, still denied when I type in the address box:

http://localhost/cgi-bin/test.pl



#cgi executable dir
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
</IfModule>

#cgi-bin permissions
#<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/">
#SetHandler cgi-script
#Options ExecCGI
#</Directory>


...will generate:


[Fri Apr 06 12:02:01 2012] [error] [client 127.0.0.1] client denied by server configuration: C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/test.pl


When testing I will restart Apache and the browser (FF and Chrome)... occasionally I'll reboot; no luck, something smells. This can't be that hard, somewhere there is a simple mistake I'm overlooking.

Also, I'm working on this locally of course, but I've put some images of the directories and pl files at this link [meinsandkasten.com ] so you may inspect the veracity of my claims to path and 'shebang' etc. This may give you a level of comfort that I'm not mis-keying something, of course you may spot something I'm missing. Thanks all!

[edited by: nyteshade at 4:47 pm (utc) on Apr 6, 2012]

enigma1




msg:4438050
 4:39 pm on Apr 6, 2012 (gmt 0)

Ok you need to figure out which directive causes the deny. If this is a test env/server it shouldn't be a problem to comment out the directory sections and the extra config

Include conf/extra/httpd-vhosts.conf
not sure what you have in it.

nyteshade




msg:4438079
 5:41 pm on Apr 6, 2012 (gmt 0)

We're in the pipe 5x5! I started with little changes seeing how Apache isn't as fragile as my ego thought; rebooted and viola! My httpd.conf looks like this:


ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.2"

Listen *:80

LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>
</IfModule>

ServerAdmin me@myemail.com

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

#default
#<Directory />
# Options FollowSymLinks
# AllowOverride None
# Order deny,allow
# Deny from all
#</Directory>

#server root permissions
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
Options Indexes FollowSymLinks MultiViews +Includes
Order allow,deny
Allow from all
</Directory>

#valid index pages
<IfModule dir_module>
DirectoryIndex index.php index.html index.shtml
</IfModule>

#deny visitor access to .htaccess
#<FilesMatch "^\.ht">
# Order allow,deny
# Deny from all
# Satisfy All
#</FilesMatch>

ErrorLog "logs/error.log"

LogLevel warn

<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access.log" common
</IfModule>

#cgi executable dir
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
</IfModule>

#cgi-bin permissions
#<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/">
#SetHandler cgi-script
#Options ExecCGI
#</Directory>

DefaultType text/plain

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi .pl
AddHandler server-parsed .shtml
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>

Include conf/extra/httpd-vhosts.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

#PHP5
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"


The 'extra' config is for my local virtual hosting btw. And, for some reason the test.pl was generating a Internal Server Error while the printenv.pl worked? I think something crawled in the test.pl, like a hidden character, I dunno; I saw a little rectangle in it and decided to just delete the file, created a new test.pl and it worked just fine. Anyway, thanks for the help. I'll begin uncommenting little by little and see what else happens. Peace.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved