apache mysql 认证_apache基于mysql数据库用户身份认证

首先安装一下mysql数据库

[root@localhost ~]# yum install -y mysql-sever mysql-devel

启动mysql数据库

[root@localhost ~]# service mysqld restart

给mysql的root设置一个密码为123

[root@localhost ~]# mysqladmin -uroot password 123

进入mysql数据库

[root@localhost ~]# mysql -uroot -p123

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.0.95 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zhanghan;

Query OK, 1 row affected (0.00 sec)

mysql> use zhanghan;

Database changed

mysql> create table edong(name char(25),pwd char(25),primary key(name));

Query OK, 0 rows affected (0.01 sec)

mysql> insert into edong(name,pwd) values('user01',ENCRYPT(111));

Query OK, 1 row affected (0.01 sec)

mysql> insert into edong(name,pwd) values('user02',ENCRYPT(111));

Query OK, 1 row affected (0.00 sec)

mysql> select * from edong;

+--------+---------------+

| name   | pwd           |

+--------+---------------+

| user01 | oLdqcSYvbXsu2 |

| user02 | .MquW8d0Wn.Xc |

+--------+---------------+

2 rows in set (0.00 sec)

我们在apache建立虚拟用户

[root@localhost ~]# cd /etc/httpd/conf.d/

[root@localhost conf.d]# vim virtual.conf

ServerName 192.168.115.128

DocumentRoot /www/users/html

AuthName linux               ----认证的名字

AuthType Basic               ----认证的类型,这里为基本的

AuthMYSQLEnable on           ----开启mysql认证

AuthMYSQLUser root           ----mysql的用户为root

AuthMYSQLPassword 123        ----mysql的root的密码为123

AuthMYSQLDB zhanghan         ----mysql里面需要认证的数据库(zhanghan)

AuthMYSQLUserTable edong     ----mysql里面需要认证数据库里的表(edong)

AuthMYSQLNameField name      ----mysql里面需要认证表里面的字段(name)

AuthMYSQLPasswordField pwd   ----mysql里面需要认证表里面的密码(pwd)

Require valid-user           ----每个用户都可以访问

保存退出

安装mysql的认证,不然启动httpd会报错

[root@localhost html]# yum install -y mod_auth_mysql

重启httpd

[root@localhost html]# /etc/init.d/httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

最后测试

http://192.168.115.128/

会跳出一个框框,输入用户名:user01

密码:111

e9c5e0a34ecb4cb014c0b9ef180e24c6.png

dcd56b7054191816f5f80f1e2b3e47f3.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值