Master Apache: Install, Configure MPMs, Virtual Hosts & LAMP Stack
Learn how to install Apache from source, understand its three MPM modes (prefork, worker, event), configure common server settings, set up port‑ and domain‑based virtual hosts, and deploy both static and dynamic (LAMP) websites with step‑by‑step command examples.
1. Apache Overview
Apache HTTP Server is an open‑source web server from the Apache Software Foundation, the most widely used web server worldwide. It runs on almost all major platforms, is fast, reliable, extensible via APIs, and can embed interpreters such as Perl or Python.
Ports: HTTP uses 80, HTTPS uses 443.
2. Apache’s Three MPM Modes
Apache provides three stable Multi‑Processing Modules (MPM): prefork, worker, and event.
Prefork
Prefork is a non‑threaded, pre‑forked MPM that creates multiple processes, each handling one connection at a time. It offers high stability and isolation but consumes more memory and does not handle high concurrency well.
Worker
Worker combines multiple processes with multiple threads per process. Threads share memory, reducing memory usage and improving performance under high load. However, a thread failure can affect other threads in the same process, and keep‑alive connections may occupy threads.
Event
Event is the newest MPM, similar to worker but with a dedicated thread pool to manage keep‑alive connections, freeing worker threads for new requests. It improves high‑concurrency handling but does not support HTTPS.
3. Common HTTP Status Codes
200 – OK (request succeeded)
201 – Created (upload succeeded)
403 – Forbidden (no permission)
404 – Not Found (resource missing)
500 – Internal Server Error
502 – Bad Gateway (invalid upstream response)
4. Advantages of Building from Source
Newer versions than binary packages.
Greater control over features and dependencies.
5. Compiling and Installing Apache
Step‑by‑step commands:
# Upload source packages (apr, apr‑util, httpd)
rz
ls
# Extract packages
tar -xf apr-1.5.2.tar.gz
tar -xf apr-util-1.5.4.tar.gz
# Install dependencies
yum install gcc gcc‑c++ ncurses-devel pcre pcre-devel openssl-devel zlib-devel -y
# Build and install APR
cd /apr-1.5.2 && ./configure --prefix=/usr/local/apr && make && make install
# Build and install APR‑util
cd /apr-util-1.5.4 && ./configure --with‑apr=/usr/local/apr --prefix=/usr/local/apr‑util && make && make install
# Build and install httpd
cd /httpd-2.4.20 && ./configure --with‑apr=/usr/local/apr --with‑apr‑util=/usr/local/apr‑util --with‑mpm=event --prefix=/usr/local/httpd2.4 --enable‑so --enable‑ssl --enable‑cache --enable‑deflate --enable‑rewrite && make && make install6. Starting Apache and Setting PATH
After installation, add the binary directory to PATH via /etc/profile.d/httpd.sh and start the server with apachectl start. Verify listening on port 80 with ss -tnl | grep 80.
7. Creating Port‑Based Virtual Hosts
Edit httpd.conf to add <VirtualHost *:81> and <VirtualHost *:82> sections, set DocumentRoot and DirectoryIndex, and add the ports to the Listen directive. Create the document‑root directories, place test files, restart Apache, and test with curl 192.168.80.3:81 and curl 192.168.80.3:82.
8. Creating Domain‑Based Virtual Hosts
Add <VirtualHost 192.168.80.3> blocks with ServerName directives for www.du1.com and www.du2.com. Map the domain names to the server IP in /etc/hosts, restart Apache, and test with curl www.du1.com and curl www.du2.com.
9. Deploying a Static Site
Upload a zip package (e.g., game.zip) to /usr/local/httpd2.4/htdocs, unzip it, and access the site via a browser.
10. Deploying a Dynamic Site (LAMP)
Install the LAMP stack with yum install httpd php‑mysql mariadb‑server php -y, start MariaDB, upload WordPress, configure wp‑config.php with database credentials, create the database and user, adjust httpd.conf to set DirectoryIndex to index.php, restart the server, and access the site.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
