Problem with Executing CGI Scripts on Apache

∥☆過路亽.° 提交于 2019-12-23 19:16:04

问题


Pretty much a complete Linux/Apache newbie here, I am in the process of moving a site from a shared host to a Linode VPS. It's all been going smoothly until I starting trying to move my Moveable Type blog which runs using a series of CGI scripts. I am running Ubuntu 10.04 and Apache2. After hours of messing about I got a PERL hello world script (hello.cgi) to execute from a the web browser in the root HTML directory. Here's the script:

#!/usr/bin/perl -w
use strict;
print "Content-Type: text/html\n\nHello world!";

I got this working by adding the following to the /etc/apache2/sites-available/mysitename.com file.

<Directory /srv/www/mysitename.com/public_html/>
    Options +ExecCGI
    AddHandler cgi-script .cgi
</Directory>

But I want to execute CGI scripts in the /srv/www/mysitename.com/public_html/mt/ directory, so I changed the directory in the entry above to that path and when I view the hello world script in that folder via a browser I see the source for the hello.cgi script rather than the output. Clearly something isn't right. I've spent more than enough time trying to work this out myself and the time has come to ask for help. So, anyone got any suggestions? Please keep answers simple I really am just learning to tread water Linux/Apache2 wise here!

Solution Found:

<VirtualHost *:80>
  ServerName www.sitename.com
  ServerAdmin general@sitename.com
  ServerAlias sitename.com
  DocumentRoot /srv/www/mysitename.com/public_html/
  ErrorLog /srv/www/mysitename.com/logs/error.log
  CustomLog /srv/www/mysitename.com/logs/access.log combined
  AddHandler cgi-script .cgi .pl
</VirtualHost>

<Directory /srv/www/mysitename.com/public_html/>
    AllowOverride All
    Order allow,deny
    Allow from all
    Options All +SymLinksIfOwnerMatch +FollowSymLinks +ExecCGI -Indexes -MultiViews
</Directory>

<Directory /srv/www/mysitename.com/public_html/mt/>
    AllowOverride All
    Order allow,deny
    Allow from all
    Options All +SymLinksIfOwnerMatch +FollowSymLinks +ExecCGI -Indexes -MultiViews
</Directory>

回答1:


Have you added mod-perl?

Add these lines

AddType perl-script .pl
AddHandler perl-script .htm

specify a DirectoryIndex

(outside the Directory block)

Are you using vhosts too? I wouldn't normally do things the way you're doing them to be honest.



来源:https://stackoverflow.com/questions/4522906/problem-with-executing-cgi-scripts-on-apache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!