12/24深夜のLAMP + Wordpressを構築した時の手順。 ※1.rootユーザーでの作業を前提とした手順です。必要に応じて、suやsudoでのコマンド実行をお願いします。 ※2.途中に出てくる斜体の箇所は、画面上に勝手に出てくる文字列です。
LAMP環境構築
Apache HTTPDのインストール
yum install -y httpd
Firewall ポート開放 → http通信を許可
firewall-cmd --permanent --add-service=http
Firewall 再起動 → 設定変更を反映させるのに再起動が必要
firewall-cmd --reload
## SELinux 無効化 → あんまりよろしくないのでセキュアなNWでのみ実行推奨
setenforce 0
→ 勉強会の環境では不要な手順になったため削除。個人の環境では必要に応じて実施してください。
Apache 起動 → 起動してあげないと動かないです
systemctl start httpd
MariaDBインストール
yum install -y mariadb-server
MariaDB起動
systemctl start mariadb
MariaDB セキュリティ設定
mysql_secure_installation
*NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! *
*In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. *
*Enter current password for root (enter for none): * *OK, successfully used password, moving on... *
*Setting the root password ensures that nobody can log into the MariaDB * *root user without the proper authorisation. *
Set root password? [Y/n] y New password: 好きなパスワードを入力 *Re-enter new password:*再度同じパスワードを入力 Password updated successfully! *Reloading privilege tables.. * *... Success! *
*By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. *
Remove anonymous users? [Y/n] y *... Success! *
*Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. *
Disallow root login remotely? [Y/n] y *... Success! *
*By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. *
Remove test database and access to it? [Y/n] y *- Dropping test database... * *... Success! * *- Removing privileges on test database... * *... Success! *
*Reloading the privilege tables will ensure that all changes made so far will take effect immediately. *
Reload privilege tables now? [Y/n] y *... Success! *
*Cleaning up... *
*All done! If you've completed all of the above steps, your MariaDB installation should now be secure. *
Thanks for using MariaDB!
PHPインストール(プログラムの実行環境)
yum install -y php php-mysql
WordPress用DB作成
DBへの接続
mysql -u root -p *Enter password:*さっき決めたパスワードを入力 *Welcome to the MariaDB monitor. Commands end with ; or \g. * *Your MariaDB connection id is 10 * *Server version: 5.5.56-MariaDB MariaDB Server *
*Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. *
*Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. *
*MariaDB [(none)]> *
テーブル作成
mysql> CREATE DATABASE wpdb; *Query OK, 1 row affected (0.00 sec) *
mysql> GRANT ALL PRIVILEGES ON wpdb.* TO "wpuser"@"localhost" IDENTIFIED BY "好きなパスワード"; *Query OK, 0 rows affected (0.00 sec) *
mysql> FLUSH PRIVILEGES; *Query OK, 0 rows affected (0.01 sec) *
mysql> exit
wgetインストール(パッケージダウンロード用ツール)
yum install -y wget
WordPressのダウンロード
wget https://ja.wordpress.org/latest-ja.tar.gz
WordPressの解凍
tar zxvf latest-ja.tar.gz
WordPressをWeb公開用ディレクトリへ移動
mv wordpress/* /var/www/html/
WordPressのアクセス権変更
chown -R apache.apache /var/www/html*
wp-config.php の作成
cd /var/www/html cp -p wp-config-sample.php wp-config.php
wp-config.phpの編集
vi wp-config.php
※「i」を入力して、編集モードへ切り替えてから以降の通りに編集※
ファイルの中ほどにあるDBへの接続設定を変更します
// MySQL 設定 - この情報はホスティング先から入手してください。 // / WordPress のためのデータベース名 */ define('DB_NAME', 'wpdb');
/ MySQL データベースのユーザー名 */ define('DB_USER', 'wpuser');
/ MySQL データベースのパスワード */ define('DB_PASSWORD', '<任意のパスワード>');
/ MySQL のホスト名 */ define('DB_HOST', 'localhost');
末尾に↓を追記します
_SERVER['HTTP_X_FORWARDED_HOST']; _SERVER['HTTP_X_FORWARDED_FOR'];
※編集が終わったら、Escキー押下 → 「ZZ」と入力※
##動作確認 ###起動したサーバーのIPアドレスを確認 ip addr show
ブラウザを開いて、ブラウザバーに確認したIPアドレスを入力 Wordpressのデフォルトページが表示されれば完了!