一.安装mysql
1. 下载mysql
wget http://download.softagency.net/MySQL/Downloads/MySQL-5.1/mysql-5.1.48.tar.gz
2. 安装mysql
tar xvfz mysql-5.1.48.tar.gz
cd mysql-5.1.48
./configure --prefix=/usr/local/mysql
make
make install
3. 启动mysql
/usr/local/mysql/bin/mysqld_safe
二.安装apache
1.下载apache
wget http://apache.freelamp.com/httpd/httpd-2.2.13.tar.gz
2.安装apache
tar -xzvf httpd-2.2.13.tar.gz
cd httpd-2.2.13
./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-rewrite --enable-so
make;
make install
三.apache动态加载mysql认证模块,apache安装的时候没有生成
1. 下载模块
Wget
http://ncu.dl.sourceforge.net/project/modauthmysql/modauthmysql/3.0.0/mod_auth_mysql-3.0.0.tar.gz
2. 针对apache2打补丁
给mod_auth_mysql.c打补丁,使该模块支持apache2(补丁文件是apache2.2.diff)
cp apache2.2.diff mod_auth_mysql-3.0.0/
cd mod_auth_mysql-3.0.0
patch <apache2.2.diff
3. 生成模块,具体怎么生成可参考mod_auth_mysql-3.0.0目录下的BUILD文件
/usr/local/apache/bin/-c -L/usr/local/mysql/lib/mysql -I/usr/local/mysql/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c
/usr/local/apache/bin/apxs -i mod_auth_mysql.la
两个命令敲完后会在apache的modules目录下面生成mod_auth_mysql.so文件
4. 修改apache配置文件并重启apache进程,具体配置可参考/etc/httpd/conf.d/auth_mysql.conf 这个配置文件,
vi /usr/local/apache/conf/httpd.conf
加载模块:
LoadModule mysql_auth_module modules/mod_auth_mysql.so
对访问目录认证
<Directory "/usr/local/apache/htdocs">
AuthBasicAuthoritative Off
AuthName "MySQL authenticated zone"
AuthType Basic
AuthMYSQLEnable on
AuthMySQLUser authuser
AuthMySQLPassword authpass
AuthMySQLDB auth
AuthMySQLUserTable users
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
require valid-user
</Directory>
配置说明:
AuthMySQLUser authuser 指定apache访问数据库的用户
AuthMySQLPassword authpass指定apache访问数据库的密码
AuthMySQLDB auth指定的是访问认证是使用的库auth
AuthMySQLUserTable users指定的是访问认证使用的表
四.创建数据库
1. 创建数据库
CREATE DATABASE auth; //创建数据库
USE auth;
CREATE TABLE users ( //创建表结构
user_name CHAR(30) NOT NULL,
user_passwd CHAR(20) NOT NULL,
PRIMARY KEY (user_name)
);
2. 在表中创建apache的登录认证用户
INSERT INTO users VALUES ('test1', ENCRYPT('pass1'));
3. 为apache访问mysql建立连接用户,赋予authuser所有权限访问auth库,仅仅在实验环境中才这样哦,请不要模仿
Use mysql
grant all privileges on auth.* to authuser@localhost identified by 'authpass' with grant option;
五.安装PHP,如果仅仅是支持apache和mysql下面的一些编译参数都用不到,下列的一些参数在安装cacti时要用到,否则要重新编译安装一次php
wget http://cn.php.net/distributions/php-5.3.3.tar.gz
tar xvfz php-5.3.3.tar.gz
cd php-5.3.3
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd --with-snmp --with-ldap --with-gettext --with-config-file-path=/usr/local/php/etc --enable-sockets
Make
Make install