Linux MEDIAWIKI+APACHE+PHP架构维基网站建置
环境:Linux Red HatEnterprise Linux Server release 6.3
IP:10.0.20
一 、安装包准备
-
httpd-2.2.4.tar.gz
-
libxml2-2.6.32.tar.gz
-
php-5.6.2.tar.gz
-
mysql-5.5.9.tar.gz
-
cmake-2.8.4.tar.gz (mysql依赖此)
-
mediawiki-1.20.3.tar.gz
二、安装过程及相关配置
1、安装 httpd-2.2.4.tar.gz
# tar –zvxfhttpd-2.2.4.tar.gz
# cd httpd-2.2.4
# ./configure --prefix=/usr/local/apache--with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config--enable-modules=so --enable-dav --enable-maintainer-mode --enable-rewrite
# make &&make install
安装好后启动apache
#/usr/local/apache/bin/apachectl –k start
用浏览器查看http://10.0.20/,得到it works,说明apache已经配置成功了。
2. libxml2-2.6.32.tar.gz安装
#tar –zxvf libxml2-2.6.32.tar.gz(注意:安装php时候依赖此,configure参数--with-libxml-dir=/usr/local/libxml)
#cd libxml2-2.6.32
#./configure –prefix=/usr/local/libxml
#make &&make install
2. cmake-2.8.4.tar.gz安装
#tar -zxvf cmake-2.8.4.tar.gz
#cd cmake-2.8.4
#./configure
#make && make install
4.安装mysql
# tar -xzvf mysql-5.5.9.tar.gz
#mkdir /usr/local/mysql
#mkdir /usr/local/mysql/data
#cd mysql-5.5.9
#cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DINSTALL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
#make
#make install
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
4)、设置目录权限
# cd /usr/local/mysql
# chown –R mysql:mysql data
5)、配置文件
# cp support-files/my-medium.cnf/etc/my.cnf //这个配置仅适合小内存系统(32M - 64M)
打开如下注释:
innodb_data_home_dir =/usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
cp/home/mysql-5.1.36/support-files/mysql.server /etc/init.d/mysqld
cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755/etc/init.d/mysqld
chkconfig --addmysqld
初始化系统数据库的表
# cd /usr/local/mysql
# /usr/local/mysql/scripts/mysql_install_db--user=mysql
设置环境变量:
# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
#source /root/.bash_profile
启动mysql: service mysqld start
测试是否启动lsof –i:3306
[root@localhostwiki]# service mysqld status
MySQL running(37081) [ OK ]
6、创建用户、数据库并设定权限
mysql –uroot –p 直接回车进入mysql命令行
create user wikiidentified by ‘123456’
create database mediawiki;
grant allprivieges on *.* to wiki;
用mysql客户端工具Navicat Premium连接数据库看是否成功
连接报错:1042-Can’t get hostname for your address错误
修改/etc/my.cnf,加入如下两行配置,即可解决上述连接失败问题
skip-name-resolve
#忽略主机名的方式访问
lower_case_table_names=1
#忽略数据库表名大小写
7、安装php-5.6.2.tar.gz
其它安装步骤省略,重点在configure这一步,特别说明如下:
./configure--prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs=/usr/local/apache/bin/apxs--with-libxml-dir=/usr/local/libxml --with-config-file-path=/usr/local/lib
因为你的系统里面是Apache2,那么参数中的下面部分:--with-apxs=/usr/local/apache/bin/apxs 应该修改为:--with-apxs2=/usr/local/apache/bin/apxs
否则报错Apache 1.3 support while your server is Apache 2. Pleaseuse the appropriate
8.使Apache能处理php页面
在apache配置文件httpd.conf中增加如下红色配置
<IfModuledir_module>
DirectoryIndex index.html index.php
</IfModule>
另外增加两行:AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
保存退出,重启apache 生效
三、安装mediawiki-1.20.3.tar.gz
#tar –zxvf mediawiki-1.20.3.tar.gz
#cp mediawiki-1.20.3 /usr/local/apache/htdocs
访问wiki首页进行正式安装时候报错MediaWikiError: “Parse error: syntax error, unexpected T,expecting T_STRING in /usr/local/www/apache2
解决方法:1.Go to line 46, change the following from: class Namespace {
to:
class MWNamespace {
Save the file.
2.Now, let’s create a script: nano wikifix.sh
Copy and paste the following:
for fl in *.php; do
mv $fl $fl.old
sed 's/Namespace::/MWNamespace::/g' $fl.old > $fl
done
3.Save the file.
4.Change the file to executable by: chmod u+xwikifix.sh
5.Search the keyword Namespace:: and replace it byMWNamespace:::
6./wikifix.sh
再访问http://10.0.0.20/mediawiki-1.20.3/mw-config/index.php安装,安装完成自动生成LocalSettings.php在/usr/local/apache/htdocs/mediawiki-1.20.3/mw-config下,将此文件cp到上一级目录cp LocalSettings.php ../然后通过http://10.0.0.20/mediawiki-1.20.3/index.php访问wiki站点
安装后页面可能会产生很多warning:警告,根据警告内容找到该文件提示的警告行,将对应php页面的代码行注释掉,即正常
至此mediawiki+apache+php的维基站点建立完成!