Apache on Windows refuses to start because httpd.conf names a PHP module it cannot find
Syntax error on line 531 of C:/Apache24/conf/httpd.conf: Can't locate API module structure `php8_module' in file C:/php/php8apache2_4.dllShort answer
LoadModule needs the name of the module variable inside the DLL. For PHP 8 that name is php_module, not php8_module and not php7_module. Fix that first, and make sure the DLL is php8apache2_4.dll from the Thread Safe PHP zip, written with forward slashes.
Fix it fast
1Find out which cause you have
Let Apache test its own configuration. It names the line it chokes on. Then print the PHP lines of httpd.conf and look at the first word after LoadModule.
C:\Apache24\bin\httpd.exe -t findstr /n /i "php" C:\Apache24\conf\httpd.conf2Match what you see, then jump to its fix
- 1
The error quotes php8_module (or php7_module) in backticks and the DLL path next to it is right.The LoadModule line uses a module name that PHP 8 does not haveFix - 2
php8apache2_4.dll is not in the PHP folder, and the module cannot be loaded at all.The PHP folder holds the Non Thread Safe build, which has no Apache moduleFix - 3
The path in the error is not the one where you unpacked PHP, or it holds single backslashes.Backslashes or a wrong folder in the pathFix
- 1
What does the error look like?
Syntax error on line 531 of C:/Apache24/conf/httpd.conf: Can't locate API module structure `php8_module' in file C:/php/php8apache2_4.dllApache service will not start after adding PHP to httpd.conf
Cause 1 of 3
The LoadModule line uses a module name that PHP 8 does not have
1Check
The first argument of LoadModule is the name of the module variable that the DLL exports, so a guessed name cannot work. The PHP manual shows php_module for PHP 8 and says the PHP 7 name was php7_module.
findstr /n /i "LoadModule" C:\Apache24\conf\httpd.conf2Fix
Change the name to php_module, keep the DLL that belongs to PHP 8, and use the handler block from the manual.
LoadModule php_module "c:/php/php8apache2_4.dll"
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
PHPIniDir "c:/php"3Verify
The syntax test now ends in Syntax OK, and the module list contains PHP.
C:\Apache24\bin\httpd.exe -t
C:\Apache24\bin\httpd.exe -M | findstr /i phpConfirmed by php.net
Cause 2 of 3
The PHP folder holds the Non Thread Safe build, which has no Apache module
1Check
The manual says that the apache2handler SAPI needs the Thread Safe (TS) build of PHP. A zip marked Non Thread Safe does not meet that requirement.
dir C:\php\php8apache2_4.dll2Fix
Download the Thread Safe zip of the PHP version you want, unpack it into a clean folder, and point LoadModule at the php8apache2_4.dll inside it.
LoadModule php_module "c:/php/php8apache2_4.dll"3Verify
The DLL exists and the syntax test passes.
dir C:\php\php8apache2_4.dll
C:\Apache24\bin\httpd.exe -tConfirmed by php.net
Cause 3 of 3
Backslashes or a wrong folder in the path
1Check
The manual tells you to use forward slashes in Apache's configuration files on Windows, and to put the real PHP location in the LoadModule line.
findstr /n /i "php8apache2_4" C:\Apache24\conf\httpd.conf2Fix
Write the path with forward slashes and point it at the folder that really contains the DLL.
# wrong
LoadModule php_module "c:\php\php8apache2_4.dll"
# right
LoadModule php_module "c:/php/php8apache2_4.dll"3Verify
Run the syntax test again, then restart Apache.
C:\Apache24\bin\httpd.exe -tConfirmed by php.net
How do I stop it coming back?
- After a PHP major upgrade, re-read the install page of the manual and compare it with httpd.conf line by line.
- Run httpd.exe -t before every restart, so a typo fails in the console and does not stop the service.
- Keep PHP in a short path such as c:/php, with no spaces, and reference it only from one place.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
XAMPP Apache will not start: shutdown unexpectedly, port blocked
make_sock: could not bind to address
Apache cannot share a port.
5 causes, each with a fixBack end
PHP inside an .html file is shown as text or ignored
the PHP code shows up as text in the browser
Apache runs PHP only for the file types it is told to hand to PHP, normally .php.
2 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
mod_fcgid: read data timeout in 40 seconds
mod_fcgid logs this when it fails to pass the PHP response on to the client, and returns a 500.
2 causes, each with a fixServers
Composer reports a different PHP version than php -v on Ubuntu
You are running 8.1.2.
Composer takes its PHP version from the interpreter that runs it, unless config.platform fakes one.
3 causes, each with a fixServers
docker-php-ext-install mbstring fails: oniguruma not found
The docker-php-ext-install step exits with a non-zero code
mbstring needs the Oniguruma library to build its regex functions, and the PHP build finds it through pkg-config.
3 causes, each with a fix