Saturday, September 30, 2006

在ubuntu下安装bugzilla

Convention:
$APACHE_HOME : installation directory of apache server.
$BUGZILLA_HOME : installation directory of bugzilla.
$MYSQL_HOME : installation directory of mysql.

Prerequirement:
Bugzilla : 2.22 release (2.22)
Perl : 5.6.1 or higher (5.8.7)
Mysql : 4.0.14 or higher (5.0.21)
Apache : 1.3 or 2.x (2.2.2)
Ubuntu : 6.0.6
GCC: apt-get install build-essential

Detailed steps:
===============================
Apache Intallation
===============================
I don't know if apache has been built in my ubuntu, so reinstalling apache is maybe a good idea. The distribution of apache for linux must be built from source.
1. download httpd.apache.org, I chose the latest stable release httpd-2.2.2.tar.gz.
2. extract source package
Here you should check if your ubuntu has insalled build environment, if not, install it by executing 'sudo apt-get install build-essential'.
3. build the source code, and do installation.
- ./configure --prefix=$TARGET_DIR
- make
- make install
4. enter $APACHE_HOME/bin, execute './httpd -k start' or './apachectl start' to start apache server. After that, open browser and access 'http://localhost' to check if server has been startup.

===============================
Mysql Intallation
===============================
It seems like that the installation of mysql is really simple. I just downloaded the binary package from www.mysql.com, then extract it to a directory. Don't need to compile, dont need to install. Enter mysql root directory, execute './configure', then it is ok.
You can start mysql daemon server by executing './bin/mysqld-safe'.
Do remember that this is justa short cut, it need a more speculated configuration in a product environment, such as creating user account, security configuration.
DO MORE RESEARCH!!

创建一个bugzilla账户, 登陆到mysql
> grant all on bugs.* to bugs@localhost identified by 'bugs';
>flush privileges;

===============================
Install Perl Modules
===============================
Bugzilla need some special perl modules to support it behaviour.
1. enter $BUGZILLA_HOME, execute './checkperl.pl --check-modules'. check the output, you will get a list of uninstalled modules.
2. install depended modules. you can install by MCPAN(???) or download module from www.cpan.org and then install it from local machine.
2.1 install from remote : /usr/bin/perl -MCPAN -e 'install "XML::Twig"'
2.2 install from local:
- download module packege from www.cpan.org.
- extract the package, and enter the module directory.
- 'perl Makefile.pl', build a makefe file.
---------------------------------------------------
NOTE: 这一步可以指定一个参数PREFIX来设置将这个模块安装到什么地方,比如"perl Makefile.PK PREFIX=/opt/mylib/perl",那么'make install'时候,模块会被安装到/opt/mylib/perl,在这个目录下会被创建很多子目录,一般是:
/opt/mylib/perl/bin
/opt/mylib/perl/share
/opt/mylib/perl/share/perl/5.8.7 [这个目录下面放置模块文件]
/opt/mylib/perl/lib/perl/5.8.7 [这个目录下面也可以放置模块文件]
/opt/mylib/perl/man [帮助文档]

PERL 解释器搜索模块的路径可以通过一个变量来设置,PERLLIB,PERL5LIB两个变量都可以增加PERL解释器的搜索路径,最好两个变量都设置最保险,因为工具可能查找不同的变量,比如[export PERLLIB=/opt/mylib/perl/share/perl/5.8.7:/opt/mylib/perl/lib/perl/5.8.7], 多个目录可以用冒号分开。当然PERL总是会搜索默认的/usr/lib这个目录。
还有@INC不知道是什么东西。。。。。。(就象java的classpath环境变量)
---------------------------------------------------
- 'make' : build the source.
- 'make test' : do test
- 'make install' : install module
NOTE : when installed DBD:mysql moudle, you should specify some arguments. The first is 'cflags'(This is a list of flags that you want to give to the C compiler. The most important flag is the location of the MySQL header files.), second is 'libs'(his is a list of flags that you want to give to the linker or loader.The most important flags are the locations and names of additional libraries. ), such as 'perl Makefile.PL --cflags=-I<$MYSQL_HOME/include> --libs=-L<$MYSQL_HOME/libs>, also you can specify some other arguments, like testdb, testhost and so forth. Here will give a concrete example:
perl Makefile.PL --cflags="-I/opt/mysql/include" --libs="-L/opt/mysql/libs" --testdb=bugs --testuser=bugs --testpassword=bugs --testhost=localhost

后来的一次安装比较奇怪,我用[ perl Makefile.PL --cflags="-I/opt/software/mysql-max-5.0.21-linux-i686-glibc23/include" --libs="-L/opt/software/mysql-max-5.0.21-linux-i686-glibc23/lib" --testdb=bugs --testuser=bugs --testpassword=bugs --testhost=localhost ]这个指令创建Makefile,然后‘make, make test',在‘make test'的时候总是会报错:
-------------------------------------------------
t/40nulls............install_driver(mysql) failed: Can't load '/opt/source/perl-bugzilla-modules/DBD-mysql-3.0006/blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql: /opt/source/perl-bugzilla-modules/DBD-mysql-3.0006/blib/arch/auto/DBD/mysql/mysql.so: undefined symbol: mysql_stmt_free_result at /usr/lib/perl/5.8/DynaLoader.pm line 225.
-------------------------------------------------
而我第一次和第二次安装的时候都没有问题,也是perl5.8.7和DBD::mysql3.0006,为什么?? 没有办法,去网上查了一个,好多人问这个问题,而且这个bug看来是新版本里面才出现的, 总算也有人给出了解决方法,就是用下面的指令:
perl Makefile.PL --cflags="-I/opt/software/mysql-max-5.0.21-linux-i686-glibc23/include" --libs="-static-libgcc -L/opt/software/mysql-max-5.0.21-linux-i686-glibc23/lib -lmysqlclient -lz -lposix4 -lgen -lsocket -lnsl -lm" --testdb=bugs --testuser=bugs --testpassword=bugs --testhost=localhost
唉,终于‘make test'通过了,不简单,值得庆贺。
--------------------------------------------------
笑的太早啦,现在我第三次在ubuntu上面安装,这个DBD::mysql模块又好好的折腾了我一把,差点让我疯掉了,难道每次安装都要碰到那么多新问题么? 就说说这次的经历吧, mysql仍然是自己从mysql网站下载了一个二进制包,然后在ubuntu下安装的。就是说完全按照第二次的安装经验,一开始就碰到了一个异常,我直接把cpan上的解决描述贴在这里:

Some Linux distributions don't come with a gzip library by default. Running ``make'' terminates with an error message like

  LD_RUN_PATH="/usr/lib/mysql:/lib:/usr/lib" gcc
-o blib/arch/auto/DBD/mysql/mysql.so -shared
-L/usr/local/lib dbdimp.o mysql.o -L/usr/lib/mysql
-lmysqlclient -lm -L/usr/lib/gcc-lib/i386-redhat-linux/2.96
-lgcc -lz
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/DBD/mysql/mysql.so] Error 1

If this is the case for you, install an RPM archive like libz-devel, libgz-devel, zlib-devel or gzlib-devel or something similar.

解决办法就是安装zlib: sudo apt-get install zlib1g-dev.
接下来碰到的问题更恼火,在"make test"的时候,得到下面的异常:

  t/00base............install_driver(mysql) failed: Can't load
'../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol: _umoddi3
at /usr/local/perl-5.005/lib/5.005/i586-linux-thread/DynaLoader.pm
line 168.

原因据说是因为编译perl的编译器与编译mysql的编译器不一样,或者他们编译的目标平台不一样,就会出现这个问题,cpan也提供了解决方案,我试了,没用,可以参考这里:

http://search.cpan.org/src/CAPTTOFU/DBD-mysql-4.003/INSTALL.html#configuration

疯了,越安装反而越搞不定了, 后来没办法,我决定删除自己的下载的mysql,通过apt-get来安装,这样的话因为perl和mysql都是ubuntu自己,应该不会有问题了吧!

>sudo apt-get install mysql-server
>sudo apt-get install libmysqlclient14
note: 必须安装mysqlclient,才能得到mysql_config,这个文件定义了编译器需要的各种flag。

然后再来执行 “perl Makefile.PL --mysql_config=/usr/bin/mysql_config --testdb=bugs --testuser=bugs --testpassword=bugs --testhost=localhost“
哈哈,这下make test终于成功了。

** 安装GD库
> wget http://www.libgd.org/releases/gd-2.0.34.tar.gz
> ./configure;
> make
> make install
安装其他的库(依赖于GD)
> perl -MCPAN -e 'install "Chart::Base"'


** 我看最好的安装perl module的方式应该是先安装zlib,gdlib,DBD::mysql这些之后,使用”perl -MCPAN -e 'install "Bundle::Bugzilla",不然真是很麻烦。

----------------------------------

You can view these arguments by adding '--help' following the command.
More information please refer to the installation document of module.
3. After complete installing depented modules, you should rerun './checksetup.pl' (no '--check-modules' argument). This command will generate a configuration file 'localconfig', and build database structure(Confirm that all configuration about database is correct, you need create db_user. The script will generate schema automatically.).这里需要手工修改localconfig文件,设置数据库连接等。我通常还会把webservergroup设置成登录账户,管不了那么多, linux的安全设置搞的我很烦,只要能让bugzilla跑起来,管不了了。
4.完成配置之后,再运行checksetup.pl,脚本会自动创建数据库。
5. Config apache for bugzilla. I adopted a very extreme approach which just copy all files in $BUGZILLA_HOME to $APACHE_HOME/htdocs, then add below block to httpd.conf:

note: 在localconfig中设定webservergroup为www-data,并且重新执行checksetup.pl。 设置$BUGZILLA_HOME的owner为www-data。
??不知道为什么直接加符号链接的时候,apache会直接显示perl源文件。

Optional: If Bugzilla does not actually reside in the webspace directory, but instead has been symbolically linked there, you will need to add the following to the Options line of the Bugzilla directive (the same one as in the step above):

 +FollowSymLinks
note: Options +Indexes +ExecCGI +FollowSymLinks

NOTE : By default the DocumentRoot directory of apache is $APACHE_HOME/htdocs, but I want put my web application outside DocumentRoot directory. How do I achieve that? It is simple, just create a symbol link in DocumentRoot directory for you application directory. For example:
- change directory to $APACHE_HOME/htdocs(the DocumentRoot directory).
- 'ln -s /opt/bugzilla-2.22 bugzilla'.
Then you can access 'http://localhost:8080/bugzilla'.
6. Start apache and bugzilla. Access 'http://localhost:8080', now the bugzilla index page is displayed.
THIS IS JUST A BEGIN.

NOTE: All bugzilla parameter settings are stored in ${BUGZILLA_HOME}/data/params.

No comments: