CentOS Stream@ConoHa VPS その4 メール・Webサーバーセットアップ

ひとまずは、SSL化は置いといて、メールサーバー、Webサーバーを使える状態に持っていく。

1. Dovecot/Postfix/MariaDB/Apache

dnf -y install dovecot dovecot-mysql
dnf -y install postfix postfix-mysql
dnf -y install mariadb-server httpd mod_ssl

2. PHP

dnf install -y wget
wget https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/libc-client-2007f-24.el8.x86_64.rpm
rpm -Uvh libc-client-2007f-24.el8.x86_64.rpm
dnf --enablerepo=remi -y install oniguruma5php
dnf module reset php
dnf module enable php:remi-7.4
dnf module install -y php:remi-7.4
dnf --enablerepo=remi install -y php-mysqlnd php-imap
systemctl enable httpd
systemctl enable php-fpm
systemctl start httpd
systemctl start php-fpm

3. MariaDB

3.1. 初期設定

systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
(略)
Enter current password for root (enter for none):  [Enter]
(略)
Set root password? [Y/n] Y
New password:  [新パスワード]
Re-enter new password:  [新パスワード]
(略)
Remove anonymous users? [Y/n] Y
 ... Success!
(略)
Disallow root login remotely? [Y/n] Y
 ... Success!
(略)
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
(略)
Reload privilege tables now? [Y/n] Y
 ... Success!

3.2. phpMyAdmin

3.2.1. インストール

dnf -y install zip unzip
cd /srv
wget https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip
unzip phpMyAdmin-5.0.4-all-languages.zip
mv phpMyAdmin-5.0.4-all-languages phpmyadmin
chown -R apache:apache phpmyadmin

3.2.2. 設定ファイル

dnf install -y expect
cd /srv/phpmyadmin
cp config.sample.inc.php config.inc.php
mkpasswd -l 32
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  ### Cookie認証用のパスフレーズとして後で使用
vi config.inc.php
/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; /* 先程取得したパスフレーズを記入 */

3.2.3. バーチャルホスト設定ファイル

vi /etc/httpd/conf.d/phpmyadmin.conf
Alias /phpmyadmin "/srv/phpmyadmin"
<Directory "/srv/phpmyadmin">
    DirectoryIndex index.html index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>
systemctl restart httpd

SELinux切ってないので、追加で以下の作業も。

dnf install -y policycoreutils-python-utils setroubleshoot-server
semanage fcontext -a -t httpd_sys_content_t '/srv/phpmyadmin(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/srv/phpmyadmin/tmp(/.*)?'
restorecon -RF /srv/phpmyadmin

4. PostfixAdmin

4.1. PostfixAdmin 本体のダウンロードと apache の設定

dnf install -y git
cd /srv/
git clone https://github.com/postfixadmin/postfixadmin.git
cd postfixadmin
LATEST_TAG=$(git tag -l | sort -V |  grep -iv 'push\|rc\|beta' | tail -1)
git checkout ${LATEST_TAG}
mkdir templates_c
chown -R apache templates_c
vi /etc/httpd/conf.d/postfixadmin.conf
Alias /postfixadmin "/srv/postfixadmin/public"
<Directory "/srv/postfixadmin/public">
    DirectoryIndex index.html index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

4.2. PostfixAdmin 用のデータベース作成

CREATE DATABASE IF NOT EXISTS postfix;  
CREATE USER 'postfix'@'localhost' IDENTIFIED BY '[postfixユーザーのパスワード]';
GRANT ALL PRIVILEGES ON postfix.* TO 'postfix'@'localhost';
FLUSH PRIVILEGES;

4.3. PostfixAdmin の設定ファイル、セットアップ画面

vi /srv/postfixadmin/config.local.php
<?php
$CONF['configured'] = true;

$CONF['default_language'] = 'ja';
$CONF['database_type'] = 'mysql';
$CONF['database_user'] = 'postfix';

$CONF['database_password'] = '[postfixユーザーのパスワード]';
$CONF['database_name'] = 'postfix';

$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';

$CONF['encrypt'] = 'dovecot:SHA512-CRYPT';

$CONF['footer_link'] = '//[your-domain]/postfixadmin/';
$CONF['footer_text'] = 'Return to [your-domain]/postfixadmin/';
?>
systemctl restart httpd

SELinux切ってないので、追加で以下の作業も。

dnf install -y policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_content_t '/srv/postfixadmin(/.*)?'
restorecon -RF /srv/postfixadmin
semanage fcontext -a -t httpd_sys_rw_content_t '/srv/postfixadmin/templates_c'
restorecon -v /srv/postfixadmin/templates_c

ここまでできたら、ブラウザでPostfixAdminのセットアップ画面にアクセスする。

https://[your-domain]/postfixadmin/setup.php

すると、各種チェックが行われて、問題なければページの下の方に、パスワードの入力欄が出てくる。

パスワードを入力して、[Generate password hash] というボタンを押すと、入力したパスワードがハッシュ化されて、以下のようなメッセージが出てくる。

If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set

$CONF['setup_password'] = '[ハッシュ化されたパスワード]';

これに従って、/srv/postfixadmin/config.local.php に追記する。

設定ファイルに追記できたら、セットアップ画面に再度アクセス。

今度は「Add a SuperAdmin Account」の欄が増えているので、必要事項を入力。

今度は、ログイン画面にアクセスする。

https://[your-domain]/postfixadmin/login.php

これで、ひとまずLAMP+メールの最低限の環境ができた。

今後やること

  • SSL化(マルチドメインで)
    • 一旦やろうとしたが、github から落としてきたcertbotが使えなくなっていた。
  • マルチドメイン化の手順確立
  • アンチウイルスソフトなど
  • メールサーバーをもう少し勉強
  • 別サーバーのUbuntu+Docker内で動かしているRedmineを移行できないか?
  • CentOS Stream で Docker とか使える?
コメントはまだありません

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA