MENU
やすひら
やすひらと申します。
長靴を履いたタヌキ(ITエンジニア)です。
モノ作りの楽しさを発信中。
X(旧Twitter)のフォローもお願いします。

[WordPress]LAMP環境の構築方法

WordPressに必要なソフトウェアである、LAMP環境の構築方法を紹介します。

やすひら

LAMP環境の構築方法を紹介します

この記事でわかること
  • LAMP環境とは
  • LAMP環境の構築方法
目次

LAMP環境とは

WordPressをインストールする前に、必要なソフトウェア準備する必要があります。
必要なソフトウェアは以下の4つで、頭文字をとってLAMP環境と言います。

  • Linux OS
  • apache
  • MySQL
  • PHP

Linux OSの構築方法

Linux OSの構築方法ですが、自前のサーバーとレンタルサーバーで構築方法が異なります。
自前のサーバーでは、isoイメージをダウンロードして外部媒体(USBメモリ等)に保存し、インストールさせる方法が一般的です。
レンタルサーバーでは、サーバーを立ち上げる際に、各レンタルサーバー会社のコンソールからOSを選択してインストールします。

apacheのインストール

apacheはhttp通信を行うためのアプリケーションです。

apacheのインストール

apacheのインストールは以下のコマンドを実行します。

コマンドライン

sudo apt install apache2

aptコマンドでapacheをインストールします。

apacheの起動

apacheを起動させるには以下のコマンドを実行します。

コマンドライン

sudo service apache2 start
sudo apachectl start

apacheを起動します。

apacheの動作確認

apacheを起動させたら、ブラウザで動作確認を行います。
ブラウザで以下のURLにアクセスして、応答があるか確認します。

URL

http://[IPアドレス]

ローカル環境で実行している場合は、localhostでアクセス可能です。
/var/www/html/index.html配下の内容がブラウザに表示され、apacheが起動できていることが確認できます。

MySQLのインストール

WordPressではデータベースを使用して、Webサーバー機能を提供しています。
データベースの一種であるMySQLのインストール方法を紹介します。

MySQLのインストール

MySQLのインストールは以下のコマンドを実行します。

コマンドライン

sudo apt install mysql-server

aptコマンドでMySQLをインストールします。

MySQLを再起動

インストールが完了したら、MySQLを再起動して状態を初期化します。

コマンドライン

systemctl restart mysql.service

MySQLを再起動します。

MySQLのパスワード設定

MySQLにはパスワード設定が可能なため、セキュリティ強化のためにパスワードを設定します。

MySQLに接続

MySQLに接続します。

コマンドライン

sudo mysql -u root

rootアカウントでMySQLに接続します。

パスワードを設定

次にrootアカウントにパスワードを設定します。

コマンドライン

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '[PASSWORD]';

[PASSWORD]は任意の値をパスワードに設定します。

セキュリティ設定

セキュリティ設定を行うためにmysql_secure_installationを実行します。
設定は対話形式で行います。筆者は全てyesで設定しました。

rootアカウントにパスワードが設定されていないとエラーが発生します。

コマンド実行例

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

MySQLのセキュリティを設定します。

PHPのインストール

WordPressではPHPを使用しているため、インストールする必要があります。
PHPを使用することで、動的にWebサーバーの内容を表示することが可能です。

PHPのインストール

PHPのインストールは以下のコマンドを実行します。

コマンドライン

sudo apt install php
sudo apt install php-mysql libapache2-mod-php php-gd php-mbstring php-xmlrpc php-zip

aptコマンドでPHP関連ソフトウェアをインストールします。

PHPの動作確認

PHPをインストールしたら、ブラウザで動作確認を行います。
/var/www/html配下にサンプルコードを作成して、 ブラウザで以下のURLにアクセスして、応答があるか確認します。

ソースコード

<html>
  <body>
    <?php echo "テスト"; ?>
  </body>
</html>

ソースコード

<?php phpinfo(); ?>

URL

http://[IPアドレス]/index.php
http://[IPアドレス]/info.php

ブラウザにPHPファイルの内容が表示され、PHPがインストールできていることが確認できます。

まとめ

WordPressで必要なLAMP環境の構築方法について紹介いたしました。

LAMP環境は
  • Linux OSをインストール
  • apachをインストール
  • MySQLをインストール
  • PHPをインストール

WordPressのインストールまでの準備が完了したら、WordPressをインストールします。

  • URLをコピーしました!
目次