设为首页 收藏本站
查看: 568|回复: 0

[经验分享] Linux + Apache + MySQL 环境下OSQA部署

[复制链接]

尚未签到

发表于 2015-6-19 10:05:59 | 显示全部楼层 |阅读模式
  OSQA是开源的问答网站,采用Python的Django框架开发。按照官方的安装指南,在安装过程中出现了一些问题,现将试验成功的方法总结下。
  官方的安装指南: http://wiki.osqa.net/display/docs/Ubuntu+with+Apache+and+MySQL?focusedCommentId=3539023#comment-3539023
  
  安装环境:linuxmint11, python2.7, django1.3, apache2.2。
  本文中,linux的用户名为neil,在安装过程中一些路径请注意替换为真实路径。
  

1.  下载OSQA
  1)  svn下载



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

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 [http://example.com/forum], if you like

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

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



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文件,并修改以下几项



DATABASE_NAME = 'osqa'
DATABASE_USER = 'osqa'
DATABASE_PASSWORD = 'your_osqa_password'
DATABASE_ENGINE = 'mysql'
  同样在settings_local.py文件中,修改以下这项,来更新域名。



APP_URL = 'http://osqa.localhost/'
9.  为OSQA数据库建表
  输入如下命令,会自动建立必须的表



sudo python manage.py syncdb --all
  进行这步操作时,出现错误cannot import name mark_safe,解决方法,打开文件/home/neil/osqa-server/forum/utils/html.py,找到第6行,做如下修改。



#from django.template import mark_safe        #原始代码
from django.utils.safestring import mark_safe #修改后
  
  在稍后部署后访问页面出现http 500错误,查看错误日志/var/log/apache2/osqa.error.log,发现该错误url(r'^%s(.*)' % _('nimda/'), admin.site.root),据stackoverflow上的说法,打开/home/neil/osqa-server/forum/urls.py文件,找到第23行,这是django1.0版本的代码,在django1.3版本下不工作。替换成如下代码。



#url(r'^%s(.*)' % _('nimda/'), admin.site.root),         #原始代码
url(r'^%s(.*)' % _('nimda/'), include(admin.site.urls)), #修改后
  
  在建完表后,系统会要求建立一个超级管理员帐号,OSQA官网推荐说此时不建立该帐号,等网站架设起来后,通过正常方法建立的第1个用户默认就是超级管理员。
  
  接下来还有一步,不是很了解,原文如下。
  With that command you have successfully defined the schema. With South installed, you also have the ability to migrate between databases--a useful feature as OSQA is updated. However, as this is a fresh install, you will need to convince South that the schema is already up to date by "faking" a migration. You can do that with the following command:



sudo python manage.py migrate forum --fake

10.  保证Apache被允许访问OSQA文件

  这条命令表示osqa-server文件夹下的所有文件被neil用户和Apache group (www-data)拥有



sudo chown -R neil:www-data /home/neil/osqa-server
  允许Apache访问upfiles和log目录



sudo chmod -R g+w /home/osqa/osqa-server/forum/upfiles
sudo chmod -R g+w /home/osqa/osqa-server/log

11.  启动网站

  如果是在本地部署,可以往hosts里添加一条指向本地的域名



sudo gedit /etc/hosts #打开hosts
  加上以下这条内容,当在浏览器中输入osqa.localhost时就会跳转到本地部署的osqa



127.0.0.1 osqa.localhost
  重新启动Apache



sudo /etc/init.d/apache2 restart
  一切部署完毕,打开osqa.localhost,就可以看到页面了。
DSC0000.png
  

  


  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-78791-1-1.html 上篇帖子: Mysql数据库“Connection is read-only”问题 下篇帖子: MySQL GUI Tools 使用简介
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表