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
apacheの起動
apacheを起動させるには以下のコマンドを実行します。
コマンドライン
sudo service apache2 start
sudo apachectl start
apacheの動作確認
apacheを起動させたら、ブラウザで動作確認を行います。
ブラウザで以下のURLにアクセスして、応答があるか確認します。
URL
http://[IPアドレス]
MySQLのインストール
WordPressではデータベースを使用して、Webサーバー機能を提供しています。
データベースの一種であるMySQLのインストール方法を紹介します。
MySQLのインストール
MySQLのインストールは以下のコマンドを実行します。
コマンドライン
sudo apt install mysql-server
MySQLを再起動
インストールが完了したら、MySQLを再起動して状態を初期化します。
コマンドライン
systemctl restart mysql.service
MySQLのパスワード設定
MySQLにはパスワード設定が可能なため、セキュリティ強化のためにパスワードを設定します。
MySQLに接続
MySQLに接続します。
コマンドライン
sudo mysql -u root
パスワードを設定
次にrootアカウントにパスワードを設定します。
コマンドライン
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '[PASSWORD]';
セキュリティ設定
セキュリティ設定を行うためにmysql_secure_installationを実行します。
設定は対話形式で行います。筆者は全てyesで設定しました。
コマンド実行例
$ 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!
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
PHPの動作確認
PHPをインストールしたら、ブラウザで動作確認を行います。
/var/www/html配下にサンプルコードを作成して、 ブラウザで以下のURLにアクセスして、応答があるか確認します。
ソースコード
<html>
<body>
<?php echo "テスト"; ?>
</body>
</html>
ソースコード
<?php phpinfo(); ?>
URL
http://[IPアドレス]/index.php
http://[IPアドレス]/info.php
まとめ
WordPressで必要なLAMP環境の構築方法について紹介いたしました。
- Linux OSをインストール
- apachをインストール
- MySQLをインストール
- PHPをインストール
WordPressのインストールまでの準備が完了したら、WordPressをインストールします。