我找到了很多关于Perl的东西,但是没有关于C++的。我现在正在使用Ubuntu,但是对它不太熟悉,所以简单的指示会很棒。我刚刚编写了一个小的C++程序,并将其制作成CGI,我需要测试一下。谢谢!
*.cgi
的可执行文件(或其他文件名),并确保你拥有。AddHandler cgi-script .cgi
.htaccess
等文件中,加入或修改类似的内容。(免责声明:我已经很多年没做过这个了,所以可能会遗漏一些东西。但我认为这就是您需要的全部内容。)对于C++程序来说,没有什么特别之处。CGI程序是由Web服务器执行的。因此,它们的前提条件与Perl脚本/程序相同。
以下是一些提示,帮助您启动和运行C++ CGI程序。
Put a simple executable in the cgi-bin directory and make it executable by the web server. Prepare a simple program returning a valid CGI response, e.g.
#include <iostream>
using namespace std;
int main()
{
cout << "Content-Type: text/html" << endl << endl;
cout << "Hello to Apache and Firefox!" << endl;
return 0;
}
Execute the program on the command line and check that the output starts with the following lines. Ensure the empty line after the Content-Type.
$ ./hello_world
Content-Type: text/html
Hello to Apache and Firefox!
Increase the LogLevel to debug and look into the web server error logs. Search the access log, the error log and the suexec.log. Look in the log from the virtual host you are using and in the main error.log, too. On my Ubuntu system the files are located in /var/log/apache2
and named access.log, error.log and suexec.log. One of my last problems was "directory is writable by others: ..."
When using DLLs ensure that the libraries are still available on the web server. Set the RPATH to point to a custom directory with the libraries. In this context ldd
and objdump -x <executable> | grep RPATH
are your friends.
(This tip from Apache documentation has not worked for me: Watch the input and output using the ScriptLog Directive from the mod_cgi module of Apache. ScriptLog should only be used on an Development Server. Further details are available from the mod_cgi page.)
More hints are shown in the article Debugging Apache Web Server Problems.