Language:EN / NE / AE / DE / IT

안녕하세요. PHP 기반으로 작동하는 Sabre WebDAV 를 설치해 보도록 하겠습니다.






1. php 및 composer 설치하기


# php5 를 설치합니다. 같이 apache2 서버도 설치됩니다.

root@AOL-Debian:~# apt-get install php5

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following extra packages will be installed:

  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd

  liblua5.1-0 libonig2 libperl4-corelibs-perl libqdbm14 lsof php5-cli php5-common php5-json php5-readlin

Suggested packages:

  www-browser apache2-doc apache2-suexec-pristine apache2-suexec-custom php-pear php5-user-cache openssl

The following NEW packages will be installed:

  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd

  liblua5.1-0 libonig2 libperl4-corelibs-perl libqdbm14 lsof php5 php5-cli php5-common php5-json php5-re

0 upgraded, 22 newly installed, 0 to remove and 4 not upgraded.

Need to get 7,197 kB of archives.

After this operation, 22.2 MB of additional disk space will be used.

Do you want to continue? [Y/n] 


# composer 를 설치하는 과정입니다.

root@AOL-Debian:~# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

root@AOL-Debian:~# php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Installer verified

root@AOL-Debian:~# php composer-setup.php

All settings correct for using Composer

Downloading...


Composer (version 1.8.0) successfully installed to: /root/composer.phar

Use it: php composer.phar


root@AOL-Debian:~# php -r "unlink('composer-setup.php');"


# 실행파일을 /usr/bin/ 으로 옮깁니다.

root@AOL-Debian:~# cp composer.phar /usr/bin/composer


# 테스트로 실행한번 합니다.

root@AOL-Debian:~# composer

Do not run Composer as root/super user! See https://getcomposer.org/root for details

   ______

  / ____/___  ____ ___  ____  ____  ________  _____

 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/

/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /

\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/

                    /_/

Composer version 1.8.0 2018-12-03 10:31:16


Usage:

  command [options] [arguments]


Options:

  -h, --help                     Display this help message

  -q, --quiet                    Do not output any message

  -V, --version                  Display this application version

      --ansi                     Force ANSI output

      --no-ansi                  Disable ANSI output

  -n, --no-interaction           Do not ask any interactive question

      --profile                  Display timing and memory usage information

      --no-plugins               Whether to disable plugins.

  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.

  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug


Available commands:

  about                Shows the short information about Composer.

  archive              Creates an archive of this composer package.

  browse               Opens the package's repository URL or homepage in your browser.

  check-platform-reqs  Check that platform requirements are satisfied.

  clear-cache          Clears composer's internal package cache.

  clearcache           Clears composer's internal package cache.

  config               Sets config options.

  create-project       Creates new project from a package into given directory.

  depends              Shows which packages cause the given package to be installed.

  diagnose             Diagnoses the system to identify common errors.

  dump-autoload        Dumps the autoloader.

  dumpautoload         Dumps the autoloader.

  exec                 Executes a vendored binary/script.

  global               Allows running commands in the global composer dir ($COMPOSER_HOME).

  help                 Displays help for a command

  home                 Opens the package's repository URL or homepage in your browser.

  i                    Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.

  info                 Shows information about packages.

  init                 Creates a basic composer.json file in current directory.

  install              Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.

  licenses             Shows information about licenses of dependencies.

  list                 Lists commands

  outdated             Shows a list of installed packages that have updates available, including their latest version.

  prohibits            Shows which packages prevent the given package from being installed.

  remove               Removes a package from the require or require-dev.

  require              Adds required packages to your composer.json and installs them.

  run-script           Runs the scripts defined in composer.json.

  search               Searches for packages.

  self-update          Updates composer.phar to the latest version.

  selfupdate           Updates composer.phar to the latest version.

  show                 Shows information about packages.

  status               Shows a list of locally modified packages, for packages installed from source.

  suggests             Shows package suggestions.

  u                    Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.

  update               Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.

  upgrade              Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.

  validate             Validates a composer.json and composer.lock.

  why                  Shows which packages cause the given package to be installed.

  why-not              Shows which packages prevent the given package from being installed.





2. Sabre WebDAV 설치하기


# composer 패키지 관리자로 sabre/dav 를 설치합니다.

root@AOL-Debian:~# composer require sabre/dav ~3.2.0

Do not run Composer as root/super user! See https://getcomposer.org/root for details

./composer.json has been updated

Loading composer repositories with package information

Updating dependencies (including require-dev)

Package operations: 7 installs, 0 updates, 0 removals

  - Installing psr/log (1.1.0): Downloading (100%)         

  - Installing sabre/uri (1.2.1): Downloading (100%)         

  - Installing sabre/event (3.0.0): Downloading (100%)         

  - Installing sabre/http (v4.2.4): Downloading (100%)         

  - Installing sabre/xml (1.5.0): Downloading (100%)         

  - Installing sabre/vobject (4.1.6): Downloading (100%)         

  - Installing sabre/dav (3.2.3): Downloading (100%)         

sabre/http suggests installing ext-curl ( to make http requests with the Client class)

sabre/vobject suggests installing hoa/bench (If you would like to run the benchmark scripts)

sabre/dav suggests installing ext-curl (*)

Writing lock file

Generating autoload files


# 업데이트를 시도하여 최신버전으로 확인사살 합니다.

root@AOL-Debian:~# composer update sabre/dav

Do not run Composer as root/super user! See https://getcomposer.org/root for details

Loading composer repositories with package information

Updating dependencies (including require-dev)

Nothing to install or update

Generating autoload files


# sabre/dav 가 설치된 vendor 폴더를 html 로 옮깁니다.

root@AOL-Debian:~# mv vendor/ /var/www/html

root@AOL-Debian:~# cd /var/www/html/

root@AOL-Debian:/var/www/html# ls

index.html  vendor


# sabre/dav 가 쓸 data 폴더를 생성하고 파일 루트 디렉터리 public 을 심링크로 생성합니다.

root@AOL-Debian:/var/www/html# mkdir data


# /mnt 를 지정하면 sdcard 에 대한 경로를 찾지 못합니다.

root@AOL-Debian:/var/www/html# ln -s /mnt/media_rw/ public

root@AOL-Debian:/var/www/html# ls

data  index.html  public  vendor


# data 폴더에 대한 권한을 설정합니다.

root@AOL-Debian:/var/www/html# chmod a+rwx data


# server.php 파일을 생성합니다.

root@AOL-Debian:/var/www/html# nano server.php


<?php


use

    Sabre\DAV;


// The autoloader

require 'vendor/autoload.php';


// Now we're creating a whole bunch of objects

// public 폴더가 아니라면 다른 폴더 이름으로도 가능합니다.

$rootDirectory = new DAV\FS\Directory('public');


// The server object is responsible for making sense out of the WebDAV protocol

$server = new DAV\Server($rootDirectory);


// If your server is not on your webroot, make sure the following line has the

// correct information

// 이 부분은 서버 설정에 따라 다릅니다.

$server->setBaseUri('/server.php');


// The lock manager is reponsible for making sure users don't overwrite

// each others changes.

$lockBackend = new DAV\Locks\Backend\File('data/locks');

$lockPlugin = new DAV\Locks\Plugin($lockBackend);

$server->addPlugin($lockPlugin);


// This ensures that we get a pretty index in the browser, but it is

// optional.

$server->addPlugin(new DAV\Browser\Plugin());


// All we need to do now, is to fire up the server

$server->exec();


# 웹 서버가 /mnt 이하의 경로를 읽을 수 있도록 그룹에 추가해 줍니다.

root@AOL-Debian:/var/www/html# adduser www-data aid_sdcard_rw

Adding user `www-data' to group `aid_sdcard_rw' ...

Adding user www-data to group aid_sdcard_rw

Done.


root@AOL-Debian:/var/www/html# adduser www-data aid_media_rw

Adding user `www-data' to group `aid_media_rw' ...

Adding user www-data to group aid_media_rw

Done.





3. Sabre Webdav 테스트


http://u5pvr_ipaddr/server.php



이까지 오셨으면 나이스! 다음으로 넘어갑니다.





4. Basic Auth 추가 


# 만들었던 server.php 를 수정합니다. 아래의 부분을 추가하세요.

root@AOL-Debian:/var/www/html# nano server.php


<?php


use

    Sabre\DAV;


// The autoloader

require 'vendor/autoload.php';


// Now we're creating a whole bunch of objects

$rootDirectory = new DAV\FS\Directory('public');


// The server object is responsible for making sense out of the WebDAV protocol

$server = new DAV\Server($rootDirectory);


// If your server is not on your webroot, make sure the following line has the

// correct information

$server->setBaseUri('/server.php');


// The lock manager is reponsible for making sure users don't overwrite

// each others changes.

$lockBackend = new DAV\Locks\Backend\File('data/locks');

$lockPlugin = new DAV\Locks\Plugin($lockBackend);

$server->addPlugin($lockPlugin);


// This ensures that we get a pretty index in the browser, but it is

// optional.

$server->addPlugin(new DAV\Browser\Plugin());


// File Auth

use Sabre\DAV\Auth;

// 인증 파일 위치 입니다.

$authBackend = new Auth\Backend\File('data/passwd');

$authBackend->setRealm('SabreDAV');

$authPlugin = new Auth\Plugin($authBackend);


// Adding the plugin to the server.

$server->addPlugin($authPlugin);


// All we need to do now, is to fire up the server

$server->exec();


# md5 로 비번 값을 생성합니다.

# 아이디:Realm:비번

root@AOL-Debian:/var/www/html# php -r "echo md5('djjproject:SabreDAV:djjproject');"

4063c9ebaa8b39b195ac274e0962ee0a

root@AOL-Debian:/var/www/html# 


# data/passwd 파일에 아래와 같이 기입합니다.

root@AOL-Debian:/var/www/html# cd data


# 아이디:Realm:MD5

root@AOL-Debian:/var/www/html/data# nano passwd


djjproject:SabreDAV:4063c9ebaa8b39b195ac274e0962ee0a


기본 인증이 생겼는지 봅니다.






5. 레이드라이브 연동








6. 안드로이드 : Solid Explorer / nPlayer








7. 추가 기능은?


http://sabre.io/dav/gettingstarted/





여기까지 마치겠습니다 ㅎㅎ