X

Compile Apache 2.4 From Source

Compiling Apache 2.4 from source is easy and allows for more customization later on. It also allows for control over where it is installed

Install some required depedencies:

yum install -y wget pcre-devel openssl openssl-devel expat-devel

First get the latest version, at the time of writing this it is 2.4.25. The link to download the latest version is here

wget -O /usr/src/httpd-2.4.25.tar.gz http://mirror.nexcess.net/apache//httpd/httpd-2.4.25.tar.gz

Change directories to /usr/src

cd /usr/src

Uncompress the tar

tar xfvz httpd-2.4.25.tar.gz

Go to the directory:

cd httpd-2.4.25

The build we are creating requires apr and apr-util so to the src lib directory and download the following (APR download page):

cd ./srclib
wget http://mirror.stjschools.org/public/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.gigenet.com/apache//apr/apr-util-1.5.4.tar.gz

Uncompress them and rename them:

tar xfvz apr-1.5.2.tar.gz; mv apr-1.5.2 apr
tar xfvz apr-util-1.5.4.tar.gz; mv apr-util-1.5.4 apr-util

Configure Apache:

Go back to the main source directory:

cd ../

To view the configure options type the following

./configure --help

This is a sample config:

./configure \
--enable-layout=RedHat \
--prefix=/usr \
--enable-expires \
--enable-headers \
--enable-rewrite \
--enable-cache \
--enable-mem-cache \
--enable-speling \
--enable-usertrack \
--enable-module=so \
--enable-unique_id \
--enable-logio \
--enable-ssl=shared \
--with-ssl=/usr \
--enable-proxy=shared \
--with-included-apr

Make:

make

Install:

make install

Start Services:

CentOS 7 

Create a systemd start file by creating /etc/systemd/system/httpd.service and add

[Unit]
Description=The Apache HTTP Server

[Service]
Type=forking
PIDFile=/var/apache/httpd.pid
ExecStart=/usr/sbin/apachectl start
ExecReload=/usr/sbin/apachectl graceful
ExecStop=/usr/sbin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true


[Install]
WantedBy=multi-user.target

Configure it to start on boot:

systemctl enable httpd

Start it

systemctl start httpd

CentOS 6

chkconfig --add httpd

chkconfig httpd on

service httpd start

That’s it for compiling Apache from source. If you visit the http://ip-address of the server you should see a default page for apache.

You can also verify its running by typing the following:

# ps aux|grep httpd
root 1101 0.0 0.0 105376 836 pts/0 S+ 21:03 0:00 grep httpd
nobody 15834 0.0 0.4 270908 8288 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15835 0.0 0.4 270764 8224 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15836 0.0 0.4 270764 8224 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15837 0.0 0.4 270764 8224 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15838 0.0 2.1 321656 40916 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15839 0.0 1.6 292740 32276 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15840 0.0 1.6 291948 31052 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL
nobody 15841 0.0 1.6 291948 31048 ? S 03:46 0:00 /usr/sbin/httpd -DHAVE_PROXY_FTP -DHAVE_AUTH_TOKEN -DHAVE_PROXY_HTTP -DHAVE_RPAF -DHAVE_PHP5 -DHAVE_XSENDFILE -DHAVE_AUTH_MYSQL -DHAVE_PROXY -DHAVE_PROXY_AJP -DHAVE_PROXY_BALANCER -DHAVE_PROXY_SCGI -DHAVE_SSL -DHAVE_PROXY_CONNECT -DSSL -DSSL -DSSL

httpd -M will show the compiled modules:

# httpd -M
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_default_module (static)
 authz_host_module (static)
 authz_groupfile_module (static)
 authz_user_module (static)
 authz_default_module (static)
 auth_basic_module (static)
 cache_module (static)
 mem_cache_module (static)
 include_module (static)
 filter_module (static)
 log_config_module (static)
 logio_module (static)
 env_module (static)
 expires_module (static)
 headers_module (static)
 usertrack_module (static)
 unique_id_module (static)
 setenvif_module (static)
 version_module (static)
 mpm_prefork_module (static)
 http_module (static)
 mime_module (static)
 status_module (static)
 autoindex_module (static)
 asis_module (static)
 cgi_module (static)
 negotiation_module (static)
 dir_module (static)
 actions_module (static)
 speling_module (static)
 userdir_module (static)
 alias_module (static)
 rewrite_module (static)
 so_module (static)
 ssl_module (shared)

Configuration Changes

The configuration is located in /etc/httpd/conf/httpd.conf typically.

How to change default ports

Apache listens on ports by the Listen directive to change it from port 80 (default)

Listen 8080

How to enable ssl in httpd.conf

Edit /etc/httpd/conf/httpd.conf and ensure the following line is uncommented:

LoadModule ssl_module modules/mod_ssl.so

And add the following line

Listen 443

You will need to restart the service if you make any changes to the configuration files.

LinuxAdmin.io
0 0 votes
Article Rating
LinuxAdmin.io:
Related Post