zoukankan      html  css  js  c++  java
  • ubuntu14.10环境,apache2配置python的cgi

    1,安装apache2,命令如下:

    sudo apt-get install apache2

    2,进入/var/www/目录,创建test.com目录,并修改拥有者权限,再在test.com目录下创建cgi-bin目录,命令分别如下:

    sudo mkdir example.com
    sudo chown -R $USER example.com
    mkdir example.com/cgi-bin

    3,创建hello.py文件,编辑内容如下(内容参考链接:http://www.yiibai.com/python/python_cgi_programming.html):

    vim hello.py
    chmod 755 hello.py
    #!/usr/bin/python print "Content-type:text/html " print '<html>' print '<head>' print '<title>Hello Word - First CGI Program</title>' print '</head>' print '<body>' print '<h2>Hello Word! This is my first CGI program</h2>' print '</body>' print '</html>'

    4,进入/etc/apache2/sites-available目录下,复制000-default.conf文件到example.com.conf文件,并修改并添加cgi配置:

    修改:
    DocumentRoot /var/www/example.com
    添加: ScriptAlias
    /cgi-bin/ /var/www/example.com/cgi-bin/ <Directory "/var/www/example.com/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all AddHandler cgi-script .py AddHandler default-handler .html .htm </Directory>

    5,禁用默认cgi配置,在目录/etc/apache2/conf-available/serve-cgi-bin.conf;禁用默认配置000-default.conf;启用example.com.conf配置;并重启apache2

    sudo a2disconf serve-cgi-bin.conf
    sudo a2dissite 000-default.conf sudo a2ensite example.com.conf sudo service apache2 restart

    6,配置sudo编辑/etc/hosts文件:

    127.0.0.1    www.example.com

    7,访问浏览器www.example.com/cgi-bin/hello.py,应该能看到结果



  • 相关阅读:
    ArchLinux and LXDE and LXDM
    如何改变X:\Users\XXX的用户名称
    Windows 7 支持4GB以上内存破解工具下载
    Linux & Vim Command Wallpaper
    The easy way to execute sudo command in Python using subprocess.Popen
    C# DateTime 精确到秒/截断毫秒部分
    制约程序员"钱途"的两大最关键因素
    Oracle基本操作
    字符串处理【Delphi版】
    java学习路线的经验之谈
  • 原文地址:https://www.cnblogs.com/doublehappyi/p/4753225.html
Copyright © 2011-2022 走看看