Guozhen AIGlobal AI field notes and model intelligence

English translation

5. Compiling and Installing Apache 2 from Source Code

Published:

Category: Apache 2 Web Deployment

Read time: 3 min

Reads: 0

Lesson #5Views are counted together with the original Chinese articleImages are preserved from the source page

In the previous article, we introduced how to install Apache2 using package management tools. Installing Apache2 via package managers is simple and fast; however, in certain scenarios—such as when custom configuration or a specific version is required—you may need to compile and install Apache2 from source code.

In this section, we’ll walk you through the complete process of compiling and installing Apache2 from source. This includes preparing the build environment, downloading the source code, compiling and installing Apache2, and performing basic configuration. Let’s get started!

Environment Preparation

Before installing Apache2, ensure your system has all necessary dependencies installed. Typically, you’ll need the following tools and libraries:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libpcre3 libpcre3-dev libssl-dev wget

The build-essential package provides essential compilation tools—including gcc and make. libpcre3 and libssl-dev are commonly used by Apache2 for regular expression handling and SSL/TLS support, respectively.

Downloading the Source Code

Next, download the Apache2 source code. Visit the official Apache HTTP Server Project website at Apache HTTP Server Project to locate the latest source distribution. Below is an example command to download Apache 2.4.x:

wget http://downloads.apache.org/httpd/httpd-2.4.x.tar.gz

Be sure to replace 2.4.x with the exact version number you intend to install.

Extracting the Archive and Navigating to the Directory

After downloading, extract the archive and change into the resulting directory:

tar -zxvf httpd-2.4.x.tar.gz
cd httpd-2.4.x

Compiling Apache2

Inside the source directory, run the configure script to set up the build environment. You can pass various options to customize the build. Here's a minimal example:

./configure --enable-so --with-included-apr
  • --enable-so: Enables support for dynamically loadable modules (DSO).
  • --with-included-apr: Uses the bundled Apache Portable Runtime (APR) library instead of a system-installed one.

Once configuration completes successfully, compile Apache2 with:

make

Compilation time varies depending on your system’s hardware and configuration.

Installing Apache2

After compilation finishes, install Apache2 using:

sudo make install

By default, Apache2 is installed under /usr/local/apache2. Verify the installation by listing its contents:

ls /usr/local/apache2

Starting Apache2

Once installed, start Apache2 with:

/usr/local/apache2/bin/apachectl start

To verify that Apache2 is running, open your web browser and navigate to http://localhost. If everything is configured correctly, you should see Apache’s default welcome page.

Checking Apache2 Status

To check whether Apache2 is running properly, use:

/usr/local/apache2/bin/apachectl status

Stopping Apache2

To stop the Apache2 server, run:

/usr/local/apache2/bin/apachectl stop

Modifying the Configuration File

In the next article, we’ll dive deep into understanding and editing Apache2’s core configuration files. If you’ve successfully completed the steps above, the main configuration file will be located at:

/usr/local/apache2/conf/httpd.conf

There, we’ll cover how to modify and optimize this file to suit your specific requirements—from virtual hosts and SSL settings to performance tuning and security hardening.

Closing Remarks

In this article, we walked through the end-to-end process of compiling and installing Apache2 from source code. Mastering this workflow gives you full control over configuration options and version selection. We hope this guide has been helpful.

In the next article, we’ll move on to hands-on Apache2 configuration. Stay tuned!

Continue

Keep reading from here

Browse English site

Reader Messages

Reader messages

Questions, corrections, extra sources, or hands-on results can be left here. No login is required.

Max 800 characters

To reduce spam, each message is checked for length, link count, and posting frequency.

0/800

Messages

0 messages
Loading messages...