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.
1 2 3 4 5 6 7 |
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
1 2 |
checking for APR... no configure: error: APR not found. Please read the documentation. |
Install APR with
For RHEL
1 |
yum -y install apr-devel apr-util-devel |
For Ubuntu/Debian
1 |
apt install libapr1-dev libaprutil1-dev libpcre3-dev build-essential |
To start Apache, use the command
1 |
/usr/local/apache/bin/apachectl start |
To stop
1 |
/usr/local/apache/bin/apachectl stop |
Apache config files are located at
1 |
/usr/local/apache/conf/httpd.conf |
Create Apache Service file
?
Create file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
vi /usr/lib/systemd/system/apache2.service <pre> With the following content <pre> [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
1 2 3 |
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
1 2 3 4 |
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 |