您的位置:首页 > 运维架构 > Apache

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

2009-04-22 09:20 831 查看
原文 : http://hdwong.com/articles/2009/03/00000026.html
最近为新公司部署了一台内网的开发用服务器,主要配置了 Apache + PHP + MySQL,SVN 版本控制,Trac 项目管理,这里炒冷饭写一下…

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 --with-apr=/usr --with-apr-util=/usr
make
make install
这时 Apache 安装在 /usr/local/apache2 目录,安装完成后,可以打开浏览器输入 URL : http://location,显示 It works! 即表示成功了,当然,这时候还没有配置虚拟主机,后面再提及这项配置

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

apt-get install mysql-server-5.0 mysql-client-5.0 libmysqlclient15-dev
其中 libmysqlclient15-dev 包含了配置 PHP MySQL 扩展时必需的 header 文件,所以我们必须安装

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 了

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 将要求你输入验证

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.5
make
make install
make 的时候,有可能会出现如下错误,原因是 Apache 的版本还太高 mod_python 未支持 (网上的说法),我的是 Apache 2.2.11 + 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
9051
/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 "Intop 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 就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐