Ubuntu安装Apache + mod_wsgi + Trac + Python 2.7

概述

Trac是自带wiki的轻量级软件项目管理系统,遵循BSD开源协议的开源软件。项目主页是https://trac.edgewall.org, 源代码在Github上有镜像git://github.com/edgewall/trac.git

Trac可以运行独立服务器,使用下面一行命令即可运行服务器。如果只有一个Trac实例,这种方式完全可以满足需求。

tracd path/to/trac --port=8080

Trac也可以使用Apache来运行,通过加载mod_wsgi模块来实现运行Python web服务器。本文主要介绍在Ubuntu系统上配置Trac。

假设软件已经安装完毕,MySQL-python, Trac(v1.2)及相关依赖也通过pip安装成功。同时假设Trac实例为demo安装在/opt/trac/demo, deploy文件到/opt/trac-deploy

软件准备

  • Ubuntu
[email protected]:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.10
Release:        16.10
Codename:       yakkety
  • Python2.7/PIP/MySQL5.7/Apache2
[email protected]:~$ python -V
Python 2.7.13
zhongw@s1:~$ mysql -V
mysql  Ver 14.14 Distrib 5.7.17, for Linux (i686) using  EditLine wrapper
zhongw@s1:~$ pip -V
pip 9.0.1 from /home/zhongw/.local/lib/python2.7/site-packages (python 2.7)
zhongw@s1:~$ /usr/local/apache2/bin/apachectl -v
Server version: Apache/2.4.25 (Unix)
Server built:   Mar 18 2017 15:51:58
  • mod_wsgi
Server:Apache/2.4.25 (Unix) mod_wsgi/4.5.15 Python/2.7

编译mod_wsgi

Apache, MySQL, Python都可以通过apt-get来安装,但mod_wsgi需要从源代码编译安装。

从Github找到mod_wsgi的最新发布版本的源代码 https://github.com/GrahamDumpleton/mod_wsgi

本文使用的版本是4.5.15

  • Configure
[email protected]:~/mod_wsgi-4.5.15$  ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/bin/python
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for prctl... yes
checking Apache version... 2.4.25
configure: creating ./config.status
config.status: creating Makefile
  • Run make命令编译mod_wsgi

如果出现编译问题,参考官方文档解决,常见的是找不到Python.h等问题,官方有详细说明。

  • make install
[email protected]:~/mod_wsgi-4.5.15$ sudo make install
/usr/local/apache2/bin/apxs -i -S LIBEXECDIR=/usr/local/apache2/modules -n ‘mod_wsgi‘ src/server/mod_wsgi.la
/usr/local/apache2/build/instdso.sh SH_LIBTOOL=‘/usr/local/apr/build-1/libtool‘ src/server/mod_wsgi.la /usr/local/apache2/modules
/usr/local/apr/build-1/libtool --mode=install install src/server/mod_wsgi.la /usr/local/apache2/modules/
libtool: install: install src/server/.libs/mod_wsgi.so /usr/local/apache2/modules/mod_wsgi.so
libtool: install: install src/server/.libs/mod_wsgi.lai /usr/local/apache2/modules/mod_wsgi.la
libtool: install: install src/server/.libs/mod_wsgi.a /usr/local/apache2/modules/mod_wsgi.a
libtool: install: chmod 644 /usr/local/apache2/modules/mod_wsgi.a
libtool: install: ranlib /usr/local/apache2/modules/mod_wsgi.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR‘
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH‘ environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH‘ environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR‘ linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf‘

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_wsgi.so
zhongw@s1:~/mod_wsgi-4.5.15$

mod_wsgi.so模块已经安装到了apache的modules目录。

验证一下mod_wsgi模块

[email protected]:/usr/local/apache2/modules$ ldd mod_wsgi.so
        linux-gate.so.1 =>  (0xb7735000)
        libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0xb74ba000)
        libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb749d000)
        libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb72e1000)
        libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb72dc000)
        libutil.so.1 => /lib/i386-linux-gnu/libutil.so.1 (0xb72d8000)
        libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7282000)
        /lib/ld-linux.so.2 (0x80065000)

配置httpd.conf

1. 在加载模块的位置增加对mod_wsgi的支持

LoadModule wsgi_module modules/mod_wsgi.so

2. 使用apache的htpasswd生成密码文件,Trac使用生成的密码文件来管理用户。

htpasswd -c /opt/trac.htpasswd admin
New password:
Re-type new password:
Adding password for user admin

3. 增加Directory和VirtualHost配置

<Directory /opt/trac-deploy/cgi-bin>
    WSGIApplicationGroup %{GLOBAL}
    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</Directory>

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/opt/trac-deploy/htdocs"
    WSGIScriptAlias / /opt/trac-deploy/cgi-bin/trac.wsgi
    <LocationMatch "/login">
        AuthType Basic
        AuthName "Trac"
        AuthUserFile /opt/trac.htpasswd
        Require valid-user
    </LocationMatch>
</VirtualHost>

重启动服务后浏览Trac

时间: 2024-11-10 13:04:09

Ubuntu安装Apache + mod_wsgi + Trac + Python 2.7的相关文章

1, 安装apache ?mod_WSGI

1, 安装apache  mod_WSGI   2, 安装 flask pip install Flask==0.9 3, 创建自己的 flask app 在 Flask 中的 "Hello, World" 现在在你的 microblog 文件夹中下有一个 flask 子文件夹,这里有 Python 解释器以及 Flask 框架以及我们将要在这个应用程序中使用的扩展. 是时候去编写我们第一个 web 应用程序! 在 cd 到 microblog 文件夹后,我们开始为应用程序创建基本的文

Ubuntu安装Apache

在虚拟机上安装了Ubuntu13.10 ,然后使用命令 sudo apt-get install apache2 安装apache总提示“E: 未找到软件包...”,不知所踪,这可能是新手容易的犯 的小错误,网上查找一番后解决掉 sudo apt-get update “获得最近的软件包的列表:列表中包含一些包的信息,比如这个包是否更新过”

Apache + mod_wsgi (Python)部署webpy应用

1. 搭建 Apache 服务器 (1). 下载 Httpd 及依赖 -- apr.apr-util httpd : http://httpd.apache.org/ apr & apr-util : https://apr.apache.org/ (2). 编译 apr : $ ./configure --prefix=/usr/local/apr $ make & sudo make install apr-util : ./configure --prefix=/usr/local/

ubuntu 安装apache

在ubuntu 12之前直接执行 sudo apt-get install apache2 不需要什么配置直接在浏览器里面输入本机ip地址或者localhost 在浏览器页面就会输出: It works! This is the default web page for this server. The web server software is running but no content has been added, yet. 这样的字眼,但是今天我在ubuntu 14版本上面做同样操作

ubuntu 安装 apache php mysql

我采用ubuntu 自动安装了搭建了php5.6 运行环境.特意写了篇技术文档,详细记录了安装过程. 效果图如下: 不懂安装的朋友:可以联系我QQ(498356271),我可以发详细的PDF文档给你.

Ubuntu安装apache+Yii2

1.下载Yii2 https://github.com/yiisoft/yii2/releases/download/2.0.11/yii-basic-app-2.0.11.tgz 2.将解压后的文件放在指定的位置,这里是/home/www/yii/ 3.安装apache2 sudo apt-get iinstall apache2 3.启动和查看apache2 启动: sudo /etc/init.d/apache2 start 查看: ps -ef |grep "apache" 4

ubuntu 安装ODOO时的python的依赖

sudo apt-get install graphviz ghostscript postgresql-client \ python-dateutil python-feedparser python-gdata \ python-ldap python-libxslt1 python-lxml python-mako \ python-openid python-psycopg2 python-pybabel python-pychart \ python-pydot python-pyp

ubuntu 下安装 apache php mysql

ubuntu 安装 apache+php+mysql1.打开终端,输入"sudo apt-get install apache2",回车;(安装apache2.0或2.x新版本,系统会自动查找新的版本)2.如有密码请再输入管理员密码,回车3.输入"Y",回车4.apache2.X 安装完成5.验证apache2.x安装是否完成,在浏览器中打开http://localhost/或者http://127.0.0.1.如果出现It works!那证明成功;6.打开终端,输

Window下python+Apache+mod_wsgi+Django配置(python2.7)

前言:试着使用python搭建一个网页,分别在windows下和linux下,本篇文章主要讲解Window下python+Apache+mod_wsgi+Django服务器配置过程中遇见的问题和解决方法. 正文: 首先,需要下载python.Apache.mod_wsgi.Django,下载地址如下 mod_wsgi:http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi(因为python2.7,所以下载mod_wsgi?4.4.21+ap24vc