はじめに
Nginxとphp-fpmとMariaDBが可動するホスト上でWordpressが動作するようにセットアップします。
Nginxインストール
こちらの投稿を参照して下さい。
php-fpmインストール
こちらの投稿を参照して下さい。
MariaDBインストール
こちらの投稿を参照して下さい。
WordPressデプロイ
公式サイトから最新のWordpressパッケージをダウンロードしてインストール、初期設定まで実施します。
コンテンツ管理用ユーザー追加
WordPressはphp-fpm上で動作しますが、ユーザーはnginxとなります。ここで、php-fpmがnginxユーザーとは別にnginxグループに属するユーザーを作成して、人がファイルを操作するときはこのユーザーを使うようにします。
$ sudo useradd -g nginx app-user
$ sudo bash -c "echo umask 0002 >> /home/app-user/.bashrc"
$ sudo su - app-user
パッケージダウンロード
$ mkdir -p ~/src
$ cd ~/src
$ curl -L https://wordpress.org/latest.tar.gz \
-o wordpress.tar.gz
パッケージデプロイ
$ tar fx wordpress.tar.gz
$ sudo mv wordpress /var/www/.
$ sudo chown -R nginx:nginx /var/www/wordpress
$ sudo chmod -R g+w /var/www/wordpress
WordPress初期設定(1)
WordPress用のデータベース、ユーザー、アクセス権限をDBサーバーに設定します。データベース名、ユーザー名、データベースユーザーパスワードは今回は簡単のためそれぞれ「wp_database」、「wp_username」、「wp_password」とします。
$ mysql -u root
(データベース作成)
> CREATE DATABASE wp_database;
(データベースユーザー作成)
> CREATE USER wp_username@'localhost' IDENTIFIED BY 'wp_password';
(データベースに対するユーザーのアクセス権限付与)
> GRANT ALL PRIVILEGES ON wp_database.* TO wp_username@'localhost';
(適用とmysqlコマンド終了)
> QUIT;
WordPress初期設定(2)
まず、Wordpress用のデータベース名、ユーザー名、データベースユーザーパスワードを入力します。
次にWordPressが使う、そのWordPress固有のシークレットを取得します。wp-config-sambple.phpの中にも記述がありますが(外部サイト)こちらのサイトにアクセスすれば簡単にシークレットを生成できます。
上記2つをwp-config.phpとして設定します。
$ cd /var/www/wordpress/
$ sudo -u nginx cp wp-config-sample.php /var/www/wordpress/wp-config.php
$ sudo -u nginx vi wp-config.php
/var/www/wordpress/wp-config.php
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wp_database');
/** MySQL database username */
define('DB_USER', 'wp_username');
/** MySQL database password */
define('DB_PASSWORD', 'wp_password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567890');
define('SECURE_AUTH_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567891');
define('LOGGED_IN_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567892');
define('NONCE_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567893');
define('AUTH_SALT', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567894');
define('SECURE_AUTH_SALT', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567895');
define('LOGGED_IN_SALT', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567896');
define('NONCE_SALT', 'ABCDEFGHIJKLMNOPQRSTUVWXYXZabcdefghijklmnopqrstuvwxyz01234567897');
/**#@-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the Codex.
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
WordPressセットアップ画面表示
ここまでくれば、あとはWordPressの管理画面にアクセスできるようになります。http://localhost/ でWordPressが表示されるか確認してみてください。
「WordPress簡単インストール」への1件の返信
[…] 今回、既存のphp56からphp73へアップブレードする方法を紹介します。尚、WordPress稼働環境はAmazonEC2 AmazonLinux、Nginx、PHP-FPM(FastCGI)、MariaDBとします。詳しい構築手順はこちらの投稿を参照してください。今回紹介する手順はサービス停止が発生します。サービス停止が許容できない場合は、別途EC2インスタンスを用意(このEC2インスタンスのスナップショットを取得、スナップショットから別のEC2インスタンスとして起動する、など)して対応してください。 […]