首先,修改apache2.conf
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
Options All
然后修改vim /etc/apache2/mods-enabled/cigd.load
内容为
LoadModule cgid_module /usr/lib/apache2/modules/mod_cgid.so
AddHandler cgi-script .cgi .pl .py .sh
此即同时支持py .cgi .sh脚本的执行 修改sites-available内容为
ServerAdmin webmaster@localhost
DocumentRoot /var/www/cgi-bin
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
添加ports.conf内容为Listen 8080 向/var/www/cgi-bin内写入 index.cpp
#include
using namespace std;
int main ()
{
cout << "Content-type:text/html\r\n\r\n";
cout << "\n";
cout << "
\n";cout << "
Hello World - First CGI Program\n";cout << "\n";
cout << "
\n";cout << "
Hello World!
\n";cout << "\n";
cout << "\n";
return 0;
}
使用指令
gcc -o index.cgi index.cpp
浏览器打开127.0.0.1:8080 即可看到你用C语言写的HelloWorld了