UBUNTU 11.04 配置 apache2 + cgi
2011-10-20 15:30
239 查看
安装apache2服务器。
zhang@zhang:~/Desktop$ sudo apt-get install apache2
建立cgi目录
zhang@zhang:~/Desktop$ sudo mkdir /var/www/cgi-bin
配置文件目录在/etc/apache2/sites-enabled/000-default
zhang@zhang:~/Desktop$ sudo vi /etc/apache2/sites-enabled/000-default
将其改为下面的样式:
修改完保存,重启apache2。
zhang@zhang:~/Desktop$ sudo /etc/init.d/apache2 restart
cgi测试(test.cpp):
编译该程序:
zhang@zhang:~/Desktop$ g++ -o test.cgi test.cpp
zhang@zhang:~/Desktop$ chmod 755 test.cgi
zhang@zhang:~/Desktop$ sudo cp test.cgi /var/www/cgi-bin/
开启浏览器chromium,输入“http://localhost/cgi-bin/test.cgi”, 浏览器显示如下:
Hello World! This is my first CGI program
注意,你的CGI程序属性一定要设为可运行(755),而与CGI有关的HTML文件的目录如果要被CGI程序写入,其权限一定要设为可写(666)。
zhang@zhang:~/Desktop$ sudo apt-get install apache2
建立cgi目录
zhang@zhang:~/Desktop$ sudo mkdir /var/www/cgi-bin
配置文件目录在/etc/apache2/sites-enabled/000-default
zhang@zhang:~/Desktop$ sudo vi /etc/apache2/sites-enabled/000-default
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
将其改为下面的样式:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /var/www/cgi-bin/ <Directory "/var/www/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory>
修改完保存,重启apache2。
zhang@zhang:~/Desktop$ sudo /etc/init.d/apache2 restart
cgi测试(test.cpp):
#include <iostream> using namespace std; int main () { cout << "Content-type:text/html\r\n\r\n"; cout << "<html>\n"; cout << "<head>\n"; cout << "<title>Hello World - First CGI Program</title>\n"; cout << "</head>\n"; cout << "<body>\n"; cout << "<h2>Hello World! This is my first CGI program</h2>\n"; cout << "</body>\n"; cout << "</html>\n"; return 0; }
编译该程序:
zhang@zhang:~/Desktop$ g++ -o test.cgi test.cpp
zhang@zhang:~/Desktop$ chmod 755 test.cgi
zhang@zhang:~/Desktop$ sudo cp test.cgi /var/www/cgi-bin/
开启浏览器chromium,输入“http://localhost/cgi-bin/test.cgi”, 浏览器显示如下:
Hello World! This is my first CGI program
注意,你的CGI程序属性一定要设为可运行(755),而与CGI有关的HTML文件的目录如果要被CGI程序写入,其权限一定要设为可写(666)。
相关文章推荐
- ubuntu Apache2 搭建及基本命令及配置
- 阿里云服务器 ECS Ubuntu系统下PHP,MYSQL,APACHE2的安装配置
- Ubuntu 11.04安装配置 OpenLDAP
- 阿里云Ubuntu16.04+apache2配置阿里云免费CA证书记录
- Ubuntu下安装和配置Apache2
- ubuntu apache2配置详解(含虚拟主机配置方法)
- Ubuntu server安装apache2及重要配置(持续更新)
- ubuntu下apache2 安装 配置 卸载 CGI设置 SSL设置
- ubuntu apache2 ssl配置
- ubuntu下apache2-php-mysql的环境配置
- Ubuntu下安装和配置Apache2
- Ubuntu下安装和配置Apache2
- ubuntu安装配置Apache2和SVN
- Ubuntu 11.04 下安装配置 JDK 7(转)
- Ubuntu Mate +Apache2 配置www服务的一些相关
- 2012-03-27 14:55 Ubuntu 11.04 下安装配置 JDK 7 图文教程(转)
- Ubuntu下安装和配置Apache2
- 在Ubuntu 11.04下安装配置JDK
- ubuntu apache2配置(转载)
- ubuntu apache2配置