红联Linux门户
Linux帮助

Ubutun下搭建MySQL用户验证的WebDav服务器

发布时间:2015-12-17 15:24:44来源:linux网站作者:dotuian

1、安装apache,mysql服务器

root@ubuntu:# apt-get install apache2 mysql-server mysql-client libapache2-mod-auth-mysql -y

※安装过程要求输入MySQL的root用户的密码,这里用rootadmin当做密码。
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1.
Set the ‘ServerName’ directive globally to suppress this message
解决Apache启动提示:
echo “ServerName localhost” >> /etc/apache2/apache2.conf


2、开启apache的webdav和mysql验证模块:

root@ubuntu:# a2enmod dav_fs
root@ubuntu:# a2enmod dav
root@ubuntu:# a2enmod auth_mysql


3、创建webdav数据库

root@ubuntu:# mysqladmin -u root -p create webdav

root@ubuntu:/etc/apache2/sites-available# mysql -u root -prootadmin
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON webdav.* TO 'webdavadmin'@'localhost' IDENTIFIED BY 'webdavpassword';
mysql> FLUSH PRIVILEGES;
mysql> USE webdav;

创建数据库结构和数据

CREATE TABLE IF NOT EXISTS `mysql_auth` (
`username` char(25) NOT NULL,
`password` char(32) DEFAULT NULL,
`active` int(1) NOT NULL,
`groups` char(25) DEFAULT NULL,
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `mysql_auth` (`username`, `password`, 'active', `groups`) VALUES('shoukii', MD5('shouadmin'), 1, 'testgroup');
INSERT INTO `mysql_auth` (`username`, `password`, 'active', `groups`) VALUES('test',    MD5('test'),      1, 'testgroup');


4、配置apache

root@ubuntu:# mkdir -p /var/www/webadv
root@ubuntu:# chown www-data /var/www/webadv
root@ubuntu:# cp -pf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/webdav.conf
root@ubuntu:# vim /etc/apache2/sites-available/webdav.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/webadv
<Directory /var/www/webadv/>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /webdav /var/www/webdav
<Location /webdav>
DAV On
AuthBasicAuthoritative Off
AuthUserFile /dev/null
AuthMySQL  On
AuthName   "webdav"
AuthName   "WebDav Server"
AuthType   Basic
Auth_MySQL_Host             localhost
Auth_MySQL_User             webdavadmin
Auth_MySQL_Password         webdavpassword
AuthMySQL_DB                webdav
AuthMySQL_Password_Table    mysql_auth
Auth_MySQL_Username_Field   username
Auth_MySQL_Password_Field   password
Auth_MySQL_Empty_Passwords  Off
Auth_MySQL_Encryption_Types PHP_MD5
Auth_MySQL_Authoritative    Off
AuthMySQL_Where             " and active=1 "
require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/webadv_error.log
CustomLog ${APACHE_LOG_DIR}/webadv_access.log combined
</VirtualHost>

重新加载Apache

root@ubuntu:# /etc/init.d/apache2 reload


5、测试

(1)安装 cadaver 客户端

root@ubuntu:/var/www/webdav# apt-get install cadaver

(2)连接WebDav服务器,

root@ubuntu:/var/www/webdav# cadaver http://localhost/webdav
Authentication required for WebDav Server on server `localhost':
Username: shoukii
Password:

dav:/webdav/> help
Available commands:
ls         cd         pwd        put        get        mget       mput
edit       less       mkcol      cat        delete     rmcol      copy
move       lock       unlock     discover   steal      showlocks  version
checkin    checkout   uncheckout history    label      propnames  chexec
propget    propdel    propset    search     set        open       close
echo       quit       unset      lcd        lls        lpwd       logout
help       describe   about
Aliases: rm=delete, mkdir=mkcol, mv=move, cp=copy, more=less, quit=exit=bye

dav:/webdav/> ls
Listing collection `/webdav/': succeeded.
001.txt                                0  12月  1 15:05
002.txt                                0  12月  1 15:05
003.txt                                0  12月  1 15:05
dav:/webdav/>