Roundcube
Roundcube 是一个全功能、基于 PHP 的 Web 邮件客户端。
安装
安装 roundcubemail 软件包。此外,您还需要一个数据库(例如 MariaDB)和一个支持 PHP 的 Web 服务器。
配置
MariaDB
以下是如何使用 MariaDB 为 Roundcube 设置名为 roundcubemail
的数据库,用户名为 roundcube
,密码为 password
的示例
$ mysql -u root -p
CREATE DATABASE `roundcubemail` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; CREATE USER `roundcube`@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON `roundcubemail`.* TO `roundcube`@`localhost`; \q
对于您使用的任何数据库,您都需要初始化 roundcubemail 数据库表。以下是如何使用 MariaDB 执行此操作的示例
$ mysql -u root -p roundcubemail < /usr/share/webapps/roundcubemail/SQL/mysql.initial.sql
SQLite
SQLite 数据库将由 Roundcube 自动创建。确保配置文件中指定的文件位于 basedir 位置。考虑将 /var/lib/roundcubemail
添加到您的 basedir 定义中。这意味着创建目录并 chown 给 http
。
其他数据库
Roundcubemail 具有 mssql、Oracle 和 PostgreSQL 的安装脚本。
Roundcube
复制示例配置文件并根据您的配置进行调整
# cd /etc/webapps/roundcubemail/config # cp config.inc.php.sample config.inc.php # chown http:http config.inc.php
设置您的邮件服务器设置,并将 enable_installer
设置为启用安装向导
/etc/webapps/roundcubemail/config/config.inc.php
$config['db_dsnw'] = 'mysql://roundcube:****@localhost/roundcubemail'; $config['imap_host'] = 'ssl://127.0.0.1:993'; $config['smtp_host'] = 'ssl://127.0.0.1:465'; $config['des_key'] = 'some_awesome_long_semi_random_string'; $config['enable_installer'] = true;
为了使 roundcube 能够从文件名扩展名检测 mime 类型,您需要将其指向 mime.types 文件。Apache 通常自带一个。
# cp /etc/httpd/conf/mime.types /etc/webapps/roundcubemail/config/mime.types # chown http:http /etc/webapps/roundcubemail/config/mime.types
/etc/webapps/roundcubemail/config/config.inc.php
$config['mime_types'] = RCUBE_INSTALL_PATH . 'config/mime.types';
如果您未使用 Apache,请查看 /etc/webapps/roundcubemail/config/defaults.inc.php
中的可用信息。
PHP
确保在您的 PHP 配置中将以下变量调整为这些最小值
/etc/php/php.ini
date.timezone = "UTC"
并取消注释
extension=iconv
如果您在 php.ini
中配置了 open_basedir
,请确保它包含 /etc/webapps
和 /usr/share/webapps
,以便 PHP 可以打开所需的 Roundcube 文件。如果 open_basedir
被禁用/注释掉(默认设置),则您无需执行任何操作。
Webserver (Apache)
将 Apache 的配置文件复制到其配置目录
# cp /etc/webapps/roundcubemail/apache.conf /etc/httpd/conf/extra/roundcube.conf
并将其包含在底部
/etc/httpd/conf/httpd.conf
Include conf/extra/roundcube.conf
重启 Apache (httpd.service
)。
php_admin_value open_basedir
行,否则您将无法访问该页面。Webserver (Nginx)
为 RoundCube 添加一个 location 块
/etc/nginx/nginx.conf
location /webmail { alias /usr/share/webapps/roundcubemail; access_log /var/log/nginx/roundcube_access.log; error_log /var/log/nginx/roundcube_error.log; expires 30d; # Favicon location ~ ^/webmail/favicon.ico$ { root /usr/share/webapps/roundcubemail/skins/classic/images; log_not_found off; access_log off; expires max; } # Robots file location ~ ^/webmail/robots.txt { allow all; log_not_found off; access_log off; } # Deny Protected directories location ~ ^/webmail/(config|temp|logs)/ { deny all; } location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { deny all; } location ~ ^/webmail/(bin|SQL)/ { deny all; } # Hide .md files location ~ ^/webmail/(.+\.md)$ { deny all; } # Hide all dot files location ~ ^/webmail/\. { deny all; access_log off; log_not_found off; } # Roundcube fastcgi config location ~ /webmail(/.*\.php)$ { include fastcgi.conf; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_split_path_info ^/webmail/(.+\.php)(/.*)$; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PHP_VALUE open_basedir="/tmp/:/var/cache/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail"; } }
在较新版本的 Roundcube 中,手动设置 fastcgi_split_path_info
和 fastcgi_param PATH_INFO
会导致 Roundcube 出现故障。$request_filename
也无法正常工作。解决方案是此配置
location ~ /webmail/?$ { include fastcgi.conf; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/webapps/roundcubemail/index.php; fastcgi_param PHP_VALUE open_basedir="/tmp/:/var/cache/roundcubemail:/var/lib/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail:/var/lib/roundcubemail"; }
使用不同的配置将需要一个额外的 location 块来访问安装程序
installer
location 块,因为它应该只使用一次。在安装后删除 /usr/share/webapps/roundcubemail/installer/
目录也更安全,因为它仅用于安装步骤。删除 config.inc.php
中的 $config['enable_installer'] = true;
可能就足够了,如安装 Roundcube 部分所述。location ~ /webmail/installer/?.*$ { include fastcgi.conf; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/webapps/roundcubemail/installer/index.php; fastcgi_param PHP_VALUE open_basedir="/tmp/:/var/cache/roundcubemail:/var/lib/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail:/var/lib/roundcubemail"; }
最后 重启 nginx.service
单元。
/dev/null
添加到 open_basedir
列表中。安装 Roundcube
最后,您可以在浏览器中访问 Roundcube 安装向导:https://127.0.0.1/roundcube/installer 或 https://127.0.0.1/webmail/installer/(如果使用了备用的 nginx 配置)。
config.inc.php
中删除 $config['enable_installer'] = true;
。由于 ~/roundcube/config
目录包含有关您服务器的敏感信息,因此最好也通过添加以下行来禁止访问此目录。
/etc/httpd/conf/extra/roundcube.conf
<Directory /usr/share/webapps/roundcubemail/config> Options -FollowSymLinks AllowOverride None Require all denied </Directory>
技巧与诀窍
设置 Roundcube 以配合仅允许 TLS 身份验证的 IMAP/SMTP 服务器使用
对于现代 IMAP/SMTP 服务器来说,仅允许安全(加密)连接(例如使用 STARTTLS)是很常见的。如果您正在设置 Roundcube 以进行 TLS 连接,则基于 Web 的安装程序将无法帮助您。 您将需要手动编辑 /etc/webapps/roundcubemail/config/config.inc.php
,添加以下行
$config['imap_host'] = 'tls://mail.my_domain.org'; // For STARTTLS IMAP $config['imap_conn_options'] = [ 'ssl' => [ 'cafile' => '/etc/ssl/certs/Your_CA_certificate.pem', // For Letsencrypt use the following line if ISRG_Root_X1 is indeed the corresponding root certificate: //'cafile' => '/etc/ssl/certs/ISRG_Root_X1.pem', // Needed for example if you're using `localhost` as imap_host but your imap server presents another host name: //'peer_name' => 'mail.my_domain.org', ], ]; // For STARTTLS SMTP $config['smtp_conn_options'] = [ 'ssl' => [ 'cafile' => '/etc/ssl/certs/Your_CA_certificate.pem', // For Letsencrypt use the following line if ISRG_Root_X1 is indeed the corresponding root certificate: //'cafile' => '/etc/ssl/certs/ISRG_Root_X1.pem', // Needed for example if you're using `localhost` as imap_host but your imap server presents another host name: //'peer_name' => 'mail.my_domain.org', ], ];
其中 mail.my_domain.org
是您的 SSL 证书中的 CN
主机名(即您的 IMAP 服务器的主机名),而 /etc/ssl/certs/Your_CA_certificate.pem
是您的 SSL 证书的路径。
PHP SSL 配置选项的完整列表可以在这里找到。例如,您可能需要调整 ciphers
元素以对应于您的 IMAP 服务器允许的密码。
PDF 和 OpenDocument 文件预览
以下 Roundcube 扩展使您可以预览 PDF 或 OpenDocument 文件附件。
安装 roundcubemail-plugins-kolabAUR 软件包,并调整以下配置文件以启用扩展。
/etc/webapps/roundcubemail/config/config.inc.php
$config['plugins'] = [ 'pdfviewer', 'odfviewer' ];
如果您遇到任何文件权限问题,请尝试此命令
chown -R http:http /usr/share/webapps/roundcubemail/plugins/odfviewer/files
日历支持
安装 roundcubemail-plugins-kolabAUR 软件包。
更新 roundcube 数据库
# mysql -u root -p roundcubemail < /usr/share/webapps/roundcubemail/plugins/calendar/drivers/database/SQL/mysql.initial.sql
配置日历服务
默认配置应足以满足大多数应用程序,但是我们仍然需要将其移至适当的位置。
# cp /usr/share/webapps/roundcubemail/plugins/calendar/config.inc.php.dist /usr/share/webapps/roundcubemail/plugins/calendar/config.inc.php
Sabre\VObject\Property\Text Not Found
如果您收到此错误,则表示插件中未包含 Sabre 或 Sabre 已过期
# cd /usr/share/webapps/roundcubemail ; composer update ; composer require sabre/dav ~3.1.3
启用插件
/etc/webapps/roundcubemail/config/config.inc.php
$config['plugins'] = [ 'calendar' ];
将地址簿与 CardDav 联系人同步
使用 Roundcube 地址簿以获得地址字段等的自动完成功能非常有用。如果您的联系人存储在其他地方,并且远程应用程序提供 CardDav 服务器进行同步,则可以使用 roundcubemail-plugin-carddavAUR 扩展在 Roundcube 中访问您的远程地址簿。要启用它,请调整您的配置文件中的以下行
/etc/webapps/roundcubemail/config/config.inc.php
$config['plugins'] = [ 'carddav' ];
更多使用说明可以在此处找到。
使用 Mark as Junk 插件训练 SpamAssassin
markasjunk
插件向消息菜单添加“标记为垃圾邮件”或“标记为非垃圾邮件”按钮。以下设置使用此功能轻松训练 SpamAssassin 过滤器与 sa-learn
创建 /usr/share/webapps/roundcubemail/plugins/markasjunk/config.inc.php.dist
的副本作为同一目录中的 config.inc.php
,并根据您的需要进行修改。现在,确保具有以下内容
/usr/share/webapps/roundcubemail/plugins/markasjunk/config.inc.php
$config['markasjunk_learning_driver'] = 'cmd_learn'; $config['markasjunk_spam_cmd'] = '/usr/bin/vendor_perl/sa-learn --spam --username=%u %f'; $config['markasjunk_ham_cmd'] = '/usr/bin/vendor_perl/sa-learn --ham --username=%u %f';
启用插件
/etc/webapps/roundcubemail/config/config.inc.php
$config['plugins'] = [ 'markasjunk' ];
故障排除
SMTP 错误:身份验证失败
您可以首先尝试禁用(注释)config.inc.php 中的以下设置,如下所示
//$config['smtp_user'] = '%u'; //$config['smtp_pass'] = '%p';
收件人地址被拒绝
您可能会收到以下错误之一,具体取决于您是否使用 TLS 或 STARTTLS
530 5.7.0 Must issue a STARTTLS command first 554 5.7.1 <>: Recipient address rejected: Access denied
如果发生这种情况,请尝试将以下行添加到 config.inc.php
$config['smtp_user'] = '%u'; $config['smtp_pass'] = '%p';
在同一服务器上使用 Apache 运行 php8 和 php7
如果您在服务器上运行 php7 和 php8,则必须使用 php7-fpm 运行 roundcube。为此,请安装 php7-fpm[失效链接:软件包未找到] 软件包。
之后,您必须启用 mysql 扩展
/etc/php7/php.ini
extension=mysqli extension=pdo_mysql
现在启动/启用 php-fpm7.service
您必须编辑您的 Roundcube 配置
/etc/httpd/conf/extra/roundcube.conf
<Directory "/usr/share/webapps/roundcubemail"> AllowOverride All Options FollowSymlinks Require all granted php_admin_value open_basedir "/tmp/:/var/cache/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail" <FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php-fpm7/php-fpm.sock|fcgi://127.0.0.1/" </FilesMatch> </Directory>
然后重启 httpd.service
。