作者 : Bun Wong
日期 : 2009年03月10日
浏览 : 2811 次
评论 : 9 个
http://www.hdwong.com/article/lamp.html

开发服务器配置笔记 (Apache PHP MySQL SVN Trac)

技术交流 @ 2009年03月10日 收藏&分享

最近为新公司部署了一台内网的开发用服务器,主要配置了 Apache + PHP + MySQL,SVN 版本控制,Trac 项目管理,这里炒冷饭写一下…

  1. Apache

    官方下载 源代码,先安装 apr 和 apr-util

    cd srclib
    cd apr
    ./configure --prefix=/usr
    make
    make install

    cd srclib
    cd apr-util
    ./configure --prefix=/usr --with-apr=/usr
    make
    make install

    接下来我们开始编译 Apache

    ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-deflate --enable-expires --with-apr=/usr --with-apr-util=/usr
    make
    make install

    这时 Apache 安装在 /usr/local/apache2 目录,安装完成后,可以打开浏览器输入 URL : http://location,显示 It works! 即表示成功了,当然,这时候还没有配置虚拟主机,后面再提及这项配置

  2. MySQL

    官方的推荐,直接下载二进制包,我通过 apt 源上直接安装了 MySQL

    apt-get install mysql-server-5.1 mysql-client-5.1 libmysqlclient16-dev

    其中 libmysqlclient16-dev 包含了配置 PHP MySQL 扩展时必需的 header 文件,所以我们必须安装

  3. PHP

    先到 官方下载 源代码,PHP 需要依赖的库较多,我们通过 apt 源上来安装

    apt-get install zlib1g-dev libfreetype6-dev libpng12-dev libjpeg62-dev libxml2-dev

    分别是 zlib, freetype, libpng, libjpeg, libxml2 的 header 文件 (libmysqlclient 前面已经安装了),接下来可以开始编译 PHP 了

    ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=/usr --with-pdo-mysql=/usr --with-zlib=/usr --enable-mbstring
    make
    make install

    PHP 会安装到 /usr/local/php 目录,绿色文字部分表明我们需要安装成 apache2 的一个 Shared Module,然后复制配置文件

    cp php.ini-recommended /usr/local/php/lib/php.ini

    接下来让 Apache 来解析 .php 文件吧,打开 /usr/local/apache2/conf/httpd.conf,搜索 libphp5.so (为什么会在 httpd.conf 里面有 libphp5.so 呢?原因是我们配置 PHP 的时候设置了 Apache 的路径),在后面增加一行

    AddType application/x-httpd-php .php

    这时候,我们来配置虚拟主机,假如虚拟主机的 DocumentRoot 是 /home/www,我们在 httpd.conf 里加入

    <Directory "/home/www">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    然后搜索 httpd-vhosts.conf,并去掉前面的井号 #,这行是读入虚拟主机的设置,接着去编辑这个配置文件

    vim /usr/local/apache2/conf/extra/httpd-vhost.conf

    改成如下

    <VirtualHost *:80>
        ServerAdmin webmaster@intop.com
        DocumentRoot "/home/www/public_html/default"
        ServerName 127.0.0.1
        ServerAlias localhost
        ErrorLog "logs/localhost-error_log"
        CustomLog "logs/localhost-access_log" common
    </VirtualHost>

    创建好 /home/www/public_html/default 目录,现在我们创建一个测试文件 testing.php 放到该目录下

    <?php
        phpinfo();
    ?>

    /usr/local/apache2/bin/apachectl restart

    重启 Apache 服务器,现在去访问 http://localhost/testing.php,将会去访问 /home/www/public_html/default 目录下的 testing.php 了

  4. SVN

    通过 apt 可以直接安装

    apt-get install subversion

    接着我们创建一个版本仓库

    mkdir /svn
    svnadmin create /svn/myproject
    svnserve -d -r /svn

    我们可以 svnserve 这行放入 /etc/rc.local 来让它每次开机自动启动。这时,我们可以通过这样来获取 myproject 当前版本

    svn co svn://localhost/myproject
    取出版本 0。

    这时候仅有匿名 checkout 的权限,我们来配置一下 myproject 的权限,打开 /svn/myproject/conf/svnserve.conf,并按修改如下

    anon-access = none #关闭匿名访问
    auth-access = write #验证用户可写
    password-db = passwd #验证用户数据在 passwd 文件里

    我们在 passwd 文件里加上一行 bun=bun (用户名=明文密码),下次访问 svn 的时候,svn client 将要求你输入验证

  5. Trac

    下载源代码,Trac 是基于 Python 的,因此你的机器上必须配置了 Python,Ubuntu 上默认已经安装了 Python 2.5,接下来只需要安装 Sqlite (Trac 的数据库),我也是通过 apt 安装,然后安装 Trac 并创建 Project

    apt-get install sqlite3 python-pysqlite2
    python ./setup.py install
    trac-admin /home/www/public_html/default/trac initenv

    我们把 Trac Project 放到 /home/www/public_html/default/trac 上因为我们后面需要通过 Apache 来访问 Trac,这时你可以通过下面的命令来测试 Trac

    tracd -s --port 8000 /home/www/public_html/default/trac

    现在应该可以通过 http://localhost:8000 来访问 Trac 了

    接下来安装 mod_python 让我们能通过 Apache 来访问 Trac,先到 官方下载 源代码,编译

    ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/bin/python2.6
    make
    make install

    make 的时候,有可能会出现如下错误,原因是 Apache 的版本还太高 mod_python 未支持 (网上的说法),我的是 Apache 2.2.15 + mod_python 3.3.1,存在此错误

    connobject.c: In function ‘_conn_read’:
    connobject.c:142: error: request for member ‘next’ in something not a structure or union
    apxs:Error: Command failed with rc=65536
    .
    make[1]: *** [mod_python.so] Error 1
    make[1]: Leaving directory `/home/bun/mod_python-3.3.1/src'
    make: *** [do_dso] Error 2

    网上的解决方法是编辑 src/connobject.c 的 142 行,改成

    //!(b == APR_BRIGADE_SENTINEL(b) ||
    !(b == APR_BRIGADE_SENTINEL(bb) ||

    最后,我们把 mod_python 加入 Apache 的 httpd.conf

    LoadModule python_module modules/mod_python.so

    设置虚拟主机配置,把刚才虚拟主机的配置改成

    <VirtualHost *:80>
        ServerAdmin webmaster@intop.com
        DocumentRoot "/home/www/public_html/default"
        ServerName 127.0.0.1
        ServerAlias localhost
        ErrorLog "logs/localhost-error_log"
        CustomLog "logs/localhost-access_log" common
        <Location "/trac">
            SetHandler mod_python
            PythonInterpreter main_interpreter
            PythonHandler trac.web.modpython_frontend
            PythonOption TracEnv /home/www/public_html/default/trac
            PythonOption TracUriRoot /trac
            AuthType Basic
            AuthName "My Trac Server"
            AuthUserFile /home/www/public_html/default/trac/.htpasswd
            Require valid-user
        </Location>
    </VirtualHost>

    加上用户身份验证,验证文件通过 htpasswd (/usr/local/apache2/bin/htpasswd) 生成,可以查看相关的使用帮助,把验证文件放到 /home/www/public_html/default/trac/.htpasswd 就可以了

    最后,用 trac-admin 为你创建一个管理员,登录后就可以看到 Admin 菜单了 :)

    trac-admin /home/www/public_html/default/trac permission add yourname TRAC_ADMIN

评论 (9)

  • #1. youyou

    2009年03月10日

    把这个ServerName 127.0.0.1
    改成例如:192.168.1.254好点吧,话明内网啊嘛127.0.0.1会不会让人跟localhost搞乱了呀

  • #2. youyou

    2009年03月10日

    嘿嘿,我是来点广告的

  • #3. 番仔

    2009年03月10日

    这篇文章终于又回来了..赞一下

  • #4. 橄榄

    2009年03月10日

    好详细

  • #5. 132

    2009年09月03日

    233

  • #6. Lanvige

    2009年11月23日

    I meet this error, please help me to fix it.
    Sorry, my ubuntu have no CHN input.

    /usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_python.la -rpath /usr/local/apache2/modules -module -avoid-version finfoobject.lo hlistobject.lo hlist.lo filterobject.lo connobject.lo serverobject.lo util.lo tableobject.lo requestobject.lo _apachemodule.lo mod_python.lo -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -lm /usr/lib/python2.6/config/libpython2.6.a -lpthread -ldl -lutil -lm -L/lib -lz

    *** Warning: Linking the shared library mod_python.la against the
    *** static library /usr/lib/python2.6/config/libpython2.6.a is not portable!
    /usr/bin/ld: cannot find -lz
    collect2: ld returned 1 exit status
    apxs:Error: Command failed with rc=65536

    Thanks!

  • #7. Bun Wong

    2009年11月23日

    或者你可以试试看在 configure 命令中加上 --enable-shared 吧,因为我本地没有环境帮你测试了,如果还不行,可以 Google 一下...

  • #8. xpen

    2010年05月06日

    你好,
    *** Warning: Linking the shared library mod_python.la against the
    *** static library /usr/lib/python2.6/config/libpython2.6.a is not portable!
    /usr/bin/ld: cannot find -lz
    collect2: ld returned 1 exit status
    apxs:Error: Command failed with rc=65536

    关于这个问题 我用了你的解决方法好像没有用啊
    环境是Ubuntu9.10 apache 2.2.11 python2.6 mod_python3.3.1

    我想是不是可以交流一下
    msn:pengphy@hotmail.com

  • #9. Bun Wong

    2010年07月15日

    Hi all,
    今天在 ubuntu 10.04 的 server 下也发现了这个问题,提示为 /usr/bin/ld: cannot find -lssl,解决方法:
    apt-get install libssl-dev
    然后重新编译即可,
    楼上两位可以通过 apt-get install libz-dev 来试试

* 昵称:

* 评论:

* 验证码: (请输入下图的 4 位数字)

Captcha看不请, 换一张

© 2011 Bun Wong

本博客基于 Bun PHP Framework 构建 • 粤ICP备07036370号