zoukankan      html  css  js  c++  java
  • 在mac os下的Apache服务器的cgi中运行python

    我是搬运工。。

    Running Python Programs on the Mac OS X Apache Web Server

    The Mac OS X operating system includes a pre-configured Apache web server and also includes the libraries needed to run Python. Thus, Python CGI scripts can be run without any configuration changes to the Apache configuration as long as the scripts are placed in the correct location and given the correct file permissions. 

    This guide assumes you are using OS X Leopard, although the steps should be the same or similar for earlier versions of OS X.

    The default location to place CGI programs for the OS X apache installation is in the following directory: 

    /Library/WebServer/CGI-Executables 

    Files placed in this directory can be accessed via the following URL: 

    http://localhost/cgi-bin/file-name

    In order for Apache to be able to execute the CGI script, the permissions on the file must be set correctly. For example, open EditRocket and create a file called test.py with the following contents. Save this file to the /Library/WebServer/CGI-Executables directory.

    #!/usr/bin/python
    print "Content-type: text/html"
    print
    print "<html><head>"
    print ""
    print "</head><body>"
    print "Test Page"
    print "</body></html>"
    

    Open a terminal window (Applications -> Utilities -> Terminal). Execute the following command: 

    cd /Library/WebServer/CGI-Executables 

    Then execute the following (if prompted, enter your password) 

    sudo chmod 755 test.py 

    You now have a Python program, test.py, saved with the correct permissions in the /Library/WebServer/CGI-Executables directory.  

    Now, we need to restart the web server to make sure the changes take effect. To restart, do the following:

    1. Go to System Preferences -> Sharing View 

    2. Uncheck the Web Sharing box. Then check the Web Sharing box again. This will start and stop the apache web server. 

    You can test this page by entering the following in your web browser: 

    http://localhost/cgi-bin/test.py

  • 相关阅读:
    linux 7版本配置端口转发
    修改/etc/hosts.allow和/etc/hosts.deny允许linux服务器允许和限制访问策略
    DNS解析全过程
    zabbix监控原理和架构详谈
    数据库连接池
    Haproxy负载均衡
    Redis数据库
    Tensorflow实战第十一课(RNN Regression 回归例子 )
    OneNote2016代码高亮插件的安装与使用
    Tensorflow实战第十课(RNN MNIST分类)
  • 原文地址:https://www.cnblogs.com/Blaxon/p/4445335.html
Copyright © 2011-2022 走看看