【发布时间】:2015-12-28 17:43:18
【问题描述】:
我正在关注有关在笔记本电脑的 Apache2 服务器上安装 Python 的 Digital Ocean 教程。 Ubuntu 14.04 LTS、Python 3.4.3、MySQL 14.14。
更新 Apache 配置看起来很简单:
<VirtualHost *:80>
<Directory /var/www/test>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script .py
...
DocumentRoot /var/www/test
...
我可以在没有问题的情况下重新启动 Apache。
/var/www/test/index.py 中的 Python 测试脚本也看起来很简单。我可以在没有问题的情况下从命令行运行它,然后将文件 chmod 到 755。
#!/usr/bin/python
# Turn on debug mode.
import cgitb
cgitb.enable()
# Print necessary headers.
print("Content-Type: text/html")
print()
# Connect to the database.
import pymysql
conn = pymysql.connect(
db='example',
user='root',
passwd='your_root_mysql_password',
host='localhost')
c = conn.cursor()
# Insert some example data.
c.execute("INSERT INTO numbers VALUES (1, 'One!')")
c.execute("INSERT INTO numbers VALUES (2, 'Two!')")
c.execute("INSERT INTO numbers VALUES (3, 'Three!')")
conn.commit()
# Print the contents of the database.
c.execute("SELECT * FROM numbers")
print([(r[0], r[1]) for r in c.fetchall()])
Apache 一直以“500”轰炸,访问日志没有提供更多详细信息。我知道这很简单,而且我办公室里没有其他人有任何专业知识。
提示?
【问题讨论】:
-
试试
/var/log/httpd/error.log -
我投票结束这个问题,因为它属于 AskUbuntu
标签: python mysql apache ubuntu python-3.x