在mac os下的Apache服务器的cgi中运行python
2015-04-21 20:10
10 查看
我是搬运工。。
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
相关文章推荐
- [Python]python CGI脚本在apache服务器上运行时出现“Premature end of script headers”错误
- 搭建简易的c语言与python语言CGI和Apache服务器的开发环境
- Apache Web 服务器配置CGI程序,执行Python、Perl脚本
- windows7平台下配置Apache+Python-CGI开发运行环境
- 在Apache服务器中运行CGI程序的方法
- 在Mac OS上使用mod_wsgi连接Python与Apache服务器
- windows中配置apache以cgi方式运行python
- Windows 配置Apache以便在浏览器中运行Python script的CGI模式
- 在IIS服务器上以CGI方式运行Python脚本的教程
- 用Apache配置本地服务器,并用以运行html和Python文件
- Mac下apache支持cgi运行python3程序
- 在Mac OS上使用mod_wsgi连接Python与Apache服务器
- Windows 配置Apache以便在浏览器中运行Python script的CGI模式
- Windows 配置Apache以便在浏览器中运行Python script的CGI模式
- Apache运行python cgi程序
- window下如何配置apache Http服务器使其能运行python cgi脚本
- 用C语言和VC6.0做个最简单的CGI程序,并且运行在apache服务器环境中。
- Python在web开发中简单服务器的搭建与运行问题
- Apache-tomcat-6.0.36配置基于Python的CGI脚本解析
- python 运行出现flask运行时提示出错了或者报服务器出错,ValueError: View function did not return a response