がじぇ

お金と家電とプログラミングのブログ

【AWS】Apache2.4をEC2(CentOS6)にローカルインストールする手順

こんにちわ

がじぇったー (@hackmylife7) | Twitter

です。

Apache2.2をEC2にローカルインストールする手順について書きます。

f:id:gadgeterkun:20200508155404j:plain

前提

  • EC2をCentOS6で立ち上げ済み
  • apacheは2.4をローカルインストールする

手順

インストール手順

  • ローカルインストールにはaprapr-utilライブラリを事前にインストールしておく必要があります
  • aprApache Portable Runtimeの略であり、どのOSでも動くようApacheのサブ的なライブラリです

Apache Portable Runtime(APR)は、クロスプラットフォームの方法で一般的なI / O関数を抽象化するように設計された関数のセットです。

Apache Portable Runtime - Second Life Wiki

# cd /usr/local/src
# wget http://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz
# wget https://ftp.riken.jp/net/apache//apr/apr-1.7.0.tar.gz
# wget https://ftp.riken.jp/net/apache//apr/apr-util-1.6.1.tar.gz
# tar -xvzf apr-1.7.0.tar.gz
# cd /usr/local/src/apr-1.7.0
# ./configure --prefix=/usr/local/apr/apr-1.7.0
# make
# make install
# cd ..
# tar -xvzf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util/apr-util-1.6.1 --with-apr=/usr/local/apr/apr-1.7.0
# make
# make install
# cd ..
# cd httpd-2.4.23
# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/apr-1.7.0 --with-apr-util=/usr/local/apr-util/apr-util-1.6.1
# make
# make install
# vi /opt/httpd-2.4.23/conf/httpd.conf
UserとGroupをapacheに変更

起動手順

# /usr/local/apache2/bin/apachectl configtest
Syntax OK
#
# ps -ef | grep httpd
root      6111     1  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    6112  6111  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    6113  6111  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    6114  6111  0 10:43 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

# curl http://localhost
<html><body><h1>It works!</h1></body></html>

起動スクリプトの作成

# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
# vi /etc/init.d/httpd
”# chkconfig: 345 85 15”をファイルの末尾に追加
確認
# tail -n 1 /etc/init.d/httpd
# chkconfig: 345 85 15

# chkconfig --add httpd
# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:on    4:on    5:on    6:off
#  service httpd restart
# ps -ef | grep httpd
root      1652     1  0 May05 ?        00:00:09 /usr/local/apache2/bin/httpd -k start
apache   19584  1652  0 15:47 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
root     19719 19502  0 15:47 pts/0    00:00:00 grep httpd
#

rebootして自動起動されていることを確認する

# reboot
sshしなおしてプロセスを確認
# ps -ef | grep httpd
root      1390     1  0 15:52 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
apache    1393  1390  0 15:52 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
root      1612  1593  0 15:57 pts/0    00:00:00 grep httpd

超オススメのAWS