When running Apache HTTP Server (version 2.4.6-18) on CentOS 7, many administrators encounter a frustrating issue where the /run/httpd
directory disappears after every system reboot. This tmpfs directory is crucial for Apache's operation as it stores PID files, shared memory segments, and Unix domain sockets.
The failure manifests through these clear symptoms in your logs:
[auth_digest:error] [pid 3370] (2)No such file or directory:
AH01762: Failed to create shared memory segment on file /run/httpd/authdigest_shm.3370
Systemd shows similar failure patterns:
Sep 30 08:56:09 brejetuba2 systemd:
httpd.service: main process exited, code=exited, status=1/FAILURE
While manually creating the directory fixes the issue temporarily:
# mkdir /run/httpd
# chown root:apache /run/httpd
# chmod 710 /run/httpd
# systemctl restart httpd
This solution doesn't persist across reboots since /run
is a tmpfs filesystem.
Create a systemd unit file to ensure directory creation at boot:
# /etc/systemd/system/httpd-dirs.service
[Unit]
Description=Create Apache runtime directories
Before=httpd.service
[Service]
Type=oneshot
ExecStart=/usr/bin/mkdir -p /run/httpd
ExecStart=/usr/bin/chown root:apache /run/httpd
ExecStart=/usr/bin/chmod 710 /run/httpd
ExecStart=/usr/bin/mkdir -p /run/httpd/htcacheclean
ExecStart=/usr/bin/chown apache:apache /run/httpd/htcacheclean
ExecStart=/usr/bin/chmod 700 /run/httpd/htcacheclean
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Then enable and start the service:
# systemctl daemon-reload
# systemctl enable httpd-dirs.service
# systemctl start httpd-dirs.service
For systems using systemd's tmpfiles.d mechanism:
# /etc/tmpfiles.d/httpd.conf
d /run/httpd 0710 root apache -
d /run/httpd/htcacheclean 0700 apache apache -
This will automatically recreate the directories with proper permissions at boot.
If SELinux is enforcing, you might need to adjust contexts:
# semanage fcontext -a -t httpd_var_run_t "/run/httpd(/.*)?"
# restorecon -Rv /run/httpd
The complete solution combines directory creation, permission management, and SELinux context configuration to ensure Apache starts reliably after every reboot.
On CentOS 7 systems using Apache 2.4.6-18 from official repositories, many administrators encounter a frustrating issue where the /run/httpd
directory gets deleted after every system reboot. This directory is crucial because:
- It stores Apache's PID file (
httpd.pid
) - Contains shared memory segments for authentication
- Holds Unix domain sockets for modules like mod_wsgi
When missing, Apache fails to start with errors like:
[auth_digest:error] [pid 3370] (2)No such file or directory: AH01762: Failed to create shared memory segment on file /run/httpd/authdigest_shm.3370
AH00020: Configuration Failed, exiting
The root cause stems from how systemd and tmpfs interact in CentOS 7:
/run
is a tmpfs (RAM-based filesystem) that gets wiped on reboot- The httpd.service unit file doesn't properly recreate the directory
- Directory creation was only handled during package installation
Method 1: Systemd tmpfiles.d Configuration (Recommended)
Create a configuration file to ensure the directory exists with correct permissions:
# Create configuration file
echo "d /run/httpd 0750 root apache -" | sudo tee /etc/tmpfiles.d/httpd.conf
# Apply changes immediately
sudo systemd-tmpfiles --create
This solution:
- Persists across reboots
- Maintains proper permissions (root:apache, 0750)
- Is the most systemd-native approach
Method 2: Custom Systemd Service Unit
For more control, modify the httpd service:
# Create override directory
sudo mkdir -p /etc/systemd/system/httpd.service.d/
# Create override file
cat << EOF | sudo tee /etc/systemd/system/httpd.service.d/rundir.conf
[Service]
ExecStartPre=/bin/mkdir -p /run/httpd
ExecStartPre=/bin/chmod 0750 /run/httpd
ExecStartPre=/bin/chown root:apache /run/httpd
EOF
# Reload systemd and restart Apache
sudo systemctl daemon-reload
sudo systemctl restart httpd
Method 3: rc.local Fallback (Legacy Systems)
For systems not using systemd-tmpfiles:
# Edit rc.local
echo "mkdir -p /run/httpd && chmod 0750 /run/httpd && chown root:apache /run/httpd" | sudo tee -a /etc/rc.local
sudo chmod +x /etc/rc.local
# Test execution
sudo /etc/rc.local
After implementing any solution, verify with:
# Check directory exists
ls -ld /run/httpd
# Should show:
drwxr-x--- 2 root apache 40 Sep 30 10:00 /run/httpd/
# Test reboot resilience
sudo systemctl reboot
# After reboot:
ls -ld /run/httpd && systemctl status httpd
If issues persist:
# Check SELinux context
ls -Z /run/httpd
# Restore context if needed
sudo restorecon -Rv /run/httpd
# Check audit logs
sudo ausearch -m avc -ts recent | grep httpd
Remember that solutions involving /etc/rc.local
or manual scripts are less ideal than the systemd-native approaches, as they might break during major system updates.