How To Install Apache on Fedora 45

Install Apache on Fedora 45

Apache HTTP Server remains one of the most dependable choices for hosting websites, APIs, reverse proxies, and internal applications on Linux. On Fedora 45, it is packaged as httpd, not apache2, and it integrates cleanly with systemd, firewalld, and SELinux. This guide walks through installing Apache, configuring a virtual host, opening firewall ports, handling SELinux correctly, applying TLS, and tuning the server for production traffic. Fedora 45 provides Apache through DNF, and current Fedora updates ship Apache HTTP Server 2.4.71.

Before You Start

Fedora is a fast-moving distribution, so a clean server should begin with updated packages. This matters more than it may seem: package updates often include security fixes, dependency changes, and improvements to service units.

Log in as a user with sudo access, then refresh the package metadata and upgrade installed software:

sudo dnf upgrade --refresh
sudo reboot

The reboot is optional after routine updates, but it is a sensible step on a newly provisioned server. It ensures that the kernel, systemd, and security-related components are all running from the versions currently installed.

Confirm the operating system:

cat /etc/fedora-release

You should see output similar to:

Fedora release 45

Fedora 45 was announced in November 2026, and its documentation and package ecosystem are actively maintained.

Install Apache HTTP Server

On Fedora, the Apache package is called httpd. This is a frequent source of confusion for administrators arriving from Debian or Ubuntu, where the package and service are named apache2.

Install Apache with:

sudo dnf install httpd

DNF resolves dependencies automatically. If Apache is already installed, DNF will tell you and leave the existing installation intact.

Check the installed version:

httpd -v

Expected output resembles:

Server version: Apache/2.4.71 (Fedora)
Server built: ...

Fedora 45 currently distributes Apache 2.4.71 through its update system.

Start and Enable the Service

Installing the package does not start the web server. Start it and enable it at boot:

sudo systemctl enable --now httpd

Verify that it is active:

systemctl status httpd --no-pager

A healthy result should include:

Active: active (running)

For a quick service check without opening the full status page:

systemctl is-active httpd

If the command returns active, Apache is running. If it returns failed, move to the troubleshooting section before changing firewall or SELinux settings.

Open HTTP and HTTPS in firewalld

Fedora installs and enables firewalld by default on most editions. Its default posture is conservative: inbound traffic is blocked except for SSH. That is exactly what you want on a production server, but it also means Apache will not be reachable from outside until you allow web traffic.

First, identify the active firewall zone:

sudo firewall-cmd --get-active-zones

On a typical server, the interface will be assigned to public. Review the current rules:

sudo firewall-cmd --list-all

Allow HTTP and HTTPS permanently:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

The --permanent option writes the rule to persistent configuration. It does not take effect in the running firewall until you reload the rules. Fedora documents this distinction clearly: runtime changes disappear after a firewall restart, while permanent rules require a reload to become active.

Confirm the result:

sudo firewall-cmd --list-all

You should now see http and https under services.

Test Apache From the Server

Use curl locally first:

curl -I http://localhost/

A successful default installation returns:

HTTP/1.1 200 OK

Then test from another machine, replacing the address with your server IP:

curl -I http://YOUR_SERVER_IP/

If local curl works but the external request times out, the issue is almost always firewalld, a cloud-provider security group, or a network route. Do not assume Apache is broken simply because a browser cannot reach it.

Understand the Fedora Apache Layout

Fedora follows the Red Hat family layout for Apache. Knowing where files live saves a great deal of time when troubleshooting.

Path Purpose
/etc/httpd/conf/httpd.conf Main Apache configuration file
/etc/httpd/conf.d/ Drop-in configuration files, including virtual hosts
/etc/httpd/conf.modules.d/ Module loading configuration
/var/log/httpd/ Apache access and error logs
/var/www/html/ Default document root
/usr/share/doc/httpd/ Package documentation and example files

The default document root is /var/www/html/. Create a simple test page:

sudo tee /var/www/html/index.html >/dev/null <<'EOF'
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Apache on Fedora 45</title>
</head>
<body>
  <h1>Apache is running on Fedora 45</h1>
</body>
</html>
EOF

Reload the page in a browser or run:

curl http://localhost/

Configure a Virtual Host

A single default site is fine for testing, but production servers usually host one or more domains. Virtual hosts let Apache route requests based on the requested hostname.

Create a directory for the site:

sudo mkdir -p /var/www/example.com/public_html

Create a basic page:

sudo tee /var/www/example.com/public_html/index.html >/dev/null <<'EOF'
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>example.com</title>
</head>
<body>
  <h1>Welcome to example.com</h1>
</body>
</html>
EOF

Set sane ownership and permissions:

sudo chown -R root:root /var/www/example.com
sudo chmod -R 755 /var/www/example.com

Create the virtual-host file:

sudo nano /etc/httpd/conf.d/example.com.conf

Add:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/example.com_error.log
    CustomLog /var/log/httpd/example.com_access.log combined
</VirtualHost>

Replace example.com with your actual domain. The ServerName directive is important because it prevents ambiguous virtual-host matching and avoids warnings during configuration tests.

Validate the configuration before restarting:

sudo apachectl configtest

A clean result is:

Syntax OK

Apply the change:

sudo systemctl reload httpd

Use reload rather than restart when possible. A reload asks Apache to re-read configuration with minimal disruption, while a restart terminates and starts worker processes. During a traffic spike, that difference matters.

SELinux: Fix It Properly

Fedora runs SELinux in enforcing mode by default. This is a strength, not an inconvenience. SELinux confines Apache to the resources its policy permits, reducing the damage a compromised web application can cause. Fedora identifies the Apache process domain as httpd_t, and files under /var/www/html normally use the httpd_sys_content_t context.

Check the current mode:

getenforce

For a production server, the expected answer is:

Enforcing

If you placed content in the standard /var/www tree, it should already have the proper context. For a custom directory, such as /var/www/example.com, verify it:

ls -Z /var/www/example.com/public_html

If the context is wrong, restore it:

sudo restorecon -Rv /var/www/example.com

This is the correct first fix. It restores the SELinux label according to the system policy rather than weakening the entire security model.

Custom Document Roots Outside /var/www

Suppose your application stores files under /srv/websites/example.com. First assign the appropriate web-content context:

sudo semanage fcontext -a -t httpd_sys_content_t "/srv/websites/example.com(/.*)?"
sudo restorecon -Rv /srv/websites/example.com

If semanage is unavailable, install the policy management utilities:

sudo dnf install policycoreutils-python-utils

For directories that Apache must write to, such as upload folders or cache directories, use a writable context:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/srv/websites/example.com/uploads(/.*)?"
sudo restorecon -Rv /srv/websites/example.com/uploads

Do not blindly apply httpd_sys_rw_content_t to an entire site. Read-only content should remain read-only wherever possible.

SELinux and Outbound Connections

Many applications need Apache or PHP to connect to a database, Redis instance, mail relay, or external API. SELinux may block that outbound network connection by default.

Check the relevant boolean:

getsebool httpd_can_network_connect

Enable it persistently only if your application genuinely needs it:

sudo setsebool -P httpd_can_network_connect on

The -P flag makes the setting survive reboots. Avoid enabling broad permissions “just in case.” A better production approach is to enable only the specific capability required by the application.

Install TLS With Let’s Encrypt

Plain HTTP is acceptable for a local test, but any public website should use HTTPS. Certbot and the Apache plugin make certificate issuance and renewal straightforward.

Install Certbot:

sudo dnf install certbot python3-certbot-apache

Issue a certificate for your domain:

sudo certbot --apache -d example.com -d www.example.com

Certbot will modify the Apache configuration to enable HTTPS and redirect HTTP traffic, depending on the options you select. Before running it, make sure DNS for example.com and www.example.com points to the server’s public IP address.

Verify the certificate renewal timer:

systemctl list-timers | grep certbot

Test renewal without making changes:

sudo certbot renew --dry-run

A certificate that cannot renew automatically is a future outage waiting to happen. Schedule a reminder to review renewal logs after the first real renewal cycle.

Apache Modules You May Need

Apache’s modular design keeps the base installation lean while allowing you to enable features when needed. On Fedora, modules are generally enabled through files in /etc/httpd/conf.modules.d/.

Common modules include:

  • mod_ssl: TLS and HTTPS support.
  • mod_rewrite: URL rewriting and redirects.
  • mod_headers: Security and caching headers.
  • mod_deflate: Compression for text-based responses.
  • mod_expires: Browser caching headers.
  • mod_proxy and mod_proxy_http: Reverse-proxy functionality.
  • mod_http2: HTTP/2 support.

Check loaded modules:

httpd -M | less

For a typical modern PHP or reverse-proxy deployment, ensure these are enabled:

sudo dnf install mod_ssl mod_http2
sudo systemctl restart httpd

Be selective. Every enabled module expands the configuration surface and can introduce performance or security trade-offs. Enable what the application needs, then document why.

Performance Tuning for Real Traffic

Apache performs well when configured for the workload in front of it. A small blog, a busy WordPress site, and a high-concurrency API do not have the same requirements.

Start by checking available memory and CPU:

free -h
nproc

For most small to medium VPS deployments, the default Multi-Processing Module configuration is a reasonable starting point. Do not copy aggressive tuning values from a forum post without measuring your own traffic.

Choose the Right MPM

Fedora’s Apache typically uses the event MPM, which is efficient for high-concurrency workloads and supports keep-alive connections well. Confirm it:

httpd -V | grep -E 'Server MPM|threaded'

If you run PHP through mod_php, the prefork MPM may be required because mod_php is not thread-safe. However, PHP-FPM is usually the better modern choice: it separates PHP execution from Apache worker processes and scales more predictably.

Useful Apache Settings

Edit the main configuration carefully:

sudo nano /etc/httpd/conf/httpd.conf

A sensible baseline for a modest server might include:

KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100

Timeout 60

ServerTokens Prod
ServerSignature Off
TraceEnable Off

These directives reduce unnecessary connection overhead, limit request exposure, and remove version details from error pages.

For a reverse-proxy setup, increase connection limits only when your backend can handle them:

<IfModule mpm_event_module>
    ServerLimit 16
    StartServers 3
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxRequestWorkers 400
</IfModule>

Those numbers are examples, not universal recommendations. A 1 GB VPS and a 16 GB dedicated server should not share the same worker limits.

Compression and Caching

Enable compression for text-based assets:

sudo nano /etc/httpd/conf.d/compression.conf

Add:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

Add long-lived caching for static assets:

sudo nano /etc/httpd/conf.d/caching.conf

Add:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/html "access plus 1 hour"
</IfModule>

Test the configuration and reload:

sudo apachectl configtest
sudo systemctl reload httpd

Compression reduces transfer size, while cache headers reduce repeated requests. Together, they often improve perceived performance more than adding CPU or RAM.

Security Best Practices

A web server exposed to the internet is attacked constantly. Automated scanners look for exposed admin panels, outdated software, open directories, and misconfigured services.

Keep the Attack Surface Small

Only open the ports you need. HTTP and HTTPS are usually enough for a standard website. Close unused ports:

sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo firewall-cmd --reload

Fedora explicitly recommends keeping ports closed unless a service requires them.

Hide Unnecessary Information

Add the following to a global or virtual-host configuration:

ServerTokens Prod
ServerSignature Off
TraceEnable Off

This does not make Apache secure by itself, but it avoids giving attackers free version information.

Restrict Directory Access

Deny access to sensitive files:

<FilesMatch "^\.">
    Require all denied
</FilesMatch>

<DirectoryMatch "/\.git">
    Require all denied
</DirectoryMatch>

This prevents exposure of dotfiles and version-control metadata. It is a small configuration change that prevents an embarrassing class of data leaks.

Use Strong File Permissions

Web content should generally be readable by Apache but not writable by it:

sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

Only upload, cache, session, and log directories should be writable by the web-server user, and only when the application requires it.

Monitor Logs

Apache logs are your first diagnostic tool:

sudo tail -f /var/log/httpd/error_log
sudo tail -f /var/log/httpd/access_log

For a multi-site server, check the per-virtual-host logs you defined earlier:

sudo tail -f /var/log/httpd/example.com_error.log

Look for repeated 403, 404, 500, and 503 responses. They often reveal permission problems, broken application code, backend failures, or abusive traffic.

Troubleshooting Common Apache Issues

Apache Fails to Start

Run:

sudo systemctl status httpd --no-pager
sudo journalctl -u httpd -b --no-pager

The most common causes are a syntax error, a port conflict, or an invalid certificate path.

Test the configuration:

sudo apachectl configtest

If the output mentions a syntax error, open the referenced file and correct the line number. Do not restart repeatedly hoping the problem resolves itself.

Port 80 or 443 Is Already in Use

Check what is listening:

sudo ss -ltnp | grep -E ':80|:443'

Another web server, such as Nginx, may already occupy the port. Stop it only if that is intentional:

sudo systemctl stop nginx
sudo systemctl disable nginx

Then start Apache:

sudo systemctl start httpd

Firewall Blocks Traffic

If curl http://localhost/ works but external access fails, inspect firewalld:

sudo firewall-cmd --list-all

Ensure http and, if applicable, https are enabled. Also check cloud security groups, load balancers, and router port-forwarding rules. A firewall rule on the server cannot override a blocked port at the cloud-provider level.

SELinux Denies Access

If Apache returns 403 Forbidden or cannot read a custom document root, inspect denials:

sudo ausearch -m avc -ts recent

Install the troubleshooting tools if needed:

sudo dnf install setroubleshoot setools-console

Then analyze the issue:

sudo sealert -a /var/log/audit/audit.log

The correct response is usually to restore a file context or enable a narrowly scoped boolean. Disabling SELinux should be a last-resort diagnostic step, not a permanent production configuration. Fedora documentation specifically warns that disabling SELinux makes future re-enablement more difficult because persistent objects may no longer be labeled correctly.

Virtual Host Loads the Wrong Site

Check Apache’s parsed virtual hosts:

sudo apachectl -S

Look for the ServerName, port, and document root. A missing ServerName, duplicate wildcard matching, or a virtual host listening on the wrong port can cause unexpected routing.

Permission Denied Errors

Check both traditional permissions and SELinux:

namei -l /var/www/example.com/public_html/index.html
ls -Z /var/www/example.com/public_html/index.html

The first command reveals every directory in the path and its Unix permissions. The second reveals the SELinux label. Both must allow access.

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.

Related Posts