본문 바로가기

Linux Distributions

How to install Apache from source code on CentOS 7 and enable HTTP/2

728x90
반응형

How to install Apache from source code on CentOS 7 and enable HTTP/2

To install Apache from source code on CentOS 7 and enable HTTP/2, you can follow these steps:

1. Install the necessary dependencies

sudo yum install -y gcc pcre-devel openssl-devel zlib-devel
sudo yum install -y libnghttp2-devel

2. Download the Apache source code from the Apache website. Choose the version you want to install.

For example, let's use Apache 2.4.57:

wget --no-check-certificate https://dlcdn.apache.org/httpd/httpd-2.4.57.tar.gz

3. Extract the source code archive:

tar -xzf httpd-2.4.57.tar.gz
cd httpd-2.4.57

4. Configure the Apache build:

./configure --enable-so --enable-ssl --with-ssl=/usr/bin/openssl --enable-http2 --enable-rewrite

5. Compile Apache:

make

6. Install Apache:

sudo make install

7. Enable the necessary Apache modules:

sudo sed -i 's/^#\(LoadModule .*mod_http2.so\)/\1/' /usr/local/apache2/conf/httpd.conf
sudo sed -i 's/^#\(LoadModule .*mod_ssl.so\)/\1/' /usr/local/apache2/conf/httpd.conf

8. Generate a self-signed SSL certificate for testing purposes:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/apache2/conf/server.key -out /usr/local/apache2/conf/server.crt

Edit the Apache configuration file

더보기

Edit the Apache configuration file to enable the SSL and HTTP/2 modules

sudo vim /usr/local/apache2/conf/httpd.conf

Add the following lines to the file

LoadModule ssl_module modules/mod_ssl.so
LoadModule http2_module modules/mod_http2.so

9. Set up a basic virtual host configuration for testing HTTP/2:

  • Protocols h2 http/1.1
sudo vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
sudo vim /usr/local/apache2/conf/extra/httpd-ssl.conf
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/path/to/your/document/root"

SSLEngine on
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

Protocols h2 http/1.1
</VirtualHost>

10. Start the Apache service:

sudo /usr/local/apache2/bin/apachectl start

 

  • apache version
/usr/local/apache2/bin/httpd -v
$ /usr/local/apache2/bin/httpd -v
Server version: Apache/2.4.57 (Unix)
Server built:   Jun 15 2023 09:53:43
  • apache modules
/usr/local/apache2/bin/httpd -M
$ /usr/local/apache2/bin/httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_worker_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 ssl_module (shared)
 http2_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 php7_module (shared)

 

Now, Apache with HTTP/2 support should be installed and running on your CentOS 7 server. You can test it by accessing https://example.com (replace example.com with your server's domain or IP address) in a web browser.

 

728x90
반응형