Linux + Apache + MySQL 环境下OSQA部署

OSQA是开源的问答网站,采用Python的Django框架开发。按照官方的安装指南,在安装过程中出现了一些问题,现将试验成功的方法总结下。

官方的安装指南: Ubuntu+with+Apache+and+MySQL?focusedCommentId=3539023#comment-3539023

安装环境:Linux Mint 11, python2.7, django1.3, apache2.2。

本文中,linux的用户名为neil,在安装过程中一些路径请注意替换为真实路径

1.  下载OSQA

1)  svn下载

sudo apt-get install subversion #下载subversionsvn co http://svn.osqa.net/svnroot/osqa/trunk/ /home/neil/osqa-server #下载osqa到指定文件夹

2)  主页下载

2.  安装Apache

sudo apt-get install apache2 libapache2-mod-wsgi

3.   更新OSQA WSGI脚本

在/home/neil/osqa-server目录下新建一个文件osqa.wsgi,并输入如下内容

import os
import sys
sys.path.append('/home/neil')
sys.path.append('/home/neil/osqa-server')
# 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-server.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

4.  移除默认的Apache配置(可选)

官网说这个服务器只用于osqa,因此可以移除Apache的默认配置。

sudo rm /etc/apache2/sites-available/default\
/etc/apache2/sites-available/default-ssl\
/etc/apache2/sites-enabled/000-default

5.  为Apache添加OSQA的配置

新建并打开一个osqa配置文件

sudo gedit /etc/apache2/sites-available/osqa #官网是用vim打开的,由于我的机器上没有vim,我用的是gedit

填入如下配置信息

# Must be readable and writable by apache
WSGISocketPrefix ${APACHE_RUN_DIR}

#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>
ServerAdmin forum@example.com
#osqa网站文件所在的目录
DocumentRoot /home/neil/osqa-server
#自定义
ServerName osqa.localhost

#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/ "/home/neil/osqa-server/forum/skins/"
<Directory "/home/neil/osqa-server/forum/skins">
Order allow,deny
Allow from all
</Directory>
Alias /upfiles/ "/home/neil/osqa-server/forum/upfiles/"
<Directory "/home/neil/osqa-server/forum/upfiles">
Order deny,allow
Allow from all
</Directory>

#this is your wsgi script described in the prev section
WSGIScriptAlias / /home/osqa/osqa-server/osqa.wsgi

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

将配置文件链接到已启用站点的目录,也就是启用该站点

sudo ln -s /etc/apache2/sites-available/osqa /etc/apache2/sites-enabled/osqa


6.  安装MySQL

sudo apt-get install mysql-server mysql-client

安装过程中要求配置mysql的root用户名和密码。

添加为MySQL添加osqa用户,输入如下命令进入mysql命令行操作模式

sudo mysql -u root -p

创建用户

CREATE USER 'osqa'@'localhost' IDENTIFIED BY 'your_osqa_password';

创建数据库

CREATE DATABASE osqa DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;
GRANT ALL ON osqa.* to 'osqa'@'localhost';

7.  安装Python

linux默认是安装了python的,如果没有安装可以输入如下命令

sudo apt-get install python

安装python setup tools,安装了这个就可以很方便的安装一些python的库了。

sudo apt-get install python-setuptools

安装依赖的库

sudo apt-get install python-mysqldb
sudo easy_install South django django-debug-toolbar markdown \
html5lib python-openid

8.  配置OSQA的settings文件

进入/home/neil/osqa-server目录,拷贝settings_local.py.dist并重命名为settings_local.py

cp settings_local.py.dist settings_local.py

打开settings_local.py文件,并修改以下几项

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pswdd.html