php PHPIniDir 在 Windows 7 下坏了?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1912574/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:16:59  来源:igfitidea点击:

PHPIniDir broken under windows 7?

phpapacheapache2apache-config

提问by giroy

I had a server running on a Windows XP machine using Apache2 with PHP and MySQL. I've recently upgraded to Windows 7 and have been having trouble getting it to work. Apache works fine and PHP works, but I can't seem to get it to work with a php.inifile.

我有一台在 Windows XP 机器上运行的服务器,使用 Apache2 和 PHP 和 MySQL。我最近升级到 Windows 7,但一直无法正常工作。Apache 工作正常,PHP 工作正常,但我似乎无法让它与php.ini文件一起工作。

When I set PHPIniDirto a directory with a php.inifile, the Apache service does NOT start.

当我设置PHPIniDir为带有php.ini文件的目录时,Apache 服务不会启动。

When I set PHPIniDirto a directory with NO php.inifile, the Apache service does start.

当我设置PHPIniDir为没有php.ini文件的目录时,Apache 服务会启动。

When I leave out PHPIniDir, the Apache service does not start.

当我离开时PHPIniDir,Apache 服务不会启动。

Has anyone found a fix for this problem? Thanks!

有没有人找到解决这个问题的方法?谢谢!

EDIT :

编辑 :

PHPIniDir "C:\Windows"#works (no php.inifile)

PHPIniDir "C:\Windows"#works(无php.ini文件)

PHPIniDir "C:\Program Files (x86)\php\"#does not work (contains php.inifile)

PHPIniDir "C:\Program Files (x86)\php\"#不起作用(包含php.ini文件)

I enable at most one at any given time.

我在任何给定时间最多启用一个。

采纳答案by Murat

I had the same problem. I fixed it. Open php.ini file with a notepad or any text editor. Disable all of the extension in php.ini file. Comment extensions by one by, and find out which extension causes the problem.

我有同样的问题。我修好了它。使用记事本或任何文本编辑器打开 php.ini 文件。禁用 php.ini 文件中的所有扩展名。逐个注释扩展名,并找出导致问题的扩展名。

回答by ar2r

delete last slash:

删除最后一个斜杠:

PHPIniDir "C:\Program Files (x86)\php"

回答by Murat

There are several reasons:

有几个原因:

  • Old version of Apache and/or PHP. Apache 2.2.13/2.2.14 seem to work fine in Windows 7, as well as PHP 5.2.11/5.3.
  • Some of PHP extensions may cause the Apache startup failure. You may either check Apache's log files or enable 'display_startup_errors' in php.ini (when it's enabled you may use ApacheMonitor.exe to start or stop the Apache service, and if an error occurs, it'll display a message). You may also disable all PHP extensions and if it helps start enabling them one by one and see which one is causing the problem.
  • Imho, make sure you've downloaded an archive of PHP and didn't use the automated installer. In my experience, installers never worked well. You can always add two PHP-related directives (PHPIniDir and LoadModule) into Apache's config file and make sure PHP dir is included in Windows' path. Oh, and service error may also be caused by php2apache library.
  • Check if Apache/PHP/MySQL directories are included into Windows' path. Here is a good utility to do that: Redmond Path. You may add the following directories into the path: Apache/bin dir, PHP dir, MySQL/bin dir. It might help.
  • 旧版本的 Apache 和/或 PHP。Apache 2.2.13/2.2.14 在 Windows 7 和 PHP 5.2.11/5.3 中似乎运行良好。
  • 某些 PHP 扩展可能会导致 Apache 启动失败。您可以检查Apache 的日志文件或在php.ini 中启用'display_startup_errors'(启用后您可以使用ApacheMonitor.exe 启动或停止Apache 服务,如果发生错误,它会显示一条消息)。您还可以禁用所有 PHP 扩展,如果它有助于开始一一启用它们,看看是哪个导致了问题。
  • 恕我直言,请确保您已经下载了 PHP 存档并且没有使用自动安装程序。根据我的经验,安装程序从来都不是很好。您始终可以将两个与 PHP 相关的指令(PHPIniDir 和 LoadModule)添加到 Apache 的配置文件中,并确保 PHP 目录包含在 Windows 的路径中。哦,服务错误也可能是php2apache库引起的。
  • 检查 Apache/PHP/MySQL 目录是否包含在 Windows 的路径中。这是一个很好的实用程序:Redmond Path。您可以将以下目录添加到路径中:Apache/bin 目录、PHP 目录、MySQL/bin 目录。它可能会有所帮助。

回答by Tungsten Carbide Rings

I had the same problem, you have to specify the full URL for the PHP module in the httpd.conf.

我遇到了同样的问题,您必须在 .php 文件中指定 PHP 模块的完整 URL httpd.conf

All of the guides that I have found said to put the following:

我发现的所有指南都说要放置以下内容:

PHPIniDir "C:/Program Files/PHP"
LoadModule php5_module "php5apache2_2.dll"

When in actual fact you need:

实际上,当您需要时:

PHPIniDir "C:/Program Files/PHP"
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"

回答by Dave Grossman

I was never able to get beyond this line:

我永远无法超越这条线:

LoadModule php5_module "C:/Program Files (x86)/PHP/php5apache2_2.dll"

LoadModule php5_module "C:/Program Files (x86)/PHP/php5apache2_2.dll"

So finally in desperation I created a new folder C:/PHP, copied that dll into C:/PHP and changed the line to

所以最后在绝望中我创建了一个新文件夹 C:/PHP,将该 dll 复制到 C:/PHP 并将该行更改为

LoadModule php5_module "C:/PHP/php5apache2_2.dll"

LoadModule php5_module "C:/PHP/php5apache2_2.dll"

And for the first time it all worked! Maybe it just doesn't like spaces in the path. Or maybe it doesn't like long path names. I dunno. It's likely that this fix is specific to a particular version of Apache and PHP, but after spending about 20 hours on this problem, I'm so bleary that I don't know what that dependency might be.

这是第一次这一切都奏效了!也许它只是不喜欢路径中的空格。或者它可能不喜欢长路径名。我不知道。此修复程序可能特定于特定版本的 Apache 和 PHP,但在解决此问题大约 20 小时后,我感到非常疲倦,以至于我不知道该依赖项可能是什么。

回答by priki

I had this problem too, but I could get Apache to work again by disabling all the extensions in the php.ini file (I had all the DLL in the ext folder, but they were disabled in the php.ini) Since I wanted to use all the php extensions, I tried disabling one by one to see which ones were crashing Apache. I also did install PHP in the C:, to avoid "blank space/long path" problems. In the end, here is how my Apache's httpd.conf file is, in the part of PHP:

我也有这个问题,但我可以通过禁用 php.ini 文件中的所有扩展来让 Apache 再次工作(我在 ext 文件夹中有所有 DLL,但它们在 php.ini 中被禁用)因为我想使用所有的 php 扩展,我试着一一禁用,看看哪些会导致 Apache 崩溃。我也确实在 C: 中安装了 PHP,以避免“空格/长路径”问题。最后,这是我的 Apache 的 httpd.conf 文件的方式,在 PHP 部分:

#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:\PHP"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

Also, the extensions that was crashing apache was:

此外,导致 apache 崩溃的扩展是:

  • php_oci8.dll
  • php_pdo_oci.dll
  • php_pdo_oci8.dll
  • php_pdo_sqlite_external.dll
  • php_pspell.dll
  • php_sybase_ct.dll
  • php_oci8.dll
  • php_pdo_oci.dll
  • php_pdo_oci8.dll
  • php_pdo_sqlite_external.dll
  • php_pspell.dll
  • php_sybase_ct.dll

I really don't know what's wrong with them, though.

不过,我真的不知道他们有什么问题。

Please, note that I installed PHP by using the msi installer (php-5.2.17-Win32-VC6-x86.msi) and I installed ALL the extensions. I'm also using Windows 7.

请注意,我使用 msi 安装程序 (php-5.2.17-Win32-VC6-x86.msi) 安装了 PHP,并且我安装了所有扩展。我也在使用 Windows 7。

回答by Alberto Martinez

As an alternative to the @ar2r answer of deleting the last backslash, you can write the path using (forward) slashes and it would work even with an slash at the end. For some reason using a backslashat the endof a path doesn't works in recent versions of Windows:

作为删除最后一个反斜杠的@ar2r 答案的替代方法,您可以使用(正)斜杠编写路径,即使末尾有斜杠也可以使用。对于使用某种原因反斜杠年底的路径不工作在最近版本的Windows:

# works, no slash or forward slash at the end
PHPIniDir "C:\Program Files\PHP7"
PHPIniDir "C:/Program Files/PHP7/"
PHPIniDir "C:\Program Files\PHP7/" # mixing slashes and backslashes

# doesn't works, backslash at the end
PHPIniDir "C:\Program Files\PHP7\"

Note that mixing forward and backslashes works as long as the trailing slash is nota backslash.

请注意,只要尾部斜杠不是反斜杠,混合正斜杠和反斜杠就可以工作。

This applies also to other directives, I noticed this behavior when configuring the Aliasfor the icons of the directory index.

这也适用于其他指令,我在配置Alias目录索引的图标时注意到了这种行为。