LoginSignup
2
2

More than 5 years have passed since last update.

CentOS 7 Apache 2.4.33のソースファイルからのインストール

Last updated at Posted at 2018-03-29

動作確認環境

  • 仮想環境 VMware Workstation Player 14.1.1
  • OS Windows 10 Pro 64bit

仮想環境

  • OS CentOS 7.4 (1708) minimalインストール
  • メモリ 2GB
  • HDD 250GB

前提条件

  • gcc 8.1.0
  • cmake 3.11.4
  • MySQL 5.7.22
  • OpenSSL 1.1.0.h

必要なパッケージのインストール

Nghttp2 1.32.0

最新バージョンの確認
Releases · nghttp2/nghttp2 · GitHub

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget https://github.com/nghttp2/nghttp2/releases/download/v1.32.0/nghttp2-1.32.0.tar.gz

ダウンロードしたファイルを展開する。

tar xvzf nghttp2-1.32.0.tar.gz

コンパイル・インストール
展開したディレクトリに移動する。

cd nghttp2-1.32.0

コンパイル・インストール

autoreconf -i
automake
autoconf
env OPENSSL_CFLAGS="-I/usr/local/openssl/include" OPENSSL_LIBS="-L/usr/local/openssl/lib -lssl -lcrypto" ./configure
make
make install

エラーが発生するので、対策で共有ライブラリに追加する。

echo /usr/local/lib > /etc/ld.so.conf.d/usr-local-lib.conf ldconfig

APR 1.6.3

最新バージョンの確認
Download - The Apache Portable Runtime Project

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget http://www-eu.apache.org/dist//apr/apr-1.6.3.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf apr-1.6.3.tar.gz

コンパイル・インストール
展開したディレクトリに移動する。

cd apr-1.6.3

コンパイル・インストール

./configure --prefix=/usr/local/apr-1.6.3
make
make install

APR-Util 1.6.1

最新バージョンの確認
Download - The Apache Portable Runtime Project

コンパイル・インストールするとエラーが発生するので、対策をする。

xml/apr_xml.c:35:19: 致命的エラー: expat.h: そのようなファイルやディレクトリはありません
コンパイルを停止しました。
make[1]: *** [xml/apr_xml.lo] エラー 1
make[1]: ディレクトリ `/usr/local/src/apr-util-1.6.1' から出ます
make: *** [all-recursive] エラー 1

expat-develをインストールする。

yum -y install expat-devel

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget http://www-eu.apache.org/dist//apr/apr-util-1.6.1.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf apr-util-1.6.1.tar.gz

コンパイル・インストール
展開したディレクトリに移動する。

cd apr-util-1.6.1

コンパイル・インストール

./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.3
make
make install

PCRE 8.42

最新バージョンの確認
Index of /pub/pcre/

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf pcre-8.42.tar.gz

コンパイル・インストール
展開したディレクトリに移動する。

cd pcre-8.42

コンパイル・インストール

./configure --prefix=/usr/local/pcre-8.42
make
make install

Apache

最新バージョンの確認
Welcome! - The Apache HTTP Server Project

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget http://www-eu.apache.org/dist//httpd/httpd-2.4.33.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf httpd-2.4.33.tar.gz

コンパイル・インストール
展開したディレクトリに移動する。

cd httpd-2.4.33

コンパイル・インストール

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-util-1.6.1 --with-pcre=/usr/local/pcre-8.42 --enable-http2 --enable-ssl --with-ssl=/usr/local/openssl --enable-so --enable-mods-shared=all --enable-mpms-shared=all
make
make install

Apacheの実行ユーザーを作成する。

useradd -d /tmp -s /sbin/nologin apache
useradd: 警告: ホームディレクトリが既に存在します。
skel ディレクトリからのコピーは行いません。

パスワードの変更

passwd apache
ユーザー apache のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。

所有者とグループの変更

chown -R apache:apache /usr/local/apache2/

Apache の基本設定
/etc/bashrcに追記する。

vi /etc/bashrc

追記する。

PATH=$PATH:/usr/local/apache2/bin

更新する。

source /etc/bashrc

httpd.confを編集する。

vi /usr/local/apache2/conf/httpd.conf

ServerNameを変更する。

httpd.conf
ServerName localhost:80

自動起動できるようファイルを作成する。

vi /usr/lib/systemd/system/httpd.service
httpd.service
[Unit]
Description=Apache httpd daemon

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start

[Install]
WantedBy=multi-user.target  

作成後、更新する。

systemctl daemon-reload

システム起動時の自動起動設定

systemctl enable httpd

以下のような表示をする。

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

起動

systemctl start httpd

ステータス確認

systemctl status httpd

以下のような表示をする。

● httpd.service - Apache httpd daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 金 2018-03-30 05:31:42 JST; 2s ago
  Process: 62639 ExecStart=/usr/local/apache2/bin/apachectl -k start (code=exited, status=0/SUCCESS)
 Main PID: 62642 (httpd)
   CGroup: /system.slice/httpd.service
           tq62642 /usr/local/apache2/bin/httpd -k start
           tq62643 /usr/local/apache2/bin/httpd -k start
           tq62644 /usr/local/apache2/bin/httpd -k start
           mq62645 /usr/local/apache2/bin/httpd -k start

 3月 30 05:31:42 knut systemd[1]: Starting Apache httpd daemon...
 3月 30 05:31:42 knut systemd[1]: Started Apache httpd daemon.

参考

記事がなくなりました
systemctl service の新規作成


目次

2
2
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
2
2