Issue
So I’m learning/experimenting with Docker - and I’m running the Apache Container from Docker Hub - Specifically I’m running the latest tag. Here is the command that I used:
docker run --name apacheServer -p 80:80 -v $(PWD)/Apache/htdocs:/usr/local/apache2/htdocs httpd:latest
Everything is working fine, if I go to http://localhost/ I can see the index.html file in the specified directory. However I’m now trying to add PHP to it and can’t get it to work. This is what I have tried so far. from the Container’s Interactive Shell I ran the following commands.
apt update
apt upgrade -y
apt install php8.2
apt install php libapache2-mod-php -y
After doing this. I checked if PHP was installed by running php -v Indeed I got the correct version.
PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
After restarting apache with apachectl restart
I ran the following command:
a2enmod php8.2
And I got the following message “Module php8.2 already enabled”
However I then tried doing:
apachectl -M
but the PHP module is not listed in the list. this is the list I got:
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (shared)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
So here is where I’m lost. Not sure what to do next. Because If I do
ls /etc/apache2/mods-available
I can see php8.2.conf
and php8.2.load
list but not in ls /usr/local/apache2/modules/
neither is libphp8.2.so
As a last try I ran the following command;
find /usr/lib/ -name libphp*.so
and got back /usr/lib/apache2/modules/libphp8.2.so
I tried to manually add that file on the /usr/local/apache2/conf/httpd.conf file by adding
LoadModule php_module /usr/lib/apache2/modules/libphp8.2.so
But then I got the following error message when restarting apache: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed
Any help would be greatly appreciated.
Solution
Ok So I was able to figure it out.
To fix the error Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed
that I was getting, after adding LoadModule php_module /usr/lib/apache2/modules/libphp8.2.so
to the configuration file I had to comment out LoadModule mpm_event_module modules/mod_mpm_event.so
and uncomment LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
.
(Thanks: https://stackoverflow.com/a/62041173/4585097).
I also had to add Include /etc/apache2/mods-available/php8.2.conf
and that did the trick.
Answered By - Carlos Sosa Answer Checked By - Dawn Plyler (WPSolving Volunteer)