2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AlmaLinux9でMediaWikiサーバを構築

Last updated at Posted at 2025-06-12

はじめに

 私自身の行った作業をまとめたものになります。
 初投稿のため、至らない点が多々ある記事かと思いますが、コメントにてそれらご教示いただけますと幸いです。
 本記事では、AlmaLinuxを使用して、開発・検証用のMediaWikiサーバを構築する方法について記載いたします。サーバ構築がゴールなので、MediaWiki自体の操作方法に関してはあまり触れません。ご了承ください。

環境

AlmaLinux 9.1 ※投稿主はVirtual Boxを用いた仮想環境上で検証を行っております。
Apache 2.4.62
MySQL 8.0.41
PHP 8.1
MediaWiki 1.43.1

LAMP環境の構築

コマンド実行時は適宜rootユーザーで操作を行う、もしくは sudo も同時に用いるなどしてください。

Apacheのインストール

 標準リポジトリからApacheをインストールします。

shell
[username@localhost ~]# sudo dnf install httpd

 http.confファイルの設定を下記の通り変更します。

httpd.conf
(省略)

<IfModule dir_module>
    DirectoryIndex index.php index.html     <-- index.phpという文言を追加
</IfModule>

(省略)

# Further relax access to the default document root:
<Directory "/var/www/html">
    
    #Options Indexes FollowSymLinks  <-- コメントアウト
    Options FollowSymLinks  <-- 「Indexes」を削除

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None  <-- コメントアウト
    AllowOverride ALL   <-- 「ALL」に変更

    Require all granted
</Directory>

(省略)

 Rewriteモジュールの状態を確認します。下記のコマンドを入力して、結果が同様であれば問題ありません。

shell
[username@localhost ~]# httpd -M | grep rewrite
 rewrite_module (shared)

PHPのインストール

 PHP 8.1は、標準リポジトリでは提供されていないためEPELリポジトリ、Remiリポジトリを使用して、PHP 8.1のインストールを行います。

EPELリポジトリとRemiリポジトリは、Red Hat社にサポートされていないリポジトリです。そのため自己責任の元で利用する必要がある点に注意してください。

 各リポジトリを追加します。

shell
[username@localhost ~]# sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
[username@localhost ~]# sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

 インストールするPHPのバージョンを指定します。

shell
[username@localhost ~]# sudo dnf module -y reset php 
[username@localhost ~]# sudo dnf module -y enable php:remi-8.1

 PHPをインストールします。

shell
[username@localhost ~]# sudo dnf install php

 MediaWikiに必要なPHPのモジュールをインストールします。

shell
[username@localhost ~]# sudo dnf install libcurl libxml2 libexif.x86_64 pcre zip ImageMagick
[username@localhost ~]# sudo dnf install php-mbstring php-bcmath php-xml php-json php-gd php-composer-pcre php-pecl-zip  php-pecl-quickhash php-pecl-imagick php-intl php-apcu
[username@localhost ~]# sudo dnf install php-mysqlnd
[username@localhost ~]# sudo dnf install php-fpm

 「/etc/php.ini」ファイルを以下のとおり変更します。

php.ini

[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; https://php.net/mbstring.language
mbstring.language = Japanese  <-- Japaneseに設定

; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 128M  <-- 128MBに設定

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
;post_max_size = 8M
post_max_size = 40M  <-- 40MBに設定

; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
;upload_max_filesize = 2M
upload_max_filesize = 30M  <-- 30MBに設定

MySQLのインストール

 MySQLをインストールします。

shell
[username@localhost ~]# sudo dnf install mysql-server mysql

 MySQLサーバを起動します。

shell
[username@localhost ~]# sudo systemctl start mysqld

 MySQLサーバの初期設定を行います。下記の通りコマンドを実行します。

shell
[username@localhost ~]# mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:  <-- [Enter]を押下
Please set the password for root here.

New password:  <-- MySQLのrootのパスワードを入力

Re-enter new password:   <-- MySQLのrootパスワードを再入力
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y  <-- 「y」を入力
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? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
 - 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? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
Success.

All done!

MediaWikiのインストール

 公式ホームページから最新バージョンのMediaWikiパッケージをダウンロードします。

shell
[username@localhost ~]# sudo wget https://releases.wikimedia.org/mediawiki/1.43/mediawiki-1.43.1.tar.gz

 ダウンロードしたファイルを解凍します。

shell
[username@localhost ~]# sudo tar zxvf mediawiki-1.43.1.tar.gz

 解凍したMediaWikiのファイルをアップロードします。

shell
[username@localhost ~]# sudo cp -R ./mediawiki-1.43.1/* /var/www/html/

 アップロードしたMediaWikiのファイルに権限を付与します。また、ディレクトリのパーミッションも設定します。

shell
[username@localhost ~]# sudo chown -R apache:apache /var/www/html/
[username@localhost ~]# sudo find /var/www/html -type d -exec chmod 755 {} \;
[username@localhost ~]# sudo find /var/www/html -type f -exec chmod 644 {} \;

 MediaWiki用のデータベースおよびユーザーを作成します。

shell
[username@localhost ~]# mysql -u root -p
Enter password:          <-- 先ほど設定したパスワードを入力
MySQL
CREATE DATABASE my_wiki;
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'database_password';
GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit

MediaWikiの初期設定

 最初にApacheを起動しておきます。

shell
[username@localhost ~]# sudo systemctl start httpd

 http://IPアドレス/mediawiki-1.43.1/をWebブラウザの検索バーに入力してアクセスします。「IPアドレス」の部分にはサーバPCのIPアドレスを入力します。IPアドレスが分からない場合は、ip aのコマンドで確認することができます。
 正しく設定できていれば、「Please set up the wiki first.」というリンクが表示されるはずです。こちらをクリックして、初期設定を進めていきます。

  • 「あなたの言語」「ウィキの言語」はそれぞれ日本語でかまいません
  • データベースの設定について
    • 一番上の項目は「localhost」にします
    • 先ほどMySQLで作成したデータベースの情報を入力します
    • 「データベーステーブルの接頭辞」は「wiki_」にしておきます
  • ウィキ名、管理者名、パスワード、メールアドレスを適宜設定します
  • オプションの設定について
    • 「スキン」の項目でどれか1つを規定値として選ばないと次に進めないので、Vectorを選びます
    • 「エディター」の項目でWikiEditorを選択しておくことをオススメします

作成した設定用ファイルの移動

 先程の作業を完了すると、自動でLocalSettings.phpというファイルがダウンロードされます。このファイルをアップロードして、権限を付与します。

shell
[username@localhost ~]# sudo mv Downloads/LocalSettings.php /var/www/html/
[username@localhost ~]# sudo chown apache:apache /var/www/html/LocalSettings.php
[username@localhost ~]# sudo chmod 640 /var/www/html/LocalSettings.php

 以上でMediaWikiのインストールは完了です。

MediaWikiにログインする

 http://IPアドレス/index.phpにアクセスすると、MediaWikiのログイン画面が表示されるはずです。設定した管理者アカウントのユーザー名とパスワードを入力しましょう。

参考文献

下記のWordPressサーバ構築に関するサイトを参考にさせていただきました。
AlmaLinuxでWordPressサーバを構築 - Ingenious
(最終閲覧日:2025年6月13日)
また、下記のMediaWiki公式ドキュメントも参考にしました。
ダウンロード - MediaWiki
(最終更新日:2025年6月13日)

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?