LoginSignup
36
34

More than 5 years have passed since last update.

Amazon Linux AMI 2015.03でLAMP環境を作成する

Last updated at Posted at 2015-04-02

2015.03時点のyum packageの最新バージョンをインストールします

Amazon Linux のアップデート

# yum update -y

Apache 2.4

インストール

# yum install -y httpd24

起動

# service httpd start

MySQL 5.5

インストール

# yum install -y mysql55 mysql55-server

起動

# service mysqld start

セキュリティ設定 mysql_secure_installation コマンド実行

  1. プロンプトが表示されたら、root アカウントのパスワードを入力します。
  2. 現在の root パスワードを入力します。デフォルトでは、root アカウントにはパスワードが設定されていないので、Enter を押します。
  3. 「Y」と入力してパスワードを設定し、安全なパスワードを 2 回入力します。
  4. 「Y」と入力して匿名ユーザーアカウントを削除します。
  5. 「Y」と入力して root ログインを無効にします。
  6. 「Y」と入力してテストデータベースを削除します。
  7. 「Y」と入力して権限テーブルを再ロードし、変更を保存します。
# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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): 初回起動時はそのままENTER
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Change the root password? [Y/n] y
New password: 安全なパスワードを入力
Re-enter new password: 安全なパスワードを入力
Password updated successfully!
Reloading privilege tables..
 ... Success!

以下は全部 y を入力でいい

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

ここまで表示されればOK

PHP 5.6

インストール

php5.6

# yum install -y php56

その他モジュール等(各環境で必要な物を選択すると良いでしょう)

# yum install -y php56-dba php56-mbstring php56-mcrypt php56-opcache php56-pdo php56-tidy php56-mysqlnd php56-dbg

起動設定、ファイル設定

chkconfigで再起動時にhttpd,mysqldを立ち上げる

# chkconfig httpd on
# chkconfig mysqld on
# chkconfig iptables off
# chkconfig ip6tables off
確認
# chkconfig

ルートディレクトリ設定

  • www グループをインスタンスに追加し、そのグループに /var/www ディレクトリの所有権を与え、グループの書き込み許可を追加します。
  • www グループのメンバーがページを更新できます。
# groupadd www
# usermod -a -G www ec2-user
# chown -R root:www /var/www
# chmod 2775 /var/www
# find /var/www -type d -exec sudo chmod 2775 {} +
# find /var/www -type f -exec sudo chmod 0664 {} +

テストページ作成

$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

LAMP ウェブサーバーをテスト

テストURLにアクセスしてページ表示
http://ec2-XXX-XXX-XXX-XXX.ap-southeast-2.compute.amazonaws.com/phpinfo.php

36
34
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
36
34