0
0

More than 1 year has passed since last update.

WordPressの構築手順

Posted at

前提条件

Nginx設定、WordPress構築の手順です。

前提条件はNginx、PHP、MariaDBをインストール済のUbuntu環境です。詳しくは「Nginx、PHP、MariaDBの構築手順」を参照してくださいませ。

環境

  • OS Ubuntu 22.04 LTS
  • Nginx 80443の管理
  • PHP Webアプリケーションの開発を得意とするプログラミング言語
  • MariaDB データーベース
  • WordPress ホームページ

作業

1. 必要環境確認

1.1 Nginxのインストール状況

$ nginx -vコマンドで確認

# 下記の様にバージョン番が出てくる →  Nginxインストール済確定
nginx version: nginx/1.18.0 (Ubuntu)

1.2 PHPのインストール状況

$ php -vコマンドで確認

# 下記の様にバージョン番が出てくる → PHPインストール済確定
PHP 8.1.2-1ubuntu2.9 (cli) (built: Oct 19 2022 14:58:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.9, Copyright (c), by Zend Technologies

1.3 MariaDBのインストール状況

$ mysql --versionコマンドで確認

# 下記の様にバージョン番が出てくる → MariaDBインストール済確定
mysql  Ver 15.1 Distrib 10.6.11-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

2. WordPress構築

2.1 WordPresssデータベースの作成と設定

  1. 空のデータベース作成

    まずはrootでMariaDBにログインする

    $ sudo mysql -u root -p

  2. データベースを作成します。データベース名はwordpress とする

    > CREATE DATABASE wordpress;
    
  3. 次にユーザーの作成と、パスワードの設定を行う

    > CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
    
  4. 作成したユーザーに全てのアクセス権を与える

    > GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' WITH GRANT OPTION;
    
  5. これまでの変更を保存し、MariaDBを抜ける

    > FLUSH PRIVILEGES;
    > EXIT;
    

2.2 WordPresssファイルをダウンロードする

  1. 先ずtmpディレクトリへ移動して

    $ cd /tmp

  2. 最新のWordPressをダウンロードする

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

  3. ファイルを解凍する

    $ tar -xvzf latest.tar.gz

  4. tmpディレクトリから、/var/www/wordpress/へダウンロードしたwordpressファイルの移動

    $ sudo mv wordpress /var/www/

  5. www-dataにwordpressディレクトリへの権限を与える

    $ sudo chown -R www-data:www-data /var/www/wordpress/

  6. wordpressディレクトリの権限変更(rwx,rx,rx

    $ sudo chmod -R 755 /var/www/wordpress/

2.3 Nginxの設定

  1. wordpress.conf を作成し設定を追加する

    $ sudo vim /etc/nginx/sites-available/wordpress.conf

    server {
        listen 80;
        listen [::]:80;
        root /var/www/wordpress;
        index  index.php index.html index.htm;
        server_name sample.com www.sample.com;
    
        client_max_body_size 100M;
        autoindex off;
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
             include snippets/fastcgi-php.conf;
             fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
        }
    }
    
  2. シンボリックファイルを貼る

    $ sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/

  3. Nginxを再起動する

    sudo systemctl restart nginx

2.4 WordPressの初期設定

  • ドメインを入力しブラウザで確認する
  • 画面の指示を従って操作する
    • データーベース名

      手順2.1の2に設定した wordpress

    • データーベースのユーザー名

      手順2.1の3に設定した wordpressuser

    • データーベースのパスワード

      手順2.1の3に設定した yourpassword

    • データーベースホスト

      ディフォルト localhost

    • テーブル接頭辞

      ディフォルト wp_

WordPress構築の手順は以上です。

お疲れ様でした。

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