如何部署WebMail Roundcube官方移动版?

WebMail

1 基础知识

1.1 前言

Roundcube Webmail 1.4-beta是具有里程碑性质的一个版本,包含elastic的皮肤,该皮肤支持各种类型的移动设备,笔者有意尝鲜,本章不再累赘基础知识,如果你还没有部署过roundcube,请参阅之前的稳定版本部署。
https://www.cmdschool.org/archives/2731

1.2 elastic项目介绍

– elastic是一个针对roundcube开发的移动设备皮肤项目,原项目地址,
https://github.com/roundcube/elastic
– elastic当前合并到roundcubemail项目,详细地址如下,
https://github.com/roundcube/roundcubemail/tree/master/skins/elastic

2 最佳实践

2.1 环境配置

2.1.1 系统环境配置

hostname = roundcube.cmdschool.org
ip address = 10.168.0.100

2.1.2 辅助工具的安装

yum install -y vim wget unzip git

2.1.3 部署LNMP环境

请参阅以下文档部署LNMP环境,
https://www.cmdschool.org/archives/1
注:PHP FastCGI请使用编译方式安装

2.1.4 下载安装包

cd ~
wget https://github.com/roundcube/roundcubemail/releases/download/1.4-beta/roundcubemail-1.4-beta-complete.tar.gz

其他版本请从如下链接下载,
https://github.com/roundcube/roundcubemail/releases

2.2 部署roundcube

2.2.1 部署源代码

mkdir -p /var/www/mail.cmdschool.org
cd ~
tar -xf roundcubemail-1.4-beta-complete.tar.gz
cp -a roundcubemail-1.4-beta/* /var/www/mail.cmdschool.org/
chown -R apache:nginx /var/www/mail.cmdschool.org/
chmod -R 774 /var/www/mail.cmdschool.org/

2.2.2 配置数据库权限

mysql -uroot -p
create database roundcubemail;
grant all privileges on roundcubemail.* to roundcube@localhost identified by 'roundcubepwd';
flush privileges;
quit;

2.2.3 导入数据库结构

mysql -uroot -p -e 'use roundcubemail; source /var/www/mail.cmdschool.org/SQL/mysql.initial.sql;'

2.2.4 配置PHP

vim /etc/php.ini

加入如下配置:

memory_limit = 64M
display_errors = Off
log_errors = On
error_log = /var/log/php-fpm/error.log
upload_max_filesize = 5M
post_max_size = 6M
zlib.output_compression = Off
suhosin.session.encrypt = Off
session.auto_start = Off
session.gc_maxlifetime = 21600
session.gc_divisor = 500
session.gc_probability = 1
date.timezone = "Asia/Shanghai"

2.2.5 配置虚拟服务器

vim /etc/nginx/conf.d/mail.cmdschool.org_80.conf

加入如下配置:

server {
    listen       80;
    server_name  mail.cmdschool.org;

    charset koi8-r;
    access_log  /var/log/nginx/mail.access.log  main;

    location / {
        root   /var/www/mail.cmdschool.org;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/mail.cmdschool.org;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

重载是配置生效:

systemctl reload nginx

2.3 运行安装向导

http://mail.cmdschool.org/installer/
注:以上域名请配置DNS或者hosts记录,否则无法访问,访问后的页面显示如下,

2.4 使用composer安装必须的扩展

2.4.1 安装的常见错误

缺少openssl扩展的错误提示,

  [Composer\Exception\NoSslException]
  The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl
  extension, you can disable this error, at your own risk, by setting the 'disable-tls' option to true.

缺少git命令的错误提示

  [RuntimeException]
  Failed to clone https://git.kolab.org/diffusion/PNL/php-net_ldap.git, git was not found, check that it is install
  ed and in your PATH env.

  sh: git: command not found

缺少mbstring扩展包的错误提示

requirements could not be resolved to an installable set of packages.

  Problem 1
    - pear/crypt_gpg v1.6.3 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - pear/crypt_gpg v1.6.2 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - pear/crypt_gpg v1.6.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - pear/crypt_gpg v1.6.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - Installation request for pear/crypt_gpg ~1.6.0 -> satisfiable by pear/crypt_gpg[v1.6.0, v1.6.1, v1.6.2, v1.6.3].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.

缺少gd扩展包的错误提示

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - endroid/qrcode 1.6.6 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - endroid/qrcode 1.6.5 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - Installation request for endroid/qrcode ~1.6.5 -> satisfiable by endroid/qrcode[1.6.5, 1.6.6].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.

2.4.2 错误解决方法

所以,为了解决以上错误提示,我们需要安装依赖的库

yum install -y openssl-devel gd-devel

修正内核文件的路径,

ln -s /usr/lib64/libssl.so /usr/lib/

手动安装GD(yum安装无法解决),
https://www.cmdschool.org/archives/2779
重新预编译PHP,

cd ~/php-7.1.12		
./configure --bindir=/usr/sbin/ \
            --sbindir=/usr/sbin/ \
            --sysconfdir=/etc/ \
            --libdir=/usr/lib64/  \
            --mandir=/usr/share/man/ \
            --includedir=/usr/include/ \
            --with-fpm-user=apache \
            --with-fpm-group=apache \
            --enable-fpm \
            --with-mysqli \
            --with-openssl=/usr \
            --enable-mbstring \
            --with-gd=/usr

重新编译并安装PHP,

make
make install

2.5 安装其他的扩展

以下扩展可根据实际情况选用,并非都是必选

2.5.1 安装工具扩展库

yum安装可安装的扩展库:

yum install -y openldap-devel libwebp-devel libjpeg-turbo-devel libXpm-devel freetype-devel libicu-devel libzip-devel

2.5.2 安装imagick扩展库

https://www.cmdschool.org/archives/2795
注:yum无法安装,需要自行编译

2.5.3 修正内核文件的路径

ln -s /usr/lib64/libldap.so /usr/lib/

2.5.4 重新预编译PHP

cd ~/php-7.1.12		
./configure --bindir=/usr/sbin/ \
            --sbindir=/usr/sbin/ \
            --sysconfdir=/etc/ \
            --libdir=/usr/lib64/  \
            --mandir=/usr/share/man/ \
            --includedir=/usr/include/ \
            --with-fpm-user=apache \
            --with-fpm-group=apache \
            --enable-fpm \
            --with-mysqli \
            --with-openssl=/usr \
            --enable-mbstring \
            --with-gd=/usr \
            --enable-intl \
            --enable-exif \
            --with-ldap=/usr \
            --with-webp-dir=/usr \
            --with-jpeg-dir=/usr \
            --with-xpm-dir=/usr \
            --with-freetype-dir=/usr \
            --enable-zip \
            --with-pdo-mysql

2.5.5 重新编译并安装PHP

			
make
make install

注:如果执行“make”有如下错误提示,

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

请按如下方法处理,

vim Makefile

以下变量加入如下参数,

EXTRA_LIBS = -llber

2.5.6 加载imagick扩展

echo 'extension=imagick.so' >> /etc/php.ini

2.5.7 重启服务使配置生效

systemctl restart php-fpm.service

2.6 链接配置

2.6.1 生成配置文件

http://mail.cmdschool.org/installer/
完成之前的步骤,向导可以单击【next】,根据向导完成配置后可单击【Download】即可得到配置文件

2.6.2 链接数据库

vim /var/www/mail.cmdschool.org/config/config.inc.php

配置如下(即下载的配置文件):

<?php

/* Local configuration for Roundcube Webmail */

// ----------------------------------
// SQL DATABASE
// ----------------------------------
// Database connection string (DSN) for read+write operations
// Format (compatible with PEAR MDB2): db_provider://user:password@host/database
// Currently supported db_providers: mysql, pgsql, sqlite, mssql, sqlsrv, oracle
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// NOTE: for SQLite use absolute path (Linux): 'sqlite:////full/path/to/sqlite.db?mode=0646'
//       or (Windows): 'sqlite:///C:/full/path/to/sqlite.db'
$config['db_dsnw'] = 'mysql://roundcube:roundcubepwd@127.0.0.1/roundcubemail';

// ----------------------------------
// IMAP
// ----------------------------------
// The IMAP host chosen to perform the log-in.
// Leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// Supported replacement variables:
// %n - hostname ($_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part)
// %s - domain name after the '@' from e-mail address provided at login screen
// For example %n = mail.domain.tld, %t = domain.tld
// WARNING: After hostname change update of mail_host column in users table is
//          required to match old user data records with the new host.
$config['default_host'] = 'imap.cmdschool.org';

// ----------------------------------
// SMTP
// ----------------------------------
// SMTP server host (for sending mails).
// Enter hostname with prefix tls:// to use STARTTLS, or use
// prefix ssl:// to use the deprecated SSL over SMTP (aka SMTPS)
// Supported replacement variables:
// %h - user's IMAP hostname
// %n - hostname ($_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part)
// %z - IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
$config['smtp_server'] = 'smtp.cmdschool.org';

// provide an URL where a user can get support for this Roundcube installation
// PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
$config['support_url'] = '';

// This key is used for encrypting purposes, like storing of imap password
// in the session. For historical reasons it's called DES_key, but it's used
// with any configured cipher_method (see below).
$config['des_key'] = 'uyfUFVOHmsJcS6I1fJVZTPqj';

// Automatically add this domain to user names for login
// Only for IMAP servers that require full e-mail addresses for login
// Specify an array with 'host' => 'domain' values to support multiple hosts
// Supported replacement variables:
// %h - user's IMAP hostname
// %n - hostname ($_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part)
// %z - IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
$config['username_domain'] = 'cmdschool.org';

// ----------------------------------
// PLUGINS
// ----------------------------------
// List of active plugins (in plugins/ directory)
$config['plugins'] = array();

// skin name: folder from skins/
$config['skin'] = 'elastic';

// Encoding of long/non-ascii attachment names:
// 0 - Full RFC 2231 compatible
// 1 - RFC 2047 for 'name' and RFC 2231 for 'filename' parameter (Thunderbird's default)
// 2 - Full 2047 compatible
$config['mime_param_folding'] = 0;

2.6.3 链接后的检查

访问如下链接,
http://mail.cmdschool.org/
如果看到如下界面则基本配置完成,

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

https://github.com/roundcube/roundcubemail/wiki/Build-from-source

没有评论

发表评论

WebMail
如何部署Roundcube imapsync插件?

1 基础知识 1.1 Roundcube imapsync 1.1.1 基本概念 – R …

WebMail
如何安装Roundcube的全局通讯录?

1 简介 地址簿,提供丰富的界面来管理你的联系人信息(保存或访问你个人或共享的地址簿) 2 最佳实践 …

WebMail
如何熟悉WebMail Roundcube的配置?

1 基础知识 1.1 搭建环境 阅读本章的参数,你需要先搭建WebMail Roundcube的环境 …