简体   繁体   English

CGI脚本在Apache2(localhost)中显示为纯文本

[英]CGI Script displayed as Plain Text in Apache2 (localhost)

I currently have to do a web server in Apache2 that consists on a Login/Register web, and I have to call a CGI Script to validate the input data from the user. 当前,我必须在Apache2中做一个包含登录/注册Web的Web服务器,并且必须调用CGI脚本来验证来自用户的输入数据。 Well, when I call the script with the submit button, the CGI Script appears as Plain Text, and I don't know what else to do to fix it. 好吧,当我使用“提交”按钮调用脚本时,CGI脚本显示为“纯文本”,我不知道该怎么做才能修复它。

I have tried uncommenting CGI Modules in /etc/apache2/httpd.conf, setting a default directory for CGI Scripts, uncommenting the AddHandler for CGI and changing Options values in my localhost directory and in the CGI directory adding ExecCGI in them all. 我尝试取消注释/etc/apache2/httpd.conf中的CGI模块,设置CGI脚本的默认目录,取消注释CGI的AddHandler并更改我的localhost目录和CGI目录中的Options值,并在其中全部添加了ExecCGI。 But it still does not work, it just appears as plain text. 但是它仍然不起作用,只是显示为纯文本。

PS: I followed this tutorial ( http://httpd.apache.org/docs/2.2/howto/cgi.html ) and also looked for the solution here in StackOverflow, but I got nothing working for me. PS:我遵循了本教程( http://httpd.apache.org/docs/2.2/howto/cgi.html ),并在StackOverflow中寻找解决方案,但没有任何帮助。

Edit: Also thank you for helping if you do :) 编辑:还要感谢您的帮助:)

The problem was the directory configuration, so I kept the default http.config file, that has a preset ScriptAlias for the /cgi-bin/ directory to the following directory: 问题在于目录配置,因此我保留了默认的http.config文件,该文件的/ cgi-bin /目录具有以下目录的预设ScriptAlias:

/Library/WebServer/CGI-Executables /图书馆/ WebServer / CGI-可执行文件

Then I enabled the CGI Module by uncommenting the line (removing the '#' before the line) in the httpd.conf file from apache2: 然后,我通过取消注释来自apache2的httpd.conf文件中的行(删除该行之前的“#”)来启用CGI模块:

LoadModule cgi_module libexec/apache2/mod_cgi.so LoadModule cgi_module libexec / apache2 / mod_cgi.so

Finally I saved the file, and then I restarted the Apache2 server using the command: 最后,我保存了文件,然后使用以下命令重新启动了Apache2服务器:

sudo /usr/sbin/apachectl restart sudo / usr / sbin / apachectl重新启动

Then I just pasted the .cgi script in the CGI-Executables directory, setting the permissions of the file as chmod a+x . 然后,我只是将.cgi脚本粘贴到CGI-Executables目录中,将文件的权限设置为chmod a + x

To run the script now you just have to access 要立即运行脚本,您只需访问

localhost/cgi-bin/script.cgi 本地主机/cgi-bin/script.cgi

Thank you for the help anyways! 无论如何,谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM