0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ラズパイ5 8GでWordpressとmastodonサーバーを立てる

Last updated at Posted at 2025-03-07

はじめに

昔、確かに仮想マシンでマストドンの公開サーバーをたてていたのですが
やめました

静かにブログしようかと思いはじめました

そこで、XPoster Share to Bluesky and Mastodonというプラグインを見つけましたので
いっそのこと同じサーバーにWordpressとマストドン(オレオレ用)を同居できないか試してみました

パワーもないが、インターネット回線の公平制御に引っかからないようにする目的でもbrotliも対応

マストドンも立てる理由

XPoster Share to Bluesky and Mastodonはマストドンに対して
1つのインスタントにしかトゥートできません
そのためオレオレインスタンスを立てて、複数のインスタンスに
記事を広告できるようにするためです

前提

Raspberry Pi 5 8G、もしくはRaspberry Pi 5 16G
最新のraspi-OSでugreenの2.5GBEが使用できるので、それを装着

Raspi-OS使用

sudo bash

でroot権限で直接操作

Wordpressに必要なもののインストール

apt install mariadb-server mariadb-client nginx wordpress libnginx-mod-http-brotli-filter php-fpm

ここでインストールしたWordpressは使いません。依存関係を簡潔にするためです
Apacheも勝手に入ってしまいますが使いません

しかし、これでは足りないとサイトヘルス等で叱られるので以下のものも入れます

apt install php8.2-mbstring php8.2-curl php8.2-dom php8.2-imagick php8.2-zip php8.2-intl

phpのバージョンにあわせてインストールしてください

nginx.conf

sites-available とか sites-enabled とか文字数長くて嫌いなので
vhosts ディレクトリから読み込むこととします

nginx.conf
# 頭に追加
include /etc/nginx/modules-enabled/*.conf;
worker_processes 3; # pagespeedでの最適値

# http のところに追加 gzipの下を奨励
        brotli on;
        #brotli_comp_level 11;
        brotli_comp_level 6;
        brotli_static on;
        brotli_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype     application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;

# 最後に追加
        include /etc/nginx/vhosts/*.conf;

vhosts/wordpress.example.com.conf

wordpress.example.com.conf
server {
        listen 80;
        server_name wordpress.example.com;
        index index.php ;
        root /home/www/wordpress.example.com/htdocs;

        location / {
                return 301 https://wordpress.example.com$request_uri;
        }
        location ~* /wp-config.php {
                deny all;
        }
        location ~ \.php$ {
                root                    /home/www/wordpress.example.com/htdocs;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include                 fastcgi_params;
        }

        location ^~/.well-known {
                alias /var/www/certbot/.well-known;
        }

}

server {
        listen 443 ssl;
        server_name wordpress.example.com;

        index index.php index.html;
        root /home/www/wordpress.example.com/htdocs;

        #ssl_certificate /etc/letsencrypt/live/wordpress.example.com/fullchain.pem;
        #ssl_certificate_key /etc/letsencrypt/live/wordpress.example.com/privkey.pem;
        #ssl_trusted_certificate /etc/letsencrypt/live/wordpress.example.com/fullchain.pem;

        location ~* /wp-config.php {
                deny all;
        }

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                include fastcgi.conf;
                fastcgi_pass   unix:/run/php/php8.2-fpm.sock;
        }
        location ~ /wp-login\.php|/wp-admin/((?!admin-ajax\.php).)*$ {
		# 自宅内だけで更新するのでこれで良い
                allow 192.168.0.11;
                allow 192.168.0.12;
                allow 192.168.0.13;
                allow 192.168.0.14;
                allow 192.168.0.15;
                allow 192.168.0.16;
                allow 192.168.0.17;
                allow 192.168.0.18;
                allow 192.168.0.19;
                deny all;
        }

        location ~ /wp-content/debug.log {
                deny all;
        }

        location ~* \.(css|gif|jpg|jpeg|js|png|webp|avif|ico|otf|sng|xlss|docx|exe|tgx)$ {
                access_log off;
                expires max;
        }
}

Wordpress用にDBを作成

systemctl enable mariadb
systemctl start mariadb
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

nginxとphp-fpmの起動

systemctl enable php8.2-fpm
systemctl start php8.2-fpm
systemctl enable nginx
systemctl start nginx

実際のWordpressをインストール

https://ja.wordpress.org/download/ より /home/www/htdocsにWordpressをセットアップ

mastodonのインストール

https://docs.joinmastodon.org/admin/install/
を参考にインストール

ただし

cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
rm /etc/nginx/sites-enabled/default

を実行せず

cp /home/mastodon/live/dist/nginx.conf /etc/nginx/vhosts/mastodon.example.com.conf

を実行する

swapリサイズ

ラズパイ5の8Gはx64の8Gよりも若干メモリが少なくて済みますが、
それでもメモリが足りなくなることがありますので、
以下のようにスワップを増やしましょう

ただし、最大サイズは2048です

dphys-swapfile swapoff
nano /etc/dphys-swapfile
dphys-swapfile setup
dphys-swapfile swapon

さいごに

実際に同じラズパイ5で立ってる様子です

インストールしたマストドンは誰でも入れるインスタンスには向きません
オレオレサーバーとして使用しましょう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?