安装 LAMP
安装 mod_python
为了开发和调试的方便,我们把apache默认目录改到我们的用户目录下 以下“你的名字”指的是你当前使用的系统用户名 如果你不清楚的话,可以执行命令 whoami 查看你当前的用户名
执行
回到你的用户目录
创建你的工作目录
修改apache配置文件
把所有 /var/www 改成 /home/你的名字/workhome" 在第10行左右,有 Options Indexes FollowSymLinks MultiViews 在后面加上 +ExecCGI 变成 Options Indexes FollowSymLinks MultiViews +ExecCGI
/var/www
/home/你的名字/workhome"
Options Indexes FollowSymLinks MultiViews
+ExecCGI
Options Indexes FollowSymLinks MultiViews +ExecCGI
修改apache用户及用户组
把www-data改成你的名字 两个都要改
www-data
建立mod_python配置文件
加入
保存退出
重新启用mod_python
重启apache
测试python
内容:
浏览器打开 http://localhost/test.py 应该不会提示你下载test.py了,正常情况会输出 Hello, Python.
Your email is never published nor shared. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
ubuntu apache python
安装 LAMP
安装 mod_python
为了开发和调试的方便,我们把apache默认目录改到我们的用户目录下
以下“你的名字”指的是你当前使用的系统用户名
如果你不清楚的话,可以执行命令 whoami 查看你当前的用户名
执行
回到你的用户目录
创建你的工作目录
修改apache配置文件
把所有
/var/www改成/home/你的名字/workhome"在第10行左右,有
Options Indexes FollowSymLinks MultiViews在后面加上
+ExecCGI变成
Options Indexes FollowSymLinks MultiViews +ExecCGI修改apache用户及用户组
把
www-data改成你的名字两个都要改
建立mod_python配置文件
加入
2
3
4
AddType text/html .py
AddHandler cgi-script .cgi .py
</IfModule>
保存退出
重新启用mod_python
重启apache
测试python
内容:
2
3
print "Content-type: text/html\n\n"
print "Hello, Python."
浏览器打开 http://localhost/test.py
应该不会提示你下载test.py了,正常情况会输出 Hello, Python.