LoginSignup
9
12

More than 5 years have passed since last update.

CentOSへApache2.xをソースビルドしてService登録する

Last updated at Posted at 2014-07-23

はじめに

yumでインストールすれば早いのですが、時としては必要になる事もあるので備忘録としてまとめておきます。
最新版のソースを取得してビルドする際には適宜読みかえて使う事を想定。

※セキュリティやパフォーマンスの向上は割愛しておりますので、このままサーバーを外部公開する事はお勧め致しません

既存のapacheが存在しないか確認する

もし存在していればアンインストール
rpm -qa httpd
[存在していればバージョンが表示される]
yum remove [httpd-version]

ソースコード取得からインストール

最新版コードのダウンロードURLは公式サイト参照

wget [http://ftp.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.2.24.tar.gz]
tar zxvf httpd-2.2.24.tar.gz
./configure -prefix=/usr/local/apache2 \
-enable-so \
-enable-rewrite \
-enable-ssl \
-enable-mods-shared=all
make
make install

起動ファイルを取得して設置

解凍したapacheのソースディレクトリ内にあるhttpd.initをinit.dへコピーして書き換え。
コピー元のパスは適宜読み替える。

cp /usr/src/httpd-2.2.24/build/rpm/httpd.init /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd

[修正内容]
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid}
CONFFILE=/usr/local/apache2/conf/httpd.conf
[ここまで]

iptablesを設定

vi /etc/sysconfig/iptables

[追記内容]
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport http -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport https -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
[ここまで]

/etc/init.d/iptables restart
/sbin/chkconfig iptables on

全ユーザー共通でパスを通す

perlやphp,mysql等も以下の設定で呼び出せるようになります
mysqlのソースビルドについては過去に投稿した記事をどうぞ

vi /etc/profile
[追記内容]
/usr/local/bin:/etc/init.d:/etc/:/usr/local/mysql/bin:/sbin/
[ここまで]
source /etc/profile

Service登録

chkconfig --add httpd
chkconfig httpd on

9
12
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
9
12