如何在Ubuntu上架設Apache2 server ?
環境:
192.168.0.101 (Ubuntun)安裝:
sudo apt-get install apache2啟用Cgi模組:
sudo a2enmod cgi編輯Apache2 conf檔:
vim /etc/apache2/apache2.conf----------------------------------------------------------------------
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory /var/www/cgi-bin/>
AddHandler cgi-script cgi
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
重新啟動Apache2:
sudo service apache2 restart撰寫Cgi程式:
vim index.cpp----------------------------------------------------------
#include <stdio.h>
int main(int argc, char *argv[]) {
printf ("Content-type: text/html\n\n");
printf ("<html>\n");
printf ("\t<head>\n");
printf ("\t\t<titLe>!!! Hello, world!!!</title>\n");
printf ("\t</head>\n");
printf ("\t<body>\n");
printf ("\t\t<h1>hello~~~~~~~</h1>\n");
printf ("\t</body>\n");
printf ("</html>\n");
return 0;
}
編譯:
vim Makefile-------------------------------------------------------------
all:
$(CXX) index.cpp -o index.cgi
make
移動Cgi程式:
將編譯好的.cgi放到 /var/www/cgi-bin/ 下面Test:
http://192.168.0.101/cgi-bin/Debug:
cat /var/log/apache2/access.logcat /var/log/apache2/error.log
沒有留言:
張貼留言