6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Wordpress のインストール

Last updated at Posted at 2018-07-22

試してみたのでメモ。NginxとMySQLはインストール済みの状態です。

前提

次の手順を実施済みの前提とします。

手順

Wordpress用データベースの作成

  1. DBの管理者ユーザでMySQLにログインする

    # mysql -u root -p
    
  2. データベース用ユーザを作成する

    mysql> CREATE USER '<データベース用ユーザ名>'@'<ホスト名>' IDENTIFIED BY '<データベース用ユーザのパスワード>';
    Query OK, 0 rows affected (0.10 sec)
    
  3. 認証プラグインを旧バージョンに戻す (MySQL 8.0 の場合、これをやらないとデータベースに接続できない。詳細はリリースノートを参照)

    mysql> ALTER USER '<データベース用ユーザ名>'@'<ホスト名>' IDENTIFIED WITH mysql_native_password BY '<データベース用ユーザのパスワード>';
    Query OK, 0 rows affected (0.10 sec)
    
  4. データベースを作成する

    mysql> CREATE DATABASE <データベース名>;
    Query OK, 1 row affected (0.09 sec)
    
  5. 権限をつける

    mysql> GRANT ALL PRIVILEGES ON <データベース名>.* TO "<データベース用ユーザ名>"@"<ホスト名>" WITH GRANT OPTION;
    Query OK, 0 rows affected (0.05 sec)
    
  6. Flushしておく

    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    

Wordpressアプリケーションのインストール

  1. Wordpress用のディレクトリを作成し移動する

    # mkdir -p /var/www
    # cd /var/www/
    
  2. Wordpressのtar.gzファイルをダウンロードする

    # curl -LkvOf https://ja.wordpress.org/wordpress-5.0.3-ja.tar.gz
    
  3. 破損がないか確認する

    # md5sum wordpress-5.0.3-ja.tar.gz
    6200b504baf8ee0814e0c3e77677a0ea  wordpress-5.0.3-ja.tar.gz
    
  4. tar.gzファイルを展開する

    # tar -xzvf wordpress-5.0.3-ja.tar.gz
    
  5. tar.gzファイルを削除する

    # rm wordpress-5.0.3-ja.tar.gz
    

Wordpressの設定ファイルの修正

  1. Wordpress用に作成したディレクトリに移動する

    # cd /var/www/
    
  2. 雛形ファイルからwp-config.phpをコピーして作成する

    # cp wordpress/wp-config-sample.php wordpress/wp-config.php
    
  3. wp-config.phpファイルを修正する

    # vi wordpress/wp-config.php
    
    wordpress/wp-config.php
    // ** MySQL 設定 - この情報はホスティング先から入手してください。 ** 
    //
    /** WordPress のためのデータベース名 */
    define('DB_NAME', '<作成したデータベース名>');
    
    /** MySQL データベースのユーザー名 */
    define('DB_USER', '<作成したユーザ名>');
    
    /** MySQL データベースのパスワード */
    define('DB_PASSWORD', '<作成したユーザのパスワード>');
    
    /** MySQL のホスト名 */
    define('DB_HOST', 'localhost:/var/lib/mysql/mysql.sock');
    

Nginxの設定変更

  1. 設定ファイルを編集する

    # vi /etc/nginx/nginx.conf
    
    /etc/nginx/nginx.conf
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        server_tokens off; ←追加
    
        ...<中略>...
    
        include /etc/nginx/conf.d/wordpress.conf; ←編集
    }
    
    # vi /etc/nginx/conf.d/wordpress.conf
    
    /etc/nginx/conf.d/wordpress.conf
    server {
        listen       80;
        server_name  <ドメイン>;
        root   <wordpressの展開したディレクトリへのフルパス>;
        index index.php;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
    
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
    
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~* \.php$ {
            try_files $uri =404;
            fastcgi_index  index.php;
            fastcgi_pass   127.0.0.1:9000;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_hide_header X-Powered-By;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    
  2. 構文に間違いがないかを確認する

    # nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  3. Nginxを再起動する

    # systemctl restart nginx
    

Wordpressの設定

  1. http://<ドメイン>/wp-admin/install.phpにアクセスする

参考

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?