AWS EC2上部署OSQA(Ubuntu+apache+MySQL)

本文介绍在AWS EC2上部署OSQA,使用环境是:Ubuntu+apache+MySQL。

1. 安装Python模块


sudo apt-get install python-setuptools  # python-setuptools包含easy_install 

# 安装Python其他模块
sudo easy_install ElementTree Markdown html5lib python-openid
sudo apt-get install python-mysqldb   # sudo easy_install mysql-python

sudo apt-get install python-django
sudo apt-get install libapache2-mod-wsgi  # 安装mod-wsgi, sudo a2enmod mod-wsgi

#sudo vim /etc/apache2/apache2.conf  # 这一步,个人认为没必要
#added by sparkandhsine, 
#LoadModule wsgi_module modules/ 


# South ships with a full database-agnostic API for performing schema changes on databases, much like Django’s ORM provides data manipulation support.
sudo apt-get install python-pip
sudo pip install south

2. 创建数据库


/var/www/$ git clone


mysql -u root -p
# 输入密码
create database osqa DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;


在/var/www/osqa/目录下运行命令python syncdb自动生成osqa数据库,如下:

/var/www/osqa$ python syncdb
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

3. 配置OSQA


$cp osqa.wsgi.dist osqa.wsgi

# 修改osqa.wsgi的sys.path.append

# osqa.wsgi文件内容如下:
import os
import sys
# The first part of this module name should be identical to the directory name
# of the OSQA source.  For instance, if the full path to OSQA is
# /home/osqa/osqa-server, then the DJANGO_SETTINGS_MODULE should have a value
# of 'osqa-server.settings'.
os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()



# settings_local.py需要修改的内容如下:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'osqa',
        'USER': 'root',
        'PASSWORD': '**********',
        'HOST': '',
        'PORT': '',
        'CONN_MAX_AGE': 600,




4. web服务器配置文件


# Must be readable and writable by apache

#NOTE: all urs below will need to be adjusted if
#settings.FORUM_SCRIPT_ALIAS !='' (e.g. = 'forum/')
#this allows "rooting" forum at [], if you like
<VirtualHost *:80>
    DocumentRoot /var/www/osqa

    #run mod_wsgi process for django in daemon mode
    #this allows avoiding confused timezone settings when
    #another application runs in the same virtual host
    WSGIDaemonProcess OSQA
    WSGIProcessGroup OSQA

    #force all content to be served as static files
    #otherwise django will be crunching images through itself wasting time
    Alias /m/ "/var/www/osqa/forum/skins/"
    <Directory "/var/www/osqa/forum/skins">
        Require all granted
    Alias /upfiles/ "/var/www/osqa/forum/upfiles/"
    <Directory "/var/www/osqa/forum/upfiles">
        Require all granted 

    #this is your wsgi script described in the prev section
    WSGIScriptAlias / /var/www/osqa/osqa.wsgi

    CustomLog ${APACHE_LOG_DIR}/osqa.access.log common
    ErrorLog ${APACHE_LOG_DIR}/osqa.error.log


sudo a2ensite osqa.conf
sudo service apache2 restart

5. 修改hosts文件


# added by sparkandshine
# xx.xx.xx.xx为AWS EC2 Elastic IP

6. 修改DNS解析

zhilitea.com的A记录@解析到xx.xx.xx.xx(为AWS EC2 Elastic IP)。

@ --> xx.xx.xx.xx  # xx.xx.xx.xx为AWS EC2 Elastic IP

PS: 若不能正常访问,可以查看错误日志文件/var/log/apache2/osqa.error.log

7. 遇到问题及解决

7.1 500 Sever Error

安装完访问提示错误: 500 Server Error。产生这个问题的原因是markdown版本太高导致的不兼容,解决方法就是使用低版本的markdown,命令如下:

sudo pip install Markdown==2.4.1

7.2 Internal Server Error


mod_wsgi (pid=2131): Exception occurred processing WSGI script '/var/www/osqa/osqa.wsgi'.

解决问题可能在这里: (睡了,改天再整)

Exception occurred processing WSGI script
Django mod_wsgi: Exception occurred processing wsgi script

[3]博文《Linux + Apache + MySQL 环境下OSQA部署
[4]Blog: Configuring www folder on Ubuntu (Amazon EC2)

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “AWS EC2上部署OSQA(Ubuntu+apache+MySQL)