Case Study

Switching SELinux to enforcing broke the database connection, and the audit log had nothing to show

We were moving a WordPress site to a new server, and part of the job was running it with SELinux enforcing instead of switched off. The trial run in permissive mode showed nothing to fix. The moment we enforced, the homepage returned a 500 while everything else kept working, and the audit log still showed nothing. The denial was there, hidden by a rule that suppresses logging. MariaDB, installed from its own repository, carried the wrong file label and ran outside SELinux’s database policy. One labelling rule fixed it, before the new server went live.

August 2026  ·  4 min read

SECTOR

Organisation moving its website to a new server

SCALE

WordPress migration with SELinux hardening

PLATFORM

Oracle Linux 9, nginx, PHP-FPM, MariaDB 10.5 from the MariaDB repository

ENGAGEMENT

Pre-launch: homepage 500 after enforcing SELinux

500 → 200

Homepage with SELinux enforcing, before and after the fix

0 log entries

For the denial that broke the site, until logging suppression was switched off

87 GB

Of website files relabelled before SELinux was switched on

Environment

One wrong label, one hidden denialThe MariaDB server binary carried the generic bin_t label, so MariaDB ran unconfined. PHP-FPM, confined as httpd_t, was then not allowed to connect to the MariaDB socket, and the denial was hidden by a dontaudit rule. Labelling the binary mysqld_exec_t made MariaDB run as mysqld_t, and PHP could connect again.One wrong label, one hidden denialPHP-FPMhttpd_tWordPressconnect to mysql.sockdenied, not loggedhomepage 500MariaDBbinary labelled bin_tran unconfinedPHP-FPMhttpd_tconnect to mysql.sockallowed, homepage 200MariaDBmysqld_exec_t → mysqld_tTop: as installed. Bottom: after one file-context rule and a restart.

Scroll the diagram sideways to see all of it →

The policy did exactly what it should. The binary was simply not labelled as a database server.

The problem

From disabled to enforcing, the careful way. SELinux had been turned off with selinux=0 on the kernel command line, and our standard is to run enforcing. We removed that from every boot entry and prepared the policy first: PHP-FPM’s port allowed for the web server, write labels on the WordPress folders that need them (uploads, cache, upgrade), labels on MariaDB’s log and file folders, and the booleans that let the web server talk to a database and to the network. Then permissive mode with a full relabel, 87 GB of files, and a reboot. In permissive mode SELinux logs what it would block but blocks nothing, so it is the usual dress rehearsal. It reported no denials, and a write test passed. When we switched to enforcing, the homepage returned a 500. Redirects, the login page’s password protection and static files all still worked.

Investigation

The denial was there. It was just not being logged. PHP’s error was mysqli_real_connect(): (HY000/2002): Permission denied: it could not open MariaDB’s socket. The audit log showed no denial. SELinux ships dontaudit rules that silence denials considered noisy and harmless, and this was one of them. Running semodule -DB rebuilds the policy with those rules disabled, and the denial appeared at once: avc: denied { connectto } from PHP-FPM, with MariaDB running as unconfined_service_t. MariaDB’s binary, /usr/sbin/mariadbd from the MariaDB.org package, carried the generic bin_t label instead of mysqld_exec_t. So it started outside the database policy, and the rule that lets the web server connect to the database socket did not apply to it.

Permissive mode said there was nothing to fix. The denial was there all along, behind a rule that tells SELinux not to log it.

What the dress rehearsal missed

Permissive mode cannot show what is never logged. The permissive run was supposed to catch this, and it could not have. A dontaudit rule hides a denial in permissive mode just as it does in enforcing mode, so an empty log only means nothing loggable happened. Our own permissive check was weaker still: the step that listed denials hit a scripting error, so its “zero” was never strong evidence. The test that found the problem was the plain one: request the homepage with SELinux enforcing and look at the status code.

At a glance

Challenge

A WordPress server being moved to SELinux enforcing: the homepage returned 500 as soon as enforcing was switched on, with nothing in the audit log.

Approach

semodule -DB exposed a hidden denial: MariaDB’s binary had the generic bin_t label, ran unconfined, and PHP could not reach its socket.

Result

One file-context rule for the binary, a restart, and the hiding rules switched back on. Homepage 200, all checks passed, before go-live.

The fix

  1. Label the binary as a database server: semanage fcontext -a -t mysqld_exec_t '/usr/sbin/mariadbd', so the rule is stored in the local policy, then restorecon on the file
  2. Restart MariaDB and confirm it now runs as mysqld_t; the database domain was kept permissive only for the minutes of this change
  3. Remove the temporary permissive domain, so the whole system is enforcing
  4. Switch the logging suppression back on with semodule -B, so the log is not flooded
  5. Test the whole stack, not one page: homepage, redirect, login protection, static files, robots.txt, the blocked xmlrpc.php, an upload write, and a WordPress database query

Outcome

Enforcing, with every check as expected. With SELinux enforcing, the homepage returned 200, the redirect 301, the protected login 401, static files and robots.txt 200, and xmlrpc.php 403 as intended. Uploads could be written, and a WordPress query returned all 1,128 option rows. All of this happened before the new server took any visitor traffic. What was not done in this window: a cold reboot to confirm the final state comes back on its own, and a test after a MariaDB package update. A separate, repeating denial from PHP-FPM was also in the log and was left for later, so we do not claim a clean audit log. The lessons we take: an empty audit log is not proof, and software installed from a vendor’s own repository needs its SELinux labels checked by hand.

More case studies

nginx Open Files Limit Under SELinux

1,024 → 65,000 open files per worker, verified live

Monitoring Checks Blind Under SELinux

73 / 0 items after the fix, none unsupported

41 GB WordPress News Site Migration

76,548 posts, the same count on both servers

Want SELinux on, without breaking the site?

We move servers to enforcing mode step by step, find the denials that never show up in the log, and test the whole stack before go-live.