如何部署AgenDAV?

Calendar

1 基础知识

1.1 简介

AgenDAV是一个CalDAV Web客户端,它具有AJAX接口,允许用户管理自己的日历和共享日历。
AgenDAV依据GPLv3的许可证发布

1.2 安装要求

– 一台CalDAV服务器
– 一台Web服务器
– PHP >= 5.5.0
– PHP扩展要求
— ctype
— curl
— curl
— mbstring
— mcrypt
— tokenizer
— xml
— xmlreader
— xmlwriter
– 数据库后端
— MySQL
— PostgreSQL
— SQLite
详细的数据库驱动请参阅以下链接,
https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver

2 最佳实践

2.1 系统的配置

2.1.1 系统环境信息

HostName = agendav.cmdschool.org
OS = CentOS 7.6-x86_64
IP Address = 10.168.0.105

2.1.2 安装常用工具

yum install -y vim git

2.1.3 升级系统

yum -y update

执行完升级之后,重启操作系统,

reboot

2.1.4 配置yum源

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2.2 软件环境

2.2.1 部署数据库

请使用yum的方式安装PostgreSQL数据库,
https://www.cmdschool.org/archives/4080

2.2.2 部署基于Apache的PHP环境

请使用编译的方式安装Apache+PHP环境,
https://www.cmdschool.org/archives/3060

2.2.3 增加Apache模块

2.2.3.1 编译所需的模块pgsql

cd ~/php-5.6.40/ext/pgsql
phpize
./configure --with-pgsql=/usr/pgsql-9.6/
make
make install

注:以上选项需要先开启“–with-pdo-pgsql”选项

2.2.3.2 编译所需的模块ctype

cd ~/php-5.6.40/ext/ctype/
phpize
./configure
make
make install

2.2.3.3 编译所需的模块curl

cd ~/php-5.6.40/ext/curl
phpize
./configure
make
make install

根据提示安装所需的软件包,

yum install -y libcurl-devel

2.2.3.4 编译所需的模块mbstring

cd ~/php-5.6.40/ext/mbstring/
phpize
./configure
make
make install

2.2.3.5 编译所需的模块mcrypt

cd ~/php-5.6.40/ext/mcrypt/
phpize
./configure
make
make install

根据提示安装依赖的包,

yum install -y libmcrypt-devel

2.2.3.6 编译所需的模块tokenizer

cd ~/php-5.6.40/ext/tokenizer/
phpize
./configure
make
make install

2.2.3.7 编译所需的模块xml

cd ~/php-5.6.40/ext/xml
phpize
./configure
make
make install

2.2.3.8 编译所需的模块xmlreader

cd ~/php-5.6.40/ext/xmlreader/
phpize
./configure
make
make install

2.2.3.9 编译所需的模块xmlwriter

cd ~/php-5.6.40/ext/xmlwriter/
phpize
./configure
make
make install

2.2.3.10 加载所需的模块

echo extension=pgsql.so >> /etc/php.ini
echo extension=curl.so >> /etc/php.ini
echo extension=mbstring.so >> /etc/php.ini
echo extension=mcrypt.so >> /etc/php.ini

重启服务使配置生效,

systemctl restart httpd.service

检查模块加载,

php -m

如果看到类似如下的提示,说明模块已经加载,无需额外编译并加载,

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'xml.so' in Unknown on line 0
[...]
[PHP Modules]
[...]
xml
[...]

注:以上需要重php.ini文件中将加载的模块语句去掉

2.3 安装前的准备

2.3.1 下载软件包

cd ~
wget https://github.com/agendav/agendav/releases/download/2.2.0/agendav-2.2.0.tar.gz

如需其他版本,请从以下页面下载,
http://agendav.org/

2.3.2 解压软件包

cd ~
tar -xf agendav-2.2.0.tar.gz

2.4 部署软件包

2.4.1 部署源代码

mv agendav-2.2.0 /usr/share/agendav

2.4.2 配置目录权限

chown apache:apache -R /usr/share/agendav/web/
chmod 750 -R /usr/share/agendav/web/var/

2.5 配置数据库连接

2.5.1 创建数据库与用户并授权

su - postgres -c psql
create user agendav with password 'agendavpwd';
create database agendav encoding 'utf8';
grant all privileges on database agendav to agendav;
\q

2.5.2 开启协议的连接方式

vim /var/lib/pgsql/9.6/data/postgresql.conf

加入如下配置:

listen_addresses = '*'
port = 5432
password_encryption = no

重启服务使配置生效,

systemctl restart postgresql-9.6.service

2.5.3 配置用户连接权限

vim /var/lib/pgsql/9.6/data/pg_hba.conf

加入如下配置:

# IPv4 local connections:
host    all             all             0.0.0.0/0               md5

重载使服务生效,

systemctl reload postgresql-9.6.service

2.5.4 测试登录权限

su - postgres -c "psql -U agendav -h 127.0.0.1 -p 5432 -d agendav -W -c '\l'"

如果显示如下,则授权完成,

   Name    |    Owner    | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+-------------+----------+-------------+-------------+-----------------------
 agendav   | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
           |             |          |             |             | postgres=CTc/postgres+
           |             |          |             |             | agendav=CTc/postgres
 postgres  | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |             |          |             |             | postgres=CTc/postgres
 template1 | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |             |          |             |             | postgres=CTc/postgres
(5 rows)

2.6 配置应用

2.6.1 配置应用程序目录

ln -s /usr/share/agendav/web/public /var/www/agendav

2.6.2 配置虚拟服务器

vim /etc/httpd/conf.d/agendav.conf

加入如下配置:

<VirtualHost *:80>
        DocumentRoot /usr/share/agendav/web/public
        DirectoryIndex index.php index.html
        ServerName agendav.cmdschool.org
        ErrorLog logs/agendav_error_log
        CustomLog logs/agendav_access_log common
        <Directory /usr/share/agendav/web/public>
                #Order allow,deny
                #Allow from all
                AllowOverride None
                # for Apache from 2.4 use
                Require all granted
                # for Apache before 2.4 use
                #Order allow,deny
                #Allow from all
        </Directory>
        <Location />
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^ index.php [QSA,L]
        </Location>
        AcceptPathInfo On
</VirtualHost>

由于使用到重写模块,你需要启用它,

sed -i 's/#LoadModule rewrite_module modules\/mod_rewrite.so/LoadModule rewrite_module modules\/mod_rewrite.so/g' /etc/httpd/httpd.conf

你需要通过重启httpd服务是配置生效,

systemctl restart httpd.service

2.6.3 创建配置文件

cp /usr/share/agendav/web/config/default.settings.php  /usr/share/agendav/web/config/settings.php
vim /usr/share/agendav/web/config/settings.php

修改数据库配置,

// Database settings
$app['db.options'] = [
        'dbname' => 'agendav',
        'user' => 'agendav',
        'password' => 'agendavpwd',
        'host' => '127.0.0.1',
        'driver' => 'pdo_pgsql'
];

注:如需了解更加详细的配置,请参阅如下链接,
https://www.cmdschool.org/archives/4123

2.6.4 创建数据库

cd /usr/share/agendav/; /usr/sbin/php agendavcli migrations:migrate

2.6.5 配置名称解析

In Windows Client

notepad \Windows\System32\drivers\etc\hosts

加入如下配置:

10.168.0.104 agendav.cmdschool.org

注:以上只是临时配置,需要使用DNS解析代替

2.6.6 测试应用

In Windows Client
http://agendav.cmdschool.org
可见如下登录界面,

2.7 连接到DAViCal服务器

2.7.1 名称解析

echo '10.168.0.104 davical.cmdschool.org' >> /etc/hosts

2.7.2 修改配置文件

vim /usr/share/agendav/web/config/settings.php

修改如下参数,

$app['caldav.baseurl.public'] = 'http://davical.cmdschool.org';

注:以上需要搭建DAViCal服务端,如果你尚未搭建,请参考如下教程,
https://www.cmdschool.org/archives/3745

2.7.3 测试登录

In Windows Client
http://agendav.cmdschool.org

2.8 调试程序

2.8.1 开启调试模式

vim /etc/httpd/conf.d/agendav.conf

加入如下内容,

        <Location />
                SetEnvIf Remote_Addr ^10\.168\.0\.8$ AGENDAV_ENVIRONMENT=dev
        </Location/>

注:10.168.0.8为调试客户端的IP地址

2.8.2 查看日志

tail -f /usr/share/agendav/web/var/log/*.log
tail -f /var/log/httpd/agendav_*_log

2.9 修复bug

2.9.1 修复interface error

interface error
Error loading events from calendar /caldav.php/will/calendar/

你需要修改如下代码,

vim /usr/share/agendav/web/vendor/guzzlehttp/guzzle/src/Client.php

代码修改为,

                    // @todo: Do not rely on curl
                    // $options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST;
                    $options['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_ANY;
                    $options['curl'][CURLOPT_USERPWD] = "$value[0]:$value[1]";
                    break;

详细请参看官方的issues,
https://github.com/agendav/agendav/issues/191

参阅文档:
===============

安装文档:
———-
http://docs.agendav.org/en/2.2.0/#

mcrypt的下载
————
http://pecl.php.net/package/mcrypt

如何解决问题
————-
https://groups.google.com/forum/#!forum/agendav-general

没有评论

发表评论

Calendar
如何集成DAViCal的LDAP认证?

1 基础知识 1.1 LDAP身份验证的简介 – DAViCal支持LDAP身份验证 & …

Calendar
如何配置AgenDav?

1 前提条件 由于理解以下配置需要先有AgenDav环境,如果你需要,请按照如下教程搭建环境, ht …

Calendar
如何部署DAViCal?

1 基础知识 1.1 DAViCal的简介 – DAViCal是一个日历共享服务器 &# …