Ubuntu安装Apache + mod_wsgi + Trac + Python 2.7

概述Trac是自带wiki的轻量级软件项目管理系统,遵循BSD开源协议的开源软件。项目主页是https://trac.edgewall.org, 源代码在Github上有镜像git://github.com/edgewall/trac.gitTrac可以运行独立服务器,使用下面一行命令即可运行服务器。如果只有一个Trac实例,这种方式完全可以满足需求。
tracd path/to/trac --port=8080
假设软件已经安装完毕,MySQL-python, Trac(v1.2)及相关依赖也通过pip安装成功。同时假设Trac实例为demo安装在/opt/trac/demo, deploy文件到/opt/trac-deploy软件准备
  • Ubuntu
  • zhongw@s1:~$ 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
  • zhongw@s1:~$ 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_wsgiApache, MySQL, Python都可以通过apt-get来安装,但mod_wsgi需要从源代码编译安装。从Github找到mod_wsgi的最新发布版本的源代码?https://github.com/GrahamDumpleton/mod_wsgi
  • Configure
  • zhongw@s1:~/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
  • zhongw@s1:~/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模块
    zhongw@s1:/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.conf1. 在加载模块的位置增加对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配置
    
        WSGIApplicationGroup %{GLOBAL}
        >
            Require all granted
        </IfModule>
    </Directory>
    
    *:80>
        ServerName localhost
        DocumentRoot "/opt/trac-deploy/htdocs"
        WSGIScriptAlias / /opt/trac-deploy/cgi-bin/trac.wsgi
        "/login">
            AuthType Basic
            AuthName "Trac"
            AuthUserFile /opt/trac.htpasswd
            Require valid-user
        </LocationMatch>
    </VirtualHost>
    4. 映射静态资源假设Trac的静态资源已经deploy到了/opt/trac-deploy
    trac-admin /opt/trac/demo deploy /opt/trac-deploy
    修改httpd.conf增加静态资源
    Alias /chrome /opt/trac-deploy/htdocs
    
        
            Require all granted
        
    
    重启Httpd服务后浏览Trac?

    相关内容推荐