Apache2.4.43 + OpenSSL1.1.1gをソースからインストール

CentOS7にApache2.4.43+OpenSSL1.1.1g+PHP7.4.5をソースからインストール

約8ヶ月ぶりにApache 2.4.43がリリースされたのでバージョンアップしました。OpenSSLも1.1.1gに上がっていますのでまとめておきます(基本的に自分用の覚書です)。

Apacheは2.4.41→2.4.43、OpenSSLは1.1.1c→1.1.1g、PHPは7.3.8→PHP7.4.5にバージョンアップしますが、それ以外は前回の投稿から変わりません。

 

1. OpenSSL 1.1.1g を /usr/local/ssl にインストール

# yum -y groupinstall base
# yum -y groupinstall development
# yum -y update
# yum -y install zlib-devel
# yum -y install perl-core
# cd /usr/local/src/
# wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
# tar xvfz openssl-1.1.1g.tar.gz
# cd openssl-1.1.1g
# ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
# make depend
# make
# make test
# make install
# ln -s /usr/local/ssl/lib/libcrypto.so.1.1 /lib64/libcrypto.so.1.1   (初めてのとき)
# ln -s /usr/local/ssl/lib/libssl.so.1.1 /lib64/libssl.so.1.1    (初めてのとき)
# echo /usr/local/ssl/lib > /etc/ld.so.conf.d/openssl111.conf  (初めてのとき)
# ldconfig
# /usr/local/ssl/bin/openssl version

※以下任意(非常に時間がかかります)

# cd /usr/local/ssl/private/
# /usr/local/ssl/bin/openssl dhparam 4096 -out dhparam.pem

 

2. Nghttp2とBrotliを /usr/local/lib にインストール

2.1. Nghttp2 1.40.0(libnghttp2)

OpenSSL 1.1.1gは /usr/local/ssl 配下にインストールしてあるので、envで指定します。

# yum -y install jansson-devel
# yum -y install libev-devel
# yum -y install c-ares-devel
# yum -y install centos-release-scl
# yum -y install devtoolset-7
# scl enable devtoolset-7 bash
# cd /usr/local/src/
# wget https://github.com/nghttp2/nghttp2/releases/download/v1.40.0/nghttp2-1.40.0.tar.gz
# tar xvzf nghttp2-1.40.0.tar.gz
# cd nghttp2-1.40.0/
# env OPENSSL_CFLAGS="-I/usr/local/ssl/include" OPENSSL_LIBS="-L/usr/local/ssl/lib -lssl -lcrypto"
#./configure --prefix=/usr \
            --disable-static \
            --enable-lib-only \
            --enable-app \
            --docdir=/usr/share/doc/nghttp2-1.40.0
# make
# make install
2.2. Brotli 1.0.7
# yum -y install cmake
# cd /usr/local/src/
# wget https://github.com/google/brotli/archive/v1.0.7.tar.gz
# tar xvzf v1.0.7.tar.gz
# cd brotli-1.0.7/
# mkdir out && cd out
# ../configure-cmake
# make
# make test
# make install
# echo /usr/local/lib > /etc/ld.so.conf.d/usr-local-lib.conf
# ldconfig

 

3. Apache 2.4.43 を /usr/local/httpd4 にインストール

3.1. APR 1.7.0
# cd /usr/local/src/
# wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-1.7.0.tar.gz
# tar xvzf apr-1.7.0.tar.gz
# cd apr-1.7.0/
# ./configure
# make
# make install
3.2. APR-util 1.6.1
# cd /usr/local/src/
# wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-util-1.6.1.tar.gz
# tar xvzf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1/
# ./configure --with-apr=/usr/local/apr
# make
# make install
3.3. Apache 2.4.43

—prefix=/usr/local/httpd4 とすることで「httpd4」のディレクトリにインストールします。

# cd /usr/local/src/
# wget http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.4.43.tar.gz
# tar xvzf httpd-2.4.43.tar.gz
# cd httpd-2.4.43/
# ./configure \
--prefix=/usr/local/httpd4 \
--enable-http2 \
--enable-brotli \
--with-brotli=/usr/local/lib \
--enable-ssl \
--with-ssl=/usr/local/ssl \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr \
--enable-so \
--enable-mods-shared=all \
--enable-mpms-shared=all
# make
# make install

インストールされたらApacheの設定。httpd.confの該当箇所を有効化、追記・修正します。

# cd /usr/local/httpd4/conf
# vi httpd.conf
-----------------------------------------
# for Brotli
LoadModule brotli_module modules/mod_brotli.so
LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
# for HTTPS
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
# for HTTP/2
LoadModule http2_module modules/mod_http2.so
# for VirtualHost
LoadModule vhost_alias_module modules/mod_vhost_alias.so
# for Rewrite
LoadModule rewrite_module modules/mod_rewrite.so
# for php-fpm
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
# for gZip
LoadModule deflate_module modules/mod_deflate.so
# for cash expire
LoadModule expires_module modules/mod_expires.so
.
.
User apache
Group apache
.
.
# for cash expire
<IfModule mod_expires.c>
    <filesMatch ".(jpg|jpeg|png|gif|swf|js|css)$">
        ExpiresActive On
        ExpiresDefault "access plus 30 days"
    </filesMatch>
</IfModule>
.
.
<IfModule dir_module>
    # index.php追加(WordPressに必要)
    #DirectoryIndex index.html
    DirectoryIndex index.html index.php
</IfModule>
.
.
# php追加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
.
.
Include conf/extra/httpd-mpm.conf
.
.
# Virtual hosts(http用、https用は分けて設定します)
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts-http.conf
Include conf/extra/httpd-vhosts-https.conf
.
.
Include conf/extra/httpd-ssl.conf
-----------------------------------------
:wq

mpm_eventの設定

# cd extra
# vi httpd-mpm.conf 
-----------------------------------------
.
.
<IfModule mpm_event_module>
    StartServers            4
    MinSpareThreads         4
    MaxSpareThreads         4
    ThreadsPerChild         16
    MaxRequestWorkers       16
    MaxConnectionsPerChild 200
</IfModule>
.
.
-----------------------------------------
:wq

HTTPSの設定。httpd-ssl.confを以下のように追記・修正します。最近SSL Labsの判定が厳しいので、TLS 1.2、TLS 1.3の緑色になる(Weak扱いされない)暗号スイートだけ残します。

# vi httpd-ssl.conf
-----------------------------------------
.
.
# 常時SSL
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
Header always set X-Frame-Options SAMEORIGIN
Header always set X-Content-Type-Options nosniff
.
.
# 明示的にSSL圧縮をOFF
SSLCompression off
.
.
SSLCipherSuite "TLS_AES_256_GCM_SHA384 \
TLS_CHACHA20_POLY1305_SHA256 \
ECDHE-RSA-AES256-GCM-SHA384 \
DHE-RSA-AES256-GCM-SHA384 \
ECDHE-RSA-CHACHA20-POLY1305"

SSLProxyCipherSuite "TLS_AES_256_GCM_SHA384 \
TLS_CHACHA20_POLY1305_SHA256 \
ECDHE-RSA-AES256-GCM-SHA384 \
DHE-RSA-AES256-GCM-SHA384 \
ECDHE-RSA-CHACHA20-POLY1305"
.
.
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLProxyProtocol all -SSLv3 -TLSv1 -TLSv1.1
.
.
# for OCSP
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache shmcb:/var/run/ocsp(128000)
.
.
#ServerName www.example.com:443
#ServerAdmin you@example.com
.
.
SSLEngine on
    #Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/ji0vwl.net/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/ji0vwl.net/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/ji0vwl.net/chain.pem
.
.
#SSLCertificateFile "/usr/local/httpd4/conf/server.crt"
.
.
#SSLCertificateKeyFile "/usr/local/httpd4/conf/server.key"
-----------------------------------------
:wq

HTTPバーチャルホストの設定

# vi httpd-vhosts-http.conf
-----------------------------------------
<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName test.ji0vwl.net

    <Directory "/var/www/html/">
        Options FollowSymlinks Includes
        AllowOverride All
        AddType text/html .html
        Require all granted
    </Directory>
    
    # HTTPSにリライトする場合はコメントアウト解除
    #RewriteEngine on
    #RewriteCond %{SERVER_NAME} =test.ji0vwl.net
    #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
-----------------------------------------
:wq

HTTPSバーチャルホストの設定

Require not ip は、必要に応じて制限したいIPアドレス範囲を指定してください。

# vi httpd-vhosts-https.conf
-----------------------------------------
<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot /var/www/html
    ServerName test.ji0vwl.net
    
    # HTTP/2有効化(h2追加)
    Protocols h2 http/1.1

    <Directory "/var/www/html/">
        Options FollowSymlinks Includes
        AllowOverride All
        AddType text/html .html
        <RequireAll>
          Require not ip xxx.xxx yyy.yyy zzz.zzz.zzz
          Require all granted
        </RequireAll>
    </Directory>

    # SSL証明書
    SSLCertificateFile /etc/letsencrypt/live/ji0vwl.net/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/ji0vwl.net/privkey.pem

    # for dhparams(dhparam.pemを作っていない場合はコメントアウト)
    SSLOpenSSLConfCmd DHParameters "/usr/local/ssl/private/dhparam.pem"
    SSLOpenSSLConfCmd ECDHParameters secp384r1
    SSLOpenSSLConfCmd Curves secp384r1

    # for gZip圧縮
   <IfModule mod_deflate.c>
       DeflateCompressionLevel 1
       <IfModule mod_filter.c>
        FilterDeclare COMPRESS
        FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^text/#i"
        FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^application/(atom\+xml|javascript|json|rss\+xml|xml|xhtml\+xml)#i"
        FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^image/(svg\+xml|vnd\.microsoft\.icon)#i"
        FilterChain COMPRESS
        FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
       </IfModule>
   </Ifmodule>

   # for Brotli圧縮
   <IfModule mod_brotli.c>
       SetOutputFilter BROTLI_COMPRESS
       SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-brotli

       BrotliCompressionQuality 5
       BrotliCompressionWindow 18

       BrotliFilterNote Input instream
       BrotliFilterNote Output outstream
       BrotliFilterNote Ratio ratio
   </IfModule>

   # for dosdetector
   DoSDetection on
   DoSPeriod 60
   DoSThreshold 250
   DoSBanPeriod 60
   DoSTableSize 100
   RewriteEngine On
   RewriteCond %{ENV:SuspectDoS} =1
   RewriteRule .* - [R=503,L]
   ErrorDocument 503 "<h1>Sorry, ji0vwl.net is busy.. Please access later.</h1>"
</VirtualHost>
</IfModule>
-----------------------------------------
:wq

 

4. Apache 2.4.43 を httpd4.service に登録

「systemctl start httpd4」で起動できるように、httpd4 という名前のサービスとして登録します。reload=graceful動作です。今回はのhttpd4を使いまわしたのでとくに対応は必要ありません。

 # vi /etc/systemd/system/httpd4.service
-----------------------------------------
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
ExecStart=/usr/local/httpd4/bin/apachectl start
ExecReload=/usr/local/httpd4/bin/apachectl graceful
ExecStop=/usr/local/httpd4/bin/apachectl stop
 
[Install]
WantedBy=multi-user.target
-----------------------------------------
:wq
# systemctl daemon-reload
# systemctl list-unit-files | grep httpd4

 

 

5. PHP 7.4.5 を /usr/local/php7.4 にインストールする

5.1. PHPAPCu/APCu_bcの準備

それぞれ最新のソースをwgetでダウンロードしてきます。apcuとapcu_bcは、PHPのソース展開後 php-7.4.5/ext/ ディレクトリ内に展開し、それぞれリネームします。

$ sudo -i
# cd /usr/local/src
# yum -y install libxml2-devel systemd-devel libpng-devel libwebp libwebp-devel libwebp-tools
# wget http://jp2.php.net/get/php-7.4.5.tar.gz/from/this/mirror -O /usr/local/src/php-7.4.5.tar.gz
# tar -xvzf php-7.4.5.tar.gz
# cd php-7.4.5/ext
# wget -q https://pecl.php.net/get/apcu-5.1.18.tgz
# wget -q https://pecl.php.net/get/apcu_bc-1.0.5.tgz
# tar zxvf apcu-5.1.18.tgz
# tar zxvf apcu_bc-1.0.5.tgz
# mv apcu-5.1.18 apcu
# mv apcu_bc-1.0.5 apcu_bc
# cd ..
# rm -rf configure
# ./buildconf --force
buildconf: Checking installation
buildconf: autoconf version 2.69 (ok)
buildconf: Forcing buildconf. The configure files will be regenerated.
buildconf: Cleaning cache and configure files
buildconf: Rebuilding configure
buildconf: Rebuilding main/php_config.h.in
buildconf: Run ./configure to proceed with customizing the PHP build.

 

5.2. PHP 7.4.5 をインストールする

–prefix=[dir]でPHPインストール先を指定します。また–with-apxs2=[dir]でPHPとApacheを、–with-openssl=[dir]でPHPとOpenSSLを、–with-mysql-sock=[dir]でPHPとmySQLを結びつけます。PHP 7.4から sqlite-devel と oniguruma-devel libXpm-devel、cmake3とlibzipがが追加で必要になったので事前にインストールしておきます。

# yum -y install sqlite-devel oniguruma-devel libXpm-devel cmake3
# ln -s /usr/bin/cmake3 /usr/local/bin/cmake
# cd /usr/local/src
# wget https://libzip.org/download/libzip-1.5.2.tar.gz
# tar xvfz libzip-1.5.2.tar.gz
# cd libzip-1.5.2
# /usr/local/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr
# make
# make install
# cd /usr/local/src/php-7.4.5
# ./configure \
--prefix=/usr/local/php7.4 \
--with-apxs2=/usr/local/httpd4/bin/apxs \
--with-openssl=/usr/local/ssl \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-mysqli \
--with-pdo-mysql \
--with-zlib \
--with-curl \
--with-zip \
--with-jpeg \
--with-xpm \
--with-freetype \
--with-fpm-systemd \
--with-fpm-user=apache \
--with-fpm-group=apache \
--enable-gd \
--enable-gd-jis-conv \
--enable-mbstring \
--enable-xml \
--enable-fpm \
--enable-ftp \
--enable-apc \
--enable-apcu \
--enable-opcache \
--enable-inline-optimization
# make
# make install
# libtool --finish /usr/local/src/php-7.4.5/libs

 

5.3. php.iniを作成する

APCuを有効にするためにphp.ini作成します。Opcacheも有効にしておきます。php.iniを作る場所が分からない場合はこちら。今回は作成済みなので省略します。

# cd /usr/local/php7.4/lib
# vim php.ini
max_execution_time=600
memory_limit=128M
error_reporting=0
display_errors=0
log_errors=0
user_ini.filename=
realpath_cache_size=2M
cgi.check_shebang_line=0
date.timezone = "Asia/Tokyo"
zend_extension=opcache.so

[opcache]
opcache.enable=1
;opcache.enable_cli=0
opcache.memory_consumption=64
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
;opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.revalidate_path=0
;opcache.save_comments=1
opcache.fast_shutdown=1
;opcache.enable_file_override=0
opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
;opcache.blacklist_filename=/etc/php.d/opcache*.blacklist
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
;opcache.error_log=
;opcache.log_verbosity_level=1
;opcache.preferred_memory_model=
;opcache.protect_memory=0
;opcache.restrict_api=
;opcache.file_cache=
;opcache.file_cache_only=0
;
apc.enabled = 1
apc.enable_cli=1
apc.shm_size=40M
apc.ttl=3600
apc.gc_ttl=3600
;apc.mmap_file_mask=/tmp/apc.XXXXXX
;
;;mbstring
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII

 

6.  Passenger 6.0.4 をインストール

Redmineを動かさない場合は飛ばしていただいて問題ありません。

# gem install passenger
# chmod o+x "/root"
# passenger-install-apache2-module --apxs2-path "/usr/local/httpd4/bin/apxs"      # めちゃくちゃ時間がかかります
1
[Enter]
●Ruby
●Python
[Enter]
y
[Enter]
.
.
.
★30分以上。気長に待ちましょう★
.
.
[Enter]
[Enter]

 

 

7. httpd4を再起動

# systemctl restart httpd4

 

httpd4を再起動してSSL LabsでHTTPSの検証を行い、無事Apache 2.4.43/OpenSSL 1.1.1g/PHP 7.4.5/(Passenger 6.0.4)の環境にて、動作が確認できました!

 


(2020/5/4 修正)

OpenSSL 1.1.1g、PHP 7.4.5に修正いたしました。

「Apache2.4.43 + OpenSSL1.1.1gをソースからインストール」への2件のフィードバック

  1. ご丁寧にご指摘いただきありがとうございます!
    1.1.1gはリリース後すぐにアップデート済みですので、記事を修正する様にいたします。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


リンクが含まれる投稿はサイト管理者の承認後に表示されます(スパム対策)