GNU/Linux >> Linux の 問題 >  >> Ubuntu

Nginxを使用してMediaWikiをインストールし、Ubuntu20.04でSSLを暗号化する方法

MediaWikiは、PHPで記述されたオープンソースのウィキソフトウェアです。これにより、サーバー上に独自のセルフホストWikiWebサイトを作成できます。シンプルさとカスタマイズ性により、最も人気のあるwikiプラットフォームの1つです。現在、多くの企業がwikiページを管理するために使用しています。インターネット上でコンテンツを公開するための多目的で無料のツールを提供します。

このチュートリアルでは、NginxWebサーバーを使用してMediaWikiをインストールする方法とUbuntu20.04にSSLを暗号化する方法を示します。

前提条件
  • Ubuntu20.04を実行しているサーバー。
  • サーバーIPで指定された有効なドメイン名。
  • ルートパスワードはサーバーで構成されています。
はじめに

まず、次のコマンドを実行して、システムパッケージを更新されたバージョンに更新します。

apt-get update -y

すべてのパッケージが更新されたら、次のステップに進むことができます。

Nginx、MariaDB、PHPをインストール

MediaWikiには、Nginx Webサーバー、MariaDBデータベースサーバー、PHP、およびその他の拡張機能が必要です。次のコマンドですべてをインストールできます:

apt-get install nginx mariadb-server php php-fpm php-mbstring php-xml php-json php-mysql php-curl php-intl php-gd php-mbstring texlive imagemagick unzip -y

すべてのパッケージがインストールされたら、次のコマンドを使用してComposerをインストールします。

apt-get install composer -y

次に、php.iniファイルを編集し、デフォルト設定を変更します。

nano /etc/php/7.4/fpm/php.ini

次の行を変更します:

memory_limit = 512M
post_max_size =32M
upload_max_filesize = 32M
date.timezone = Asia/Kolkata

ファイルを保存して閉じてから、PHP-FPMを再起動して変更を適用します。

systemctl restart php7.4-fpm

終了したら、次のステップに進むことができます。

MariaDBデータベースを作成する

MediaWikiはMariaDBをデータベースバックエンドとして使用するため、MediaWikiのデータベースとユーザーを作成する必要があります。

まず、次のコマンドを使用してMariaDBに接続します。

mysql

接続したら、次のコマンドを使用してデータベースとユーザーを作成します。

MariaDB [(none)]> CREATE DATABASE mediadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mediadb.* TO 'mediauser'@'localhost' IDENTIFIED BY 'password';

次に、特権をフラッシュし、次のコマンドでMariaDBを終了します。

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

終了したら、次のステップに進むことができます。

MediaWikiをダウンロード

初め。 MediaWikiのWebサイトにアクセスして、MediaWikiの最新バージョンを選択します。次に、次のコマンドを実行してサーバーにダウンロードします。

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip

ダウンロードが完了したら、次のコマンドを使用してダウンロードしたファイルを解凍します。

unzip mediawiki-1.35.2.zip

次に、次のコマンドを使用して、抽出したディレクトリをNginxWebルートディレクトリに移動します。

mv mediawiki-1.35.2 /var/www/html/mediawiki

次に、ディレクトリをMediaWikiに変更し、次のコマンドを使用してすべてのPHP依存関係をインストールします。

cd /var/www/html/mediawiki
composer install --no-dev

すべての依存関係がインストールされたら、次のコマンドを使用して適切な権限と所有権を設定します。

chown -R www-data:www-data /var/www/html/mediawiki
chmod -R 755 /var/www/html/mediawiki

終了したら、次のステップに進むことができます。

MediaWiki用にNginxを構成する

次に、MediaWiki用のNginx仮想ホスト構成ファイルを作成する必要があります。次のコマンドで作成できます:

nano /etc/nginx/conf.d/wiki.conf

次の行を追加します:

server {
        listen 80;
        server_name wiki.example.com;

        root /var/www/html/mediawiki;
        index index.php;
   
        error_log /var/log/nginx/mediawiki.error;
        access_log /var/log/nginx/mediawiki.access;

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


        location ~ /\.ht {
          deny all;
         }

        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include snippets/fastcgi-php.conf;
        }
}

ファイルを保存して閉じ、次のコマンドを使用して構文エラーがないかNginxを確認します。

nginx -t

次の出力が表示されます。

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

次に、Nginxサービスを再起動して、変更を適用します。

systemctl restart nginx

次のコマンドを使用して、Nginxのステータスを確認することもできます。

systemctl status nginx

次の出力が表示されます。

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-06-02 05:06:48 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 24594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24605 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24606 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.8M
     CGroup: /system.slice/nginx.service
             ??24606 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??24607 nginx: worker process

Jun 02 05:06:48 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 02 05:06:48 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server.

MediaWikiWebUIにアクセス

次に、Webブラウザーを開き、URL http://wiki.example.comを入力します。 。次のページにリダイレクトされます:

次に、ウィキの設定をクリックします。 ボタン。次のページが表示されます:

ここで、Wiki言語を選択し、続行をクリックします。 ボタン。次のページが表示されます:

次に、続行をクリックします ボタン。次のページが表示されます:

次に、データベースの詳細を入力して、続行をクリックします。 ボタン。次のページが表示されます:

インストールと同じアカウントを使用するを選択し、続行をクリックします ボタン。次のページが表示されます:

次に、Wikiサイト名、ユーザー名、およびパスワードを入力します。次に、続行をクリックします ボタン。次のページが表示されます:

続行をクリックします ボタンをクリックしてインストールを開始します。次のページが表示されます:

続行をクリックします ボタン。インストールが完了すると、次のページが表示されます。

次に、ダウンロードボタンをクリックして、 LocalSettings.phpをダウンロードします。 システムにファイルします。次に、このファイルをMediaWikiルートディレクトリ内のサーバーにコピーし、次のコマンドを使用して適切な権限を設定します。

chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php

次に、Webブラウザに戻り、ウィキを入力をクリックします。 。次のページにMediaWikiダッシュボードが表示されます:

SSLを暗号化しようで安全なMediaWiki

次に、Certbotクライアントパッケージをインストールして、Let'sEncryptSSLの管理をインストールする必要があります。

まず、次のコマンドを使用してCertbotをインストールします。

apt-get install python3-certbot-nginx -y

インストールが完了したら、次のコマンドを実行してLet'sEncryptSSLをWebサイトにインストールします。

certbot --nginx -d wiki.example.com

以下に示すように、有効なメールアドレスを入力し、利用規約に同意するよう求められます。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for wiki.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/wiki.conf

次に、以下に示すように、HTTPトラフィックをHTTPSにリダイレクトするかどうかを選択します。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2と入力し、Enterキーを押してインストールを終了します。次の出力が表示されます。

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/wiki.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://wiki.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=wiki.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wiki.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wiki.example.com/privkey.pem
   Your cert will expire on 2021-12-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

これで、WebサイトはLet'sEncryptSSLで保護されます。 URLhttps://wiki.example.com。を使用して安全にアクセスできます

結論

おめでとう!これで、Ubuntu20.04にNginxとLet'sEncryptSSLを使用してMediaWikiが正常にインストールされました。 MediaWikiを使用して独自のWikiサイトを簡単にホストできるようになりました。


Ubuntu
  1. Nginxを使用してNextcloudをインストールし、Ubuntu20.04LTSでSSLを暗号化する方法

  2. Nginxを使用してMagento2をインストールし、Ubuntu20.04LTSでSSLを暗号化する方法

  3. Ubuntu16.04にNginxでMediaWikiをインストールする方法

  1. Ubuntu 15.10にNginx、PHP-FPM、SSLを使用してDrupal8をインストールする方法

  2. Ubuntu15.10にNginxとSSLを使用してOpenCart2をインストールする方法

  3. NGINXを使用してShopwareをインストールし、Ubuntu18.04LTSで暗号化する方法

  1. Nginxを使用してAutomadCMSをインストールし、Ubuntu18.04でSSLを暗号化できるようにします

  2. Nginxを使用してX-Cartをインストールし、Ubuntu18.04LTSでSSLを暗号化する方法

  3. Nginxを使用してDrupalをインストールし、Ubuntu20.04LTSでSSLを暗号化する方法