ติดตั้ง Roundcube Webmail บน VPS Ubuntu
Roundcube คือ webmail client ที่ได้รับความนิยมสูงสุดสำหรับ self-hosted email server ใช้งาน email ผ่าน browser ได้สะดวกเหมือน Gmail รองรับ IMAP/SMTP ทำงานร่วมกับ Dovecot + Postfix mail stack รองรับปลั๊กอิน เปลี่ยน skin ได้ และมี community active ดูแลมาตลอดกว่า 15 ปี
ติดตั้ง Dependencies
sudo apt update
sudo apt install nginx php8.1-fpm php8.1-mysql php8.1-curl \
php8.1-xml php8.1-zip php8.1-mbstring php8.1-intl \
php8.1-imap mysql-server -y
# ตรวจ
php -v
nginx -v
สร้าง Database สำหรับ Roundcube
sudo mysql -u root -p
CREATE DATABASE roundcube CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON roundcube.* TO 'roundcube'@'localhost';
FLUSH PRIVILEGES;
EXIT;
ดาวน์โหลดและติดตั้ง Roundcube
# ดาวน์โหลด Roundcube (ตรวจ version ล่าสุดที่ roundcube.net)
cd /tmp
wget https://github.com/roundcube/roundcubemail/releases/download/1.6.7/roundcubemail-1.6.7-complete.tar.gz
tar -xzf roundcubemail-1.6.7-complete.tar.gz
sudo mv roundcubemail-1.6.7 /var/www/roundcube
# ตั้ง permissions
sudo chown -R www-data:www-data /var/www/roundcube
sudo chmod -R 755 /var/www/roundcube
Import Database Schema
mysql -u roundcube -p roundcube < /var/www/roundcube/SQL/mysql.initial.sql
ตั้ง Nginx Virtual Host
sudo nano /etc/nginx/sites-available/roundcube
server {
listen 80;
server_name mail.yourdomain.com;
root /var/www/roundcube;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Block access to sensitive dirs
location ~ ^/(config|temp|logs) {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/roundcube /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
ตั้ง Roundcube Config
sudo cp /var/www/roundcube/config/config.inc.php.sample \
/var/www/roundcube/config/config.inc.php
sudo nano /var/www/roundcube/config/config.inc.php
$config['db_dsnw'] = 'mysql://roundcube:StrongPassword123!@localhost/roundcube';
$config['imap_host'] = 'ssl://localhost:993';
$config['smtp_host'] = 'tls://localhost:587';
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['des_key'] = 'your_random_24_char_string_here';
$config['plugins'] = ['archive', 'zipdownload', 'password'];
$config['language'] = 'th_TH';
หากต้องการ domain อีเมลของตัวเองพร้อม hosting สำหรับเว็บไซต์ เว็บโฮสติ้งจาก asiagb.com มีแพ็กเกจที่รวม email hosting พร้อม DirectAdmin ราคาเริ่มต้นไม่กี่ร้อยบาทต่อปี สะดวกกว่าตั้งค่า mail server เองสำหรับผู้ที่ไม่ต้องการจัดการ infrastructure นอกจากนี้ยังสามารถตรวจสอบ DNS และ email configuration ของโดเมนด้วย dnsxray.com ก่อน setup Roundcube เพื่อให้แน่ใจว่า MX record ถูกต้อง
http://mail.yourdomain.com/installer เพื่อ verify configuration และ test database connection ก่อนใช้งานจริง จากนั้นลบ installer directory ออกทันที
ตรวจสอบว่า Roundcube ทำงานถูกต้อง
# ตรวจ PHP-FPM รัน
systemctl status php8.1-fpm
# ตรวจ Nginx log
sudo tail -f /var/log/nginx/error.log
# ตรวจ database connection
mysql -u roundcube -p roundcube -e "SHOW TABLES;"
# ตรวจ IMAP connectivity
curl -v imaps://localhost:993 --user [email protected]:password
sudo rm -rf /var/www/roundcube/installer เพื่อความปลอดภัย ถ้าไม่ลบ Roundcube จะแสดง warning ทุกครั้งที่ login
แก้ปัญหาที่พบบ่อย
Cannot connect to IMAP server
ตรวจ Dovecot รัน และ port 993 เปิดอยู่:
systemctl status dovecot
ss -tlnp | grep 993
sudo ufw allow 993/tcp
sudo ufw allow 587/tcp
Login ได้แต่ส่ง email ไม่ได้ (SMTP error)
ตรวจ Postfix และ SMTP credentials ใน config:
systemctl status postfix
sudo tail -20 /var/log/mail.log
# ตรวจ config SMTP ใน config.inc.php
grep smtp /var/www/roundcube/config/config.inc.php
Database connection failed
ตรวจ credentials และ MySQL service:
systemctl status mysql
mysql -u roundcube -pStrongPassword123! roundcube -e "SELECT 1;"
Roundcube แสดง "500 Internal Server Error"
ดู PHP error log และ Nginx error log:
sudo tail -50 /var/log/nginx/error.log
sudo tail -50 /var/log/php8.1-fpm.log
# ตรวจ PHP extension ครบ
php -m | grep -E "imap|mysql|curl|xml|mbstring"
คำถามที่พบบ่อย
Roundcube กับ Rainloop/Snappymail ต่างกันอย่างไร?
Roundcube เป็น mature project ที่มี community ใหญ่ plugin ecosystem ครบ และ documentation ดี Snappymail (fork จาก Rainloop) เบากว่าและใช้งาน AJAX มากกว่า ทำให้ responsive กว่าบน connection ช้า สำหรับ server ส่วนตัว Roundcube เหมาะกว่าเพราะ feature ครบกว่า
Roundcube รองรับ 2FA ไหม?
รองรับผ่าน plugin "Two Factor Authentication" สำหรับ TOTP (Google Authenticator) ติดตั้งเพิ่มได้จาก GitHub: github.com/alexandregz/twofactor_gauthenticator หรือ plugin อื่นที่รองรับ U2F/WebAuthn
ต้องการ mail server เองก่อนถึงจะใช้ Roundcube ได้ไหม?
ใช่ Roundcube เป็นแค่ webmail client ต้องมี IMAP server (เช่น Dovecot) และ SMTP server (เช่น Postfix) ก่อน หรือใช้ Roundcube connect ไปยัง email provider ภายนอกเช่น Office 365 หรือ Zoho Mail ก็ได้