LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

【AWS自分用メモ】webサーバーに関しての設定

Posted at

インストール

  • 各サービスのインストール
  • 基本PHPのモジュールインストール

各サービスのインストール

yum install -y httpd24 php56 mysql56 git

基本phpモジュールのインストール

phpのモジュールをインストールする。
yum install -y php56-mcrypt php56-intl php56-mbstring php56-mysqlnd php56-opcache php56-devel

各サービスの設定

git設定

◆gitコマンド時にユーザー、パスワードを省略する
ホームディレクトリ.netrcを作成
#vi .netrc

.netrc
machine [ホスト]
login [ユーザー]
password [パスワード]

◆プロジェクトを取得する
ホームディレクトリで取得する。
#git clone [URL]

apache設定

◆virtualconfの設定
構成:
・ホームディレクトリにプロジェクトを置きます。
・ELBのヘルスチェックのログとプロジェクトに対してのログは分けます。
・バーチャルconfに記述のRemoteIPHeader X-Forwarded-Forでログに相手のパブリックIPを表示させる。(/etc/httpd/conf/httpd.confのログフォーマットも変えないといけませんので後に記述)

バーチャルconfの作成
#vi /etc/httpd/conf.d/projects.conf

projects.conf
ServerName example.com
<VirtualHost *:80>

  DocumentRoot /home/user/projects/
  ServerName example.com
  SetEnvIf User-Agent "ELB-HealthChecker*" elb
  SetEnvIf User-Agent "ELB-HealthChecker*" nolog
  SetEnvIf User-Agent "internal dummy connection" nolog
  ErrorLog logs/projects-error_log
  CustomLog logs/projects-access_log combined env=!nolog
  CustomLog logs/elb-helth_log combined env=elb
  RemoteIPHeader X-Forwarded-For

  <Directory /home/user/projects>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

</VirtualHost>

◆httpd.confの設定
ログにアクセスしてきた人のパブリックIPを表示させます。
変更前:LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
変更後:LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

◆ディレクトリの権限の変更
apacheユーザーがProjectを読み込めるように設定

#chown -R user:apache /home/user
#chmod 2775 /home/user
#find /home/user -type d -exec chmod 2775 {} \;
#find /home/user -type f -exec chmod 0664 {} \;

◆自動起動
#chkconfig httpd on

◆起動
#/etc/init.d/httpd start

mysql

◆RDSへの接続テスト
RDSはauroraかmysqlを想定

mysql -u user -h RDSエンドポイント -D database -p

◆.myconfでmysqlコマンドを省略して接続
ホームディレクトリに.my.confを作成する
#vi .my.conf

.my.conf
[client]
host = host
user = user
password ="password"
database = database
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