WAVE Log
PHP 設定ファイル編集

:~# vi /etc/php.ini

変更削除追加

short_open_tag = Off ↓↓↓ short_open_tag = On output_buffering = 4096 ↓↓↓ output_buffering = Off display_errors = Off ↓↓↓ display_errors = On ;date.timezone = Asia/Tokyo ;mbstring.language = Japanese ;mbstring.internal_encoding = UTF-8 ;mbstring.http_input = UTF-8 ;mbstring.http_output = UTF-8 ;mbstring.encoding_translation = Off ↓↓↓ mbstring.encoding_translation = On ;mbstring.detect_order = auto ;mbstring.substitute_character = none ↓↓↓ mbstring.substitute_character = "?"

httpd リロード。

:~# systemctl reload httpd

ImageMagick と imagick をインストール

ImageMagick をインストール。

:~# dnf --enablerepo=epel,crb install ImageMagick ImageMagick-devel

僕は WebP への変換で cwebp, gif2webp, webpmux を使っているので、libwebp-tools をインストール。

:~# dnf --enablerepo=epel,crb install libwebp-tools

確認。

:~# magick --version :~# cwebp -version :~# gif2webp -version :~# webpmux -version

必要なパッケージをインストール。

:~# dnf install php-devel php-pear

pecl で imagick をインストール。
Enter

:~# pecl install imagick ・・・ ・・・ Please provide the prefix of ImageMagick installation [autodetect] : ・・・ ・・・ You should add "extension=imagick.so" to php.ini

php.ini 最下部に追記

:~# vi /etc/php.ini ・・・ ・・・ extension=imagick.so

反映。

:~# systemctl restart php-fpm

Let’s Encrypt で SSL 証明書を取得

Certbot クライアントをインストールします。参考:Certbot Instructions
まず、snapd をインストールし、自動起動有効+起動。

:~# dnf --enablerepo=epel install snapd :~# systemctl enable --now snapd.socket

シンボリックリンクを作成。

:~# ln -s /var/lib/snapd/snap /snap

snap のパスが正しく更新されるようにするには、一度ログアウトして再度ログインするか、システムを再起動してください。

certbot をインストール。

:~# snap install --classic certbot

下記エラーが出たら、数分待ってから再度実行する。

error: too early for operation, device not yet seeded or device model not acknowledged

シンボリックリンクを作成。

:~# ln -s /snap/bin/certbot /usr/local/bin/certbot

証明書取得。(80番ポートが外部からアクセス可能であること)

:~# certbot certonly --webroot \ -w /var/www/html \ -m you@example.com \ --agree-tos \ -d xxxxx.xvps.jp

・・・ ・・・ Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/xxxxx.xvps.jp/fullchain.pem Key is saved at: /etc/letsencrypt/live/xxxxx.xvps.jp/privkey.pem This certificate expires on 2026-07-14. These files will be updated when the certificate renews. Certbot has set up a scheduled task to automatically renew this certificate in the background. ・・・ ・・・

mod_ssl インストール。

:~# dnf -y install mod_ssl

SSL 設定ファイル編集。

:~# vi /etc/httpd/conf.d/ssl.conf

変更追加

# Use separate log files for the SSL virtual host; note that LogLevel # is not inherited from httpd.conf. ErrorLog logs/ssl_error_log ↓↓↓ ErrorLog logs/error_log TransferLog logs/ssl_access_log ↓↓↓ CustomLog logs/access_log combined env=!no_log LogLevel warn ・・・ ・・・ #SSLProtocol all -SSLv3 #SSLProxyProtocol all -SSLv3 SSLProtocol TLSv1.2 TLSv1.3 SSLProxyProtocol TLSv1.2 TLSv1.3 ・・・ ・・・ SSLHonorCipherOrder on ・・・ ・・・ SSLCipherSuite PROFILE=SYSTEM ↓↓↓ SSLCipherSuite HIGH:!aNULL:!MD5:!3DES:!CAMELLIA:!AESCCM:!ECDSA ・・・ ・・・ SSLCertificateFile /etc/pki/tls/certs/localhost.crt ↓↓↓ SSLCertificateFile /etc/letsencrypt/live/xxxxx.xvps.jp/fullchain.pem ・・・ ・・・ SSLCertificateKeyFile /etc/pki/tls/private/localhost.key ↓↓↓ SSLCertificateKeyFile /etc/letsencrypt/live/xxxxx.xvps.jp/privkey.pem ・・・ ・・・ Header always set Strict-Transport-Security "max-age=15768000" </VirtualHost>

Apache 設定反映。

:~# systemctl reload httpd

ポート開放。

:~# firewall-cmd --add-service=https --zone=public --permanent :~# firewall-cmd --reload

自動更新をテストする。

:~# certbot renew --dry-run

MariaDB インストール

php-mysqlnd も一緒にインストールしています。

:~# dnf -y install mariadb-server php-mysqlnd

MariaDB 設定ファイル編集。

追加

:~# vi /etc/my.cnf.d/mariadb-server.cnf

# This group is only read by MariaDB-10.11 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mariadb-10.11] character-set-server = utf8mb4

:~# vi /etc/my.cnf.d/client.cnf

# This group is not read by mysql client library, # If you use the same .cnf file for MySQL and MariaDB, # use it for MariaDB-only client options [client-mariadb] default-character-set = utf8mb4

自動起動有効+起動。

:~# systemctl enable --now mariadb

MariaDB 初期設定。

:~# mysql_secure_installation

入力

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!

【MariaDB 操作】

MariaDB へ root でログイン。(パスワード不要)

:~# mysql

root で DB(app_db)を作る

MariaDB [(none)]> CREATE DATABASE app_db;

root でユーザー(app_user)を作る(パスワード:xxx)

MariaDB [(none)]> CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'xxx';

必要最小限の権限だけ与える

MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE ON app_db.* TO 'app_user'@'localhost';

ログアウト。

MariaDB [(none)]> exit Bye

【データのバックアップ及びリストア】

:~# mysqldump app_db > app_db.sql

:~# mysql app_db < app_db.sql

Composer インストール

:~# curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

確認。

:~# composer --version

Composer 本体のアップデート方法。

:~# composer self-update

composer update は プロジェクト内のライブラリを更新するコマンド であり、 Composer 本体の更新とは別です。

Composer 本体 → composer self-update
プロジェクトの依存パッケージ → composer update(慎重に扱う必要あり)

Brevo でメール送信をする

Brevo で利用可能なSMTPポートには、465, 587 に加えて、2525 があります。

465, 587 へは VPS の制限から接続できないのですが、2525 には接続できたので 2525 ポートを使って PHPMailer でメール送信ができます。

OpenSSL で SMTP サーバーに直接接続できるか確認する。

:~# openssl s_client -connect smtp-relay.brevo.com:465 何も返らず固まる(アウトバウンド制限) :~# openssl s_client -starttls smtp -connect smtp-relay.brevo.com:587 何も返らず固まる(アウトバウンド制限) :~# openssl s_client -starttls smtp -connect smtp-relay.brevo.com:2525 証明書情報や 250 などの応答が返る

また、Brevo で提供している API を使えばそもそもポートを気にせずにメール送信ができます。(API は 443 ポートで通信するためブロックされません)

API 送信をする。PHP SDK | Brevo API Documentation
/usr/local/lib で Composer を実行して SDK をインストール。

:~# cd /usr/local/lib :/usr/local/lib# composer require getbrevo/brevo-php :/usr/local/lib# composer require guzzlehttp/guzzle

APIキーを取得して、authorized IP address も登録する。

PHPコード例:

<?php require_once '/usr/local/lib/vendor/autoload.php'; use Brevo\Brevo; use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem; // APIクライアント初期化 $client = new Brevo(apiKey: 'YOUR_BREVO_API_KEY'); // メール送信 $result = $client->transactionalEmails->sendTransacEmail( new SendTransacEmailRequest([ 'subject' => 'Hello from Brevo API!', 'htmlContent' => '<html><body><p>Hello!</p><p>This is a test email via Brevo API.</p></body></html>', 'sender' => new SendTransacEmailRequestSender([ 'name' => 'Your Name', 'email' => '[email protected]', ]), 'to' => [ new SendTransacEmailRequestToItem([ 'email' => '[email protected]', 'name' => 'John Doe', ]), ], ]) ); echo 'Email sent. Message ID: ' . $result->messageId . PHP_EOL;

logwatch のレポートを Brevo API でメール送信する

「logwatch → ファイル出力 → PHP で Brevo API 送信」という構成。

logwatch をインストール。

:~# dnf install logwatch

logwatch をファイル出力にするコマンド。

logwatch --output file --filename /var/log/logwatch-report.txt

PHP でファイルを読み込んで Brevo API 送信。

/usr/local/scripts ディレクトリ作成。

:~# mkdir -p /usr/local/scripts :~# chmod 755 /usr/local/scripts

PHPコード例:

:~# vi /usr/local/scripts/send-logwatch.php

<?php require_once '/usr/local/lib/vendor/autoload.php'; use Brevo\Brevo; use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem; // logwatch のレポートを読み込む $report = file_get_contents('/var/log/logwatch-report.txt'); // Brevo API クライアント $client = new Brevo(apiKey: 'YOUR_BREVO_API_KEY'); // メール送信 $result = $client->transactionalEmails->sendTransacEmail( new SendTransacEmailRequest([ 'subject' => 'Daily Logwatch Report', 'htmlContent' => nl2br(htmlspecialchars($report)), 'sender' => new SendTransacEmailRequestSender([ 'name' => 'Server', 'email' => '[email protected]', ]), 'to' => [ new SendTransacEmailRequestToItem([ 'email' => '[email protected]', 'name' => 'Your Name', ]), ], ]) ); echo "Sent: " . $result->messageId . PHP_EOL;

毎日実行するように cron に登録例:

:~# crontab -e

0 7 * * * /usr/sbin/logwatch --output file --filename /var/log/logwatch-report.txt 5 7 * * * /usr/bin/php /usr/local/scripts/send-logwatch.php