サーバー環境

Aws EC2 Apache + Mysql + php7 構築の記録

アマゾンに無料枠を使い Apache + Mysql + php7 をインストールした時のメモです。

インストールするLinuxサーバー  AWS アカウント作成のながれ Apache2.4 MySQL5.6 PHP7.1 MySQLドライバのインストール

#1 yum にて Linuxを最新に更新

$ sudo yum -y update

#2 Amazon linux バージョン確認 

$ cat /etc/system-release
Amazon Linux AMI release 2017.09

#3 Apache、MySQL、PHP、MySQLドライバのインストール

$sudo yum install -y php71 php71-devel php71-fpm php71-mysql php71-mysqlnd php71-mbstring php71-pdo php71-xml php71-zip httpd24 mysql56-server php71-mysqlnd

・ ・

Installed:
httpd24.x86_64 0:2.4.27-3.75.amzn1
mysql56-server.x86_64 0:5.6.38-1.27.amzn1
php71.x86_64 0:7.1.13-1.30.amzn1
php71-mysqlnd.x86_64 0:7.1.13-1.30.amzn1
php71-devel.x86_64 0:7.1.13-1.30.amzn1
php71-fpm.x86_64 0:7.1.13-1.30.amzn1
php71-mbstring.x86_64 0:7.1.13-1.30.amzn1

Dependency Installed:
apr.x86_64 0:1.5.2-5.13.amzn1
apr-util.x86_64 0:1.5.4-6.18.amzn1
httpd24-tools.x86_64 0:2.4.27-3.75.amzn1
mysql-config.x86_64 0:5.5.58-1.19.amzn1
mysql56.x86_64 0:5.6.38-1.27.amzn1
mysql56-common.x86_64 0:5.6.38-1.27.amzn1
mysql56-errmsg.x86_64 0:5.6.38-1.27.amzn1
mysql56-libs.x86_64 0:5.6.38-1.27.amzn1
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.11.amzn1
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.1.amzn1
perl-DBD-MySQL56.x86_64 0:4.023-5.21.amzn1
perl-DBI.x86_64 0:1.627-4.8.amzn1
perl-Data-Dumper.x86_64 0:2.145-3.5.amzn1
perl-IO-Compress.noarch 0:2.061-2.12.amzn1
perl-Net-Daemon.noarch 0:0.48-5.5.amzn1
perl-PlRPC.noarch 0:0.2020-14.7.amzn1
php71-cli.x86_64 0:7.1.13-1.30.amzn1
php71-common.x86_64 0:7.1.13-1.30.amzn1
php71-json.x86_64 0:7.1.13-1.30.amzn1
php71-pdo.x86_64 0:7.1.13-1.30.amzn1
php71-process.x86_64 0:7.1.13-1.30.amzn1
php71-xml.x86_64 0:7.1.13-1.30.amzn1
php71-devel.x86_64 0:7.1.13-1.30.amzn1
php71-fpm.x86_64 0:7.1.13-1.30.amzn1
php71-mbstring.x86_64 0:7.1.13-1.30.amzn1
Complete!

#4 インストールされた内容、バージョン確認

$ php -v
PHP 7.1.13 (cli) (built: Jan 25 2018 22:40:51) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

$ mysql -V
mysql Ver 14.14 Distrib 5.6.38, for Linux (x86_64) using EditLine wrapper

$ apachectl -v
Server version: Apache/2.4.27 (Amazon)
Server built: Sep 24 2017 23:19:50

#5 Apache 設定

$ sudo chkconfig httpd on

$ cd /etc/httpd
$ ll
total 12
drwxr-xr-x 2 root root 4096 Feb 24 23:58 conf
drwxr-xr-x 2 root root 4096 Feb 26 00:54 conf.d
drwxr-xr-x 2 root root 4096 Feb 26 00:54 conf.modules.d
lrwxrwxrwx 1 root root 14 Feb 24 23:58 logs -> /var/log/httpd
lrwxrwxrwx 1 root root 24 Feb 24 23:58 modules -> /usr/lib64/httpd/modules
lrwxrwxrwx 1 root root 14 Feb 24 23:58 run -> /var/run/httpd

#6 ユーザー追加 Webアカウントの設定

$ sudo useradd khagiwara -G apache
$ sudo passwd khagiwara
Changing password for user khagiwara. New password:
Retype new password:
passwd: all authentication tokens updated successfully.
$ id khagiwara
uid=502(khagiwara) gid=502(khagiwara) groups=502(khagiwara),48(apache)
$ sudo su khagiwara
$ whoami
khagiwara
$ pwd
/home/khagiwara
$ mkdir .ssh
$ chmod 700 .ssh
$ ls -al
total 28
drwx—— 3 khagiwara khagiwara 4096 Feb 26 02:28 .
drwxr-xr-x 5 root root 4096 Feb 26 02:13 ..
-rw——- 1 khagiwara khagiwara 220 Feb 26 02:27 .bash_history
-rw-r–r– 1 khagiwara khagiwara 18 Aug 30 19:00 .bash_logout
-rw-r–r– 1 khagiwara khagiwara 193 Aug 30 19:00 .bash_profile
-rw-r–r– 1 khagiwara khagiwara 124 Aug 30 19:00 .bashrc
drwx—— 2 khagiwara khagiwara 4096 Feb 26 02:28 .ssh
$ cd .ssh
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/khagiwara/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/khagiwara/.ssh/id_rsa.
Your public key has been saved in /home/khagiwara/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vgTfEOEN9xZWwEMSRnluT0S03hAmNHF5K9Uo4VZ94P4 khagiwara@ip-172-31-30-0
The key’s randomart image is:
+—[RSA 2048]—-+
| o.**@BX=.|
| . *.==O++=|
| o .o=+=.o|
| . oo+.+ |
| . S . o+ .|
| + o .. |
| + . E|
| . . |
| . |
+—-[SHA256]—–+
$ ll
total 8
-rw——- 1 khagiwara khagiwara 1675 Feb 26 05:00 id_rsa
-rw-r–r– 1 khagiwara khagiwara 406 Feb 26 05:00 id_rsa.pub

#7 作成された id_rsa.pub を  authorized_key に 追加する。

$ pwd
/home/khagiwara/.ssh
$ cat id_rsa.pub >> authorized_keys
$ ll
-rw——- 1 khagiwara khagiwara 825 Feb 26 05:06 authorized_keys
-rw——- 1 khagiwara khagiwara 1675 Feb 26 05:00 id_rsa
-rw-r–r– 1 khagiwara khagiwara 406 Feb 26 05:00 id_rsa.pub
# フォルダー内にある id_rsa をローカルにダウンロードし適当な名称に変更する。
# ここでは aws_khagiwara.pem とする。
# ファイルをダウンロードするには インスタンス作成時のデフォルトkey を使い scp や sftp でダウンロードする。
# 作成されたペアキーはダウンロード後に削除しておく

#8 ssh 接続するホームホルダーの属性を 711 にしておく。

$ ls -al /home/khagiwara
total 32
drwx–x–x 3 khagiwara khagiwara 4096 Feb 26 05:06 .
drwxr-xr-x 5 root root 4096 Feb 26 02:13 ..
-rw——- 1 khagiwara khagiwara 747 Feb 26 10:37 .bash_history



# これによりローカルからインスタンス作成時のデフォルトkey同様にsshでログインが可能となる

#9 http のテストページの表示

AWS 管理ページ > EC2 > インスタンス > 該当するインスタンスを選択 > セキュリティグループ > インバウンド > ルールの追加 > HTTP を追加する


#10 Http を起動し、ブラウザで Apache のテストページを確認する。

$ sudo apachectl start


#11 ユーザーホームを有効にする。

vi /etc/httpd/conf.d/userdir.conf

#UserDir disabled #コメントアウト


UserDir public_html #UserDir public_html #削除 コメント解除

<Directory “/home/*/public_html”>
AllowOverride All # 変更
Options None # 変更
Require method GET POST OPTIONS
</Directory>



# 別途 GIT で リモートレポジトリを作成しローカル環境をアップロードするに続きます。

最近の記事

  1. wordpres5をubuntu nginxにインストール
  2. ubuntu 20.04 nginx php mysql Webサーバー環境整備
  3. Ubuntu nginx SSL
  4. EC-CUBE 4.0 インストール
  1. 趣味・実用

    vim テキストエディターを快適に使う
  2. Raspberry PI

    raspberryPi 4B CenotOS7 をインストール LAMP環境を…
  3. Raspberry PI

    Raspberry Pi 4 ModelB Raspbian インストール VN…
  4. プログラミング

    WordPress jQuery + CSS + ショートコードで モーダル…
  5. サーバー環境

    無料SSL証明書 Let’s Encrypt でワイルドカードな証明…
PAGE TOP