我刚刚安装了Ubuntu 13.10,并且正在尝试安装Apache。但是,当我尝试在cgi-bin中运行perl文件时,浏览器只显示纯文本。
我的Apache的default.conf如下:
AddHandler cgi-script .cgi .pl
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +Indexes +ExecCGI +MultiViews +SymLinksIfOwnerMatch
#Order allow,deny
Require all granted
Allow from all
</Directory>
这是我的perl cgi文件:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<title> PERL CGI</title>\n";
print "<body>";
print "hello perl-cgi!!!!!!!";
print "</body>";
print "</html>\n";
我在usr中打开了处理程序,这个文件在/ mime.conf /lib/cgi-bin中,我以http而不是file:///.的身份运行它我还安装了mod_perl。我是Apache的新手。我已经搜索了几个小时,尝试了无数的Apache配置,阅读了Apache文档,但仍然无法解决它。是不是因为"+ExecCGI“代码有问题?我看到另一个人在将Ubuntu 12.04升级到13.10后也遇到了类似的问题。也许Ubuntu才是问题所在?请帮帮忙。Apache配置和Ubuntu权限几乎让我抓狂。
发布于 2013-12-09 23:06:42
尝试使用以下命令:
sudo a2enmod cgi
然后重新启动apache!
发布于 2014-07-29 10:25:21
我在Ubuntu 14.04中设置bugzilla时遇到了这个问题,@Andrew的回答很有帮助,@Kevin的链接也是如此。因此,除了启用cgi之外,还要确保安装了用于apache2的perl模块。您可以通过以下方式完成此操作:
sudo apt-get install libapache2-mod-perl2
这将自动启用该模块并重新启动apache服务器。如果不是,则手动执行该操作。
没有足够的代表来给你们两个人投票,所以谢谢。
发布于 2017-09-07 18:27:36
确保启用了apache cgi模式
sudo a2enmod cgi //will enable the cgi mode
sudo a2dismod cgi //Will disable the cgi mode
将所有文件保存在webroot "cgi-bin“文件夹下
sudo mkdir /home/www/cgi-bin
请确保对.cgi文件的文件权限为okay
sudo chmod 755 yourFile.cgi
尝试通过终端执行它
perl /Path_To_The_File/fileName.cgi
确保您的fileName.cgi在文件顶部包含以下代码
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
如果以上步骤都运行良好,那么
在apache中为perl项目创建虚拟主机
cp /etc/apache2/sites-available/000-default.conf ./your_project.conf
sudo nano /etc/apache2/sites-available/your_project.conf
在your_project.conf文件中,替换以下行
<VirtualHost *:80>
ServerAdmin xyz@gmail.com
DocumentRoot /var/www/html/cgi-bin //Define where your project is
ServerName your_project.com //URL through which you want to access
ServerAlias your_project.com
ErrorLog ${APACHE_LOG_DIR}/error.log //Error for the project will store in this file
CustomLog ${APACHE_LOG_DIR}/access.log combined
ScriptAlias /cgi-bin/ "/var/www/html/cgi-bin/" //particular directory is set aside for CGI programs
<Directory /var/www/html/cgi-bin/>
##TO consider the files as cgi which has .cgi and .pl extension
Options +ExecCGI
AddHandler cgi-script .cgi .pl
##To consider all files as cgi file (if want to use remove # from last two line add in above 2 line)
#Options ExecCGI
#SetHandler cgi-script
</Directory>
</VirtualHost>
运行这些命令
sudo a2ensite your_project.conf //Will enable your configuration file
sudo service apache2 restart //Restarting apache2
添加您的主机
sudo nano /etc/hosts
//add this line
127.0.0.1 your_project.com
现在运行执行cgi文件
your_project.com/cgi-bin/fileName.cgi
https://stackoverflow.com/questions/20172518
复制相似问题