How to install Apache from source code

To install the latest version of Apache Web Server from source code, go to the apache website, download the latest source code .tar.gz file.

https://httpd.apache.org/download.cgi

At the time of writing this, the latest version was Apache HTTP Server 2.4.52.

Advertisement

cd /usr/local/src
wget --no-check-certificate https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.gz
tar xvf httpd-2.4.52.tar.gz
cd /usr/local/src/httpd-2.4.52
./configure --prefix=/usr/local/apache --enable-proxy --enable-proxy-connect --enable-proxy-fcgi --enable-remoteip
make
make install

If you get an error related to APR

checking for APR... no
configure: error: APR not found.  Please read the documentation.

Install APR with

For RHEL

yum -y install apr-devel apr-util-devel

For Ubuntu/Debian

apt install libapr1-dev libaprutil1-dev libpcre3-dev build-essential

To start Apache, use the command

/usr/local/apache/bin/apachectl start

To stop

/usr/local/apache/bin/apachectl stop

Apache config files are located at

/usr/local/apache/conf/httpd.conf

Create Apache Service file

Create file

vi /usr/lib/systemd/system/apache2.service
With the following content

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl graceful
ExecStop=/usr/local/apache/bin/apachectl graceful-stop
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target

Enable and start Apache service with
systemctl daemon-reload
systemctl enable apache2
systemctl restart apache2

To enable Apache module, you can edit file /usr/local/apache/conf/httpd.conf
Here are sed commands to enable some common apache modules
sed -i 's/^#LoadModule proxy_module/LoadModule proxy_module/g'  /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule proxy_fcgi_module/LoadModule proxy_fcgi_module/g'  /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule ssl_module/LoadModule ssl_module/g'  /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule rewrite_module/LoadModule rewrite_module/g'  /usr/local/apache/conf/httpd.conf
Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement