マイウィキ

ペコネットウィキサイト

ユーザ用ツール

サイト用ツール


ubuntu:server:wordpress

文書の過去の版を表示しています。


WordPressサイトの作成

ローカルサーバー(Apache + PHP + MariaDB)上にWordPressサイトを設置してセットアップします。


はじめに(設定環境)

WordPressのダウンロードと展開

日本語版WordPressの最新版を公式サイトからダウンロードします。

$ wget https://ja.wordpress.org/latest-ja.tar.gz

ダウンロードしたアーカイブを展開します。カレントディレクトリ(ここではホームディレクトリ `/home/peconet/`)に `wordpress` ディレクトリが作成されます。

$ tar xvfz latest-ja.tar.gz

展開した `/home/peconet/wordpress/` を `/var/www/` 配下へ移動し、ここではディレクトリ名を `peconet.localsite` とします。
移動と同時にドキュメントルート名 `peconet.localsite` にリネームします。

$ sudo mv /home/peconet/wordpress/ /var/www/peconet.localsite/

設定ファイルの作成と編集

デフォルトのVirtualHost設定ファイルをコピーして、新しいサイト用の設定ファイルを作成します。

$ cd /etc/apache2/sites-available/
$ sudo cp 000-default.conf peconet.localsite.conf

設定ファイルの編集

$ sudo vim peconet.localsite.conf

設定ファイルが開きます。行頭に `#` が付いている行はコメントアウト(無効化)されている項目です。

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

無効化されている `#ServerName` の `#` を外して `peconet.localsite` を指定し、`DocumentRoot` を `/var/www/peconet.localsite` に変更します。

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName peconet.localsite

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/peconet.localsite

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

編集後、保存して閉じます。

サイトの有効化

設定ファイルの有効化

$ sudo a2ensite peconet.localsite.conf

ドキュメントルートの所有ユーザー・グループの変更

$ sudo chown -R www-data:www-data /var/www/peconet.localsite

ドキュメントルートのパーミッションの変更

$ sudo chmod -R 775 /var/www/peconet.localsite

※環境や運用方針に応じて、ディレクトリは `775`(または `755`)、ファイルは `664`(または `644`)に整理するとより安全です。

ユーザー「peconet」をwww-dataグループに追加

$ sudo usermod -aG www-data peconet

※グループ追加を現在のセッションに反映させるには、一度ログアウトして再ログインしてください。

Rewriteモジュールの有効化と「.htaccess」の有効化

パーマリンク設定の変更やリダイレクト利用などのため、`rewrite` モジュールおよびドキュメントルートでの `.htaccess`(`AllowOverride All`)を有効化します。

Rewriteモジュールの有効化

$ sudo a2enmod rewrite

「.htaccess」の有効化

先ほどの `/etc/apache2/sites-available/peconet.localsite.conf` を再度開き、`<Directory /var/www/peconet.localsite>` ブロックを追記します。

<Directory /var/www/peconet.localsite>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

追記後のイメージは次のようになります。

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName peconet.localsite

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/peconet.localsite

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        
        <Directory /var/www/peconet.localsite>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
        
</VirtualHost>

設定の構文確認とApacheの再起動を行います(Windows側の `hosts` ファイルに `192.168.3.10 peconet.localsite` が設定済みであることもあわせて確認してください)。

$ sudo apache2ctl configtest
$ sudo systemctl restart apache2

WordPressのインストール

ブラウザから `http://peconet.localsite/` にアクセスして、WordPressの初期セットアップ画面からインストールを進めます。

データベースの作成 で作成したデータベース接続情報を入力します。

  • データベース名:`DB_peconet`
  • ユーザー名:`peconet`
  • パスワード:`aaa`
  • データベースのホスト名:`localhost`(デフォルトのまま)
  • テーブル接頭辞:`wp_`(デフォルトのまま)

入力を終えたら「送信」をクリックし、データベース接続が確認できたら「インストール実行」へ進みます。

続いてサイト情報や管理者アカウントを設定します(ここで設定するユーザー名・パスワードはWordPress管理画面のログインに必要です)。

  • サイトのタイトル:(任意)
  • ユーザー名:(任意)
  • パスワード:(任意・控えておく)
  • メールアドレス:(任意)
  • 検索エンジンでの表示:(任意)

入力を終えたら「WordPressをインストール」をクリックします。

インストール完了画面が表示されたら「ログイン」をクリックし、設定したユーザー名とパスワードでログインして管理画面(`/wp-admin/`)へ進みます。

関連項目

ubuntu/server/wordpress.1795468384.txt.gz · 最終更新: by peconet

ページの先頭へ