提问人:Carlos Sosa 提问时间:9/14/2023 更新时间:9/14/2023 访问量:177
在 Docker 容器中运行 PHP httpd:latest
Running PHP in Docker Container httpd:latest
问:
所以我正在学习/试验 Docker - 我正在从 Docker Hub 运行 Apache 容器 - 具体来说,我正在运行最新的标签。这是我使用的命令:
docker run --name apacheServer -p 80:80 -v $(PWD)/Apache/htdocs:/usr/local/apache2/htdocs httpd:latest
一切正常,如果我去 http://localhost/,我可以看到指定目录中的索引.html文件。但是,我现在正在尝试将PHP添加到其中,但无法使其工作。这是我到目前为止尝试过的。从容器的交互式 Shell 中,我运行了以下命令。
apt update
apt upgrade -y
apt install php8.2
apt install php libapache2-mod-php -y
做完这个之后。我通过运行 php -v 检查是否安装了 PHP,确实我得到了正确的版本。
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
重新启动apache后,我运行了以下命令:apachectl restart
a2enmod php8.2
我收到以下消息,但是我随后尝试这样做:“Module php8.2 already enabled”
apachectl -M
但 PHP 模块未在列表中列出。这是我得到的清单:
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)
所以这就是我迷路的地方。不知道下一步该怎么做。因为如果我这样做
ls /etc/apache2/mods-available
我可以看到并列出,但两者都不是php8.2.conf
php8.2.load
ls /usr/local/apache2/modules/
libphp8.2.so
作为最后一次尝试,我运行了以下命令;
find /usr/lib/ -name libphp*.so
然后回来了/usr/lib/apache2/modules/libphp8.2.so
我试图通过添加
LoadModule php_module /usr/lib/apache2/modules/libphp8.2.so
但是后来我在重新启动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
任何帮助将不胜感激。
答:
好的,所以我能够弄清楚。
要修复我收到的错误,在添加到配置文件后,我必须注释掉并取消注释。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
LoadModule php_module /usr/lib/apache2/modules/libphp8.2.so
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
(谢谢:https://stackoverflow.com/a/62041173/4585097)。
我还必须添加,这就成功了。Include /etc/apache2/mods-available/php8.2.conf
评论