我已经用 C++ 编写了一个程序并用 gcc 编译了它(就像 fastcgi.com 中的示例)但是我不知道如何在本地主机上运行它。
到处搜索,我发现 mod_fcgi 的 php 配置不起作用 对于 C++。
是否有人配置了 apache 和 mod_fcgi 来运行 c++ web 应用程序???
最佳答案
mod_fcgi?我只找到了 mod_fastcgi 和 mod_fcgid。两者的 Apache 配置看起来都非常简单。让我们编译 FastCGI 示例并创建一个简约的 Apache 实例来为其提供服务:
安装 libfcgi-dev
在某处创建临时目录并编译来自https://opensource.apple.com/source/FastCGI/FastCGI-4/fcgi/doc/fcgi-devel-kit.htm#S3.1 的示例
当你简单地运行它时,它已经有一些输出:
$ ./tiny-cgi Content-type: text/html <title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 1 running on host <i>(null)</i>
安装 apache2 和 libapache2-mod-fcgid;创建配置文件 apache.conf:
User www-data Listen 8080 PidFile apache.pid DocumentRoot . LoadModule fcgid_module /usr/lib/apache2/modules/mod_fcgid.so SetHandler fcgid-script Options +ExecCGI ErrorLog error.log
用户 www-data 很重要,因为它可以访问
/var/lib/apache2/fcgid/sock/
,这对 fcgid 非常重要(我在 Debian 上运行,也许在其他地方它会有所不同)。将 DocumentRoot 与其他目录放在同一目录中并不是很好,但这只是一个简单的示例。运行
sudo/usr/sbin/apache2 -d 。 -f apache.conf -X
那个
-X
是debug模式,当server不daemonize(不detach)的时候,这样玩还是挺方便的。转到
http://localhost:8080/tiny-cgi
,您将在其中看到 FastCGI 程序的输出。如果不是,请参阅error.log
。停止 Apache,安装 libapache2-mod-fastcgi,将配置中的两行替换为:
LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so SetHandler fastcgi-script
再次访问
http://localhost:8080/tiny-cgi
。
关于c++ - 如何配置 apache2 和 fastCGI 来运行我的 C++ 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3781979/