PHP 扩展不会在 Apache 启动时加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/873734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP extensions won't load on Apache startup
提问by KdgDev
I've added php as a module for Apache 2.2.11:
我已将 php 添加为 Apache 2.2.11 的模块:
LoadModule php5_module "c:/php/php5apache2_2.dll"
And also added
并且还添加了
AddType application/x-httpd-php .php
And in PHP.ini, my extension dir is set to: extension_dir = "C:\php\ext"
在 PHP.ini 中,我的扩展目录设置为: extension_dir = "C:\php\ext"
And yes, the directories are correct and all files do exist.
而且是,目录是正确的,所有文件确实存在。
But when I start apache, I get these errors:
但是当我启动 apache 时,出现以下错误:
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pdo_pgsql.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pgsql.dll' - The specified module could not be found.\r\n in Unknown on line 0
[Sun May 17 03:46:01 2009] [notice] Apache/2.2.11 (Win32) PHP/5.2.9-2 configured -- resuming normal operations
[Sun May 17 03:46:01 2009] [notice] Server built: Dec 10 2008 00:10:06
[Sun May 17 03:46:01 2009] [notice] Parent: Created child process 4652
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pdo_pgsql.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pgsql.dll' - The specified module could not be found.\r\n in Unknown on line 0
[Sun May 17 03:46:01 2009] [notice] Child 4652: Child process is running
[Sun May 17 03:46:01 2009] [notice] Child 4652: Acquired the start mutex.
[Sun May 17 03:46:01 2009] [notice] Child 4652: Starting 64 worker threads.
[Sun May 17 03:46:01 2009] [notice] Child 4652: Starting thread to listen on port 80.
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext\php_mysql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext\php_pdo_pgsql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext \php_pgsql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
[Sun May 17 03:46:01 2009] [notice] Apache/2.2.11 (Win32) PHP/5.2.9 -2 已配置 -- 恢复正常操作
[Sun May 17 03:46:01 2009] [notice] 服务器构建时间:2008 年 12 月 10 日 00:10:06
[Sun May 17 03:46:01 2009] [notice] 父:已创建子进程 4652
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext\php_mysql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext\php_pdo_pgsql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext \php_pgsql.dll' - 找不到指定的模块。\r\n 在 Unknown on line 0
[Sun May 17 03:46:01 2009] [notice] Child 4652:子进程正在运行
[Sun May 17 03: 46:01 2009] [notice] 子 4652:获得了启动互斥锁。
[Sun May 17 03:46:01 2009] [notice] 子 4652:启动 64 个工作线程。
[Sun May 17 03:46:01 2009] [notice] 子 4652:启动线程以侦听端口 80。
So I'm probably forgetting something simple here, can someone tell me what I'm forgetting?
所以我可能在这里忘记了一些简单的事情,有人能告诉我我忘记了什么吗?
采纳答案by Pablo Santa Cruz
Not only you need PHP extension's DLLs in order to add MySQL and PostgreSQL support to PHP. You also need MySQL and PostgreSQL native libraries. PHP extension's DLLs are probably not finding some DLL they depend on, so they can't start.
您不仅需要 PHP 扩展的 DLL 才能为 PHP 添加 MySQL 和 PostgreSQL 支持。您还需要 MySQL 和 PostgreSQL 本机库。PHP 扩展的 DLL 可能找不到它们依赖的某些 DLL,因此它们无法启动。
Make sure you have MySQL and PostgreSQL client installed, and their DLLs into some locatable place.
确保您安装了 MySQL 和 PostgreSQL 客户端,并将它们的 DLL 放在某个可定位的位置。
I.E. example:
IE 示例:
- php_mysql.dll depends on libmysql.dll
- php_mysql.dll 依赖于 libmysql.dll
So, make sure PHP is able to find libmysql.dll (I believe this one comes with the binary distribution of Windows PHP. Not sure though).
因此,请确保 PHP 能够找到 libmysql.dll(我相信这是 Windows PHP 的二进制分发版。不过不确定)。
回答by Max Kosyakov
To add to Pablo Santa Cruz's advice. On windows you can include the required libraries in the PATHenvironment. (No necessarily copy to Windows folder). When loading libraries widows looks in PATHdirectories as well.
添加到 Pablo Santa Cruz 的建议中。在 Windows 上,您可以在PATH环境中包含所需的库。(不一定要复制到 Windows 文件夹)。加载库时,寡妇PATH也会查看目录。
If you use standard Win32 binary distribution from php.net for PHP5.2, then the package should contain all the dependencies in the root of the packages. So, if you have installed the PHP5.2 into C:\php, add this directory to the PATHenvar. Restart the Apache and I'd expect extensions to load properly.
如果您为 PHP5.2 使用来自 php.net 的标准 Win32 二进制分发版,则该包应包含包根目录中的所有依赖项。因此,如果您已将 PHP5.2 安装到 中C:\php,请将此目录添加到PATHenvar。重新启动 Apache,我希望扩展能够正确加载。
回答by macbirdie
Those extensions depend on native libraries which are provided by the MySQL and PostgreSQL binary distributions. Install them and put the libs in apache's binfolder for example. Those are LIBMYSQL.DLLand LIBPQ.DLLrespectively.
这些扩展依赖于 MySQL 和 PostgreSQL 二进制发行版提供的本机库。例如,安装它们并将库放在 apache 的bin文件夹中。分别是LIBMYSQL.DLL和LIBPQ.DLL。
I usually do that instead of polluting Windows/System32folder with them, because on my system only the apache/php is the client of those databases and also it makes my apache/php setup more portable.
我通常这样做而不是Windows/System32用它们污染文件夹,因为在我的系统上,只有 apache/php 是这些数据库的客户端,而且它使我的 apache/php 设置更加便携。
回答by Andreas
I had a problem with a specific version of PHP on Windows. The problem was libmysql. I found a posted bug on the php.net site from someone having the same problem.
我在 Windows 上使用特定版本的 PHP 时遇到问题。问题是libmysql。我在 php.net 站点上发现了一个有相同问题的人发布的错误。
I used the previous php release and libmysql worked. Check out the notes on the php distribution you are using. I think that after a specific version they mention a new policy regarding libmysql.
我使用了以前的 php 版本并且 libmysql 工作。查看有关您正在使用的 php 发行版的说明。我认为在特定版本之后,他们提到了有关 libmysql 的新政策。
From what you mention php is unable to find the extensions. Make sure you have set the path on php.ini that specifies where the extensions are located, that the extensions exist and that the folder can be accessed (read-permissions).
根据您提到的 php 无法找到扩展名。确保您已在 php.ini 上设置了路径,该路径指定了扩展程序所在的位置、扩展程序存在并且可以访问该文件夹(读取权限)。
If all fails try moving the extension to windows/system32 in an effort to find what might be the real problem.
如果一切都失败,请尝试将扩展移至 windows/system32 以找出可能是真正的问题。
Regards,
问候,
回答by n3rd
In my experience, PHP on Windows is a major pain in the behind. I usually get it to work eventually, but there's always a lot of googling and trial-and-error involved - for me at least.
根据我的经验,Windows 上的 PHP 是背后的一大痛点。我通常最终让它工作,但总是有很多谷歌搜索和反复试验 - 至少对我来说。
So I finally got sick and tired of it and simply installed Ubuntu Server in a VM and had it up and running within minutes. Whether this is an option for you or not I can't say, but if it is it will most definitely save you a lot of headaches in the long run. Not to mention you can always move your VMs around, create snapshots and do all the other fancy stuff that VMs are good for.
所以我终于厌倦了它,只是在虚拟机中安装了 Ubuntu Server,并在几分钟内启动并运行。我不能说这是否适合您,但如果是,从长远来看,它肯定会为您省去很多麻烦。更不用说你可以随时移动你的虚拟机,创建快照并做所有其他虚拟机适合的花哨的事情。
回答by jbu83
I had the same problem. I was getting one of those annoying windows popup errors everytime I tried to log in to phpmyadmin. I typed in the username and password and then would throw the error.
我有同样的问题。每次尝试登录 phpmyadmin 时,都会遇到令人讨厌的窗口弹出错误之一。我输入了用户名和密码,然后会抛出错误。
What solved it for me, was also copying the libmysql.dl to the apache bin directory. The strange thing is apparantly the extensions where included correctly but still I needed to do this.
为我解决的问题也是将 libmysql.dl 复制到 apache bin 目录。奇怪的是,扩展名显然是正确包含的,但我仍然需要这样做。
回答by AndyJ
I tried several of these solutions and one or more of them worked... Rebooting is the key here. I did not reboot in between these changes, but after I rebooted it was working:
我尝试了其中的几种解决方案,其中一种或多种有效......重新启动是这里的关键。我没有在这些更改之间重新启动,但在我重新启动后它正在工作:
- add postgres DLL to apache lib dir
- add postgres path to system PATH
- add postgres DLL to system32
- 将 postgres DLL 添加到 apache lib 目录
- 将 postgres 路径添加到系统路径
- 将 postgres DLL 添加到 system32
I believe just the PATH would have worked but no time for cleanliness here so there you go.
我相信只有 PATH 会起作用,但没有时间在这里保持清洁,所以你去吧。
回答by farzad
the problem here is that apache has loaded PHP, but PHP was not able to load its extension (mysql, postgresql, ...). I think you should enter path values in your php.ini file in unix format (do not use backslash characters as directory separator). so in your php.ini file change this:
这里的问题是 apache 已经加载了 PHP,但 PHP 无法加载它的扩展(mysql、postgresql 等)。我认为您应该在 php.ini 文件中以 unix 格式输入路径值(不要使用反斜杠字符作为目录分隔符)。所以在你的 php.ini 文件中改变这个:
extension_dir="C:/php/ext"
extension_dir="C:/php/ext"
回答by gnabhan
I'm also had same problem and solved by adding "PostgreSQL" bin path into System Environment variables
我也遇到了同样的问题,并通过将“PostgreSQL”bin 路径添加到系统环境变量中来解决
PATH: C:\Program Files\PostgreSQL\8.4\bin You can check in phpinfo() also.
路径:C:\Program Files\PostgreSQL\8.4\bin 您也可以检查 phpinfo()。
When I install PostgreSQL, setting into System Path missed. I manually added then restart the system.
当我安装 PostgreSQL 时,未设置到系统路径。我手动添加然后重启系统。
回答by DString
I had this problem too, and copied the pertinent (.dlls) to systen 32 and it still did not work for me. I am running Windows 7 64bit. To get this to work for me I had to also copy the libmysql.dll to the ext directory. The error message left the Apache log and the page loaded with a favorable response (conection established).
我也有这个问题,并将相关的 (.dlls) 复制到 systen 32,但它仍然对我不起作用。我正在运行 Windows 7 64 位。为了让它对我有用,我还必须将 libmysql.dll 复制到 ext 目录。错误消息离开了 Apache 日志,页面加载了一个有利的响应(建立了连接)。

