Ubuntu/16.04LTS+Apache/2.4.18 环境下实现Python CGI编程

来源:互联网 发布:明星网络暴力 编辑:程序博客网 时间:2024/06/09 19:53

菜鸟教程不可谓不简,短短一句话“在你进行CGI编程前,确保您的Web服务器支持CGI及已经配置了CGI的处理程序“估计會使许多菜鸟纠结数天。

通过國内國外和官网各种资料查看,终于把apache2环境配置好了 最起码可以运行python程序。现 以觞大家 分享是美德!

1.安装apache2

sudo apt-get install apache2
2.编辑apache2.conf配置文件,以上方法安装的apache2没有httpd.conf 配置文件或者为空。请在root情况下打开配置文件
root@x-MacBook:/home/x# vim /etc/apache2/apache2.conf
使配置文件修改如下所示:
ScriptAlias /usr/lib/cgi-bin/ "/var/www/cgi-bin/"<Directory "/var/www/cgi-bin/">    AllowOverride None    Options +ExecCGI    Order allow,deny    Allow from all    AddHandler cgi-script .cgi .pl .py</Directory><Directory />        Options FollowSymLinks        AllowOverride None        Order deny,allow        allow from all</Directory><Directory /usr/share>        AllowOverride None        Require all granted</Directory><Directory /var/www/cgi-bin>        Options Indexes FollowSymLinks        AllowOverride None        Require all granted</Directory>#<Directory /srv/>#       Options Indexes FollowSymLinks#       AllowOverride None#       Require all granted#</Directory>ServerName lacalhost:80 # 这句最好放整个配置文件的最下面  

3.接着编辑000-default.conf配置文件 这个配置文件存在于 /etc/apache2/sites-avaibable/和 /etc/apache2/sites-enabled/目录中,且存在于 /etc/apache2/sites-avaibable/中没用,必须通过 ln -s 命令关联到 /etc/apache2/sites-enabled/中
vim /etc/apache2/sites-avaibable/000-default.conf
配置好如下:
<VirtualHost *:80># The ServerName directive sets the request scheme, hostname and port that# the server uses to identify itself. This is used when creating# redirection URLs. In the context of virtual hosts, the ServerName# specifies what hostname must appear in the request's Host: header to# match this virtual host. For the default virtual host (this file) this# value is not decisive as it is used as a last resort host regardless.# However, you must set it for any further virtual host explicitly.#ServerName www.example.comServerAdmin webmaster@localhostDocumentRoot /var/www/cgi-bin        <Directory "var/www/cgi-bin">           AllowOverride None           Options Indexes FollowSymLinks ExecCGI            Order allow,deny           Allow from all           AllowOverride All        </Directory># Available loglevels: trace8, ..., trace1, debug, info, notice, warn,# error, crit, alert, emerg.# It is also possible to configure the loglevel for particular# modules, e.g.#LogLevel info ssl:warnErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined# For most configuration files from conf-available/, which are# enabled or disabled at a global level, it is possible to# include a line for only one particular virtual host. For example the# following line enables the CGI configuration for this host only# after it has been globally disabled with "a2disconf".Include conf-available/serve-cgi-bin.conf</VirtualHost># vim: syntax=apache ts=4 sw=4 sts=4 sr noet

4.
/etc/init.d/apache2 reload
/etc/init.d/apache2 start
 

剩下的就可以参考菜鸟教程啦,等有闲情再来改



原创粉丝点击