Apache 2.2 phpinfo() 配置文件 (php.ini) 路径与 httpd.conf 不匹配

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

Apache 2.2 phpinfo() Configuration File (php.ini) Path doesn't match httpd.conf

apachephphttpd.conf

提问by user1513171

I am trying to set up Apache to work with PHP. It seems to be working because I can run a file index.php from my "example" directory which is within htdocs in Apache. However, when I look at the Configuration File (php.ini) Path on the phpinfo() screen it does not match what I have in httpd.conf. Also, my modules that are turned on within my php.ini file are not set to enabled.

我正在尝试设置 Apache 以使用 PHP。它似乎有效,因为我可以从我的“示例”目录运行文件 index.php,该目录位于 Apache 的 htdocs 中。但是,当我查看 phpinfo() 屏幕上的配置文件 (php.ini) 路径时,它与我在 httpd.conf 中的内容不匹配。此外,在我的 php.ini 文件中打开的模块未设置为启用。

So I think it is not getting my php.ini. On the phpinfo() screen it says the Path is C:\Windows.

所以我认为它没有得到我的 php.ini。在 phpinfo() 屏幕上,它说路径是 C:\Windows。

In my httpd file in the conf directory of Apache I have this:

在我的 Apache conf 目录中的 httpd 文件中,我有这个:

.
.
.
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule php5_module C:/php/php5apache2_2.dll
PHPIniDir "C:/php/"

All of these files exist. However this is not even a php.ini at C:\Windows.

所有这些文件都存在。然而,这甚至不是 C:\Windows 中的 php.ini。

You may say that maybe my httpd.conf file isn't being read. However, if I change the php5_module line to something like

你可能会说也许我的 httpd.conf 文件没有被读取。但是,如果我将 php5_module 行更改为类似

LoadModule php5_module C:/php/incorect.dll

Apache fails to start up. So this is being read. Just my php.ini isn't being read. Why? Thanks for the help!

Apache 无法启动。所以这是正在阅读。只是我的 php.ini 没有被读取。为什么?谢谢您的帮助!

EDIT:Also want to mention, on the phpinfo() screen, Loaded Configuration File is displaying as (none). Not sure what this is even talking about, but just some more insight to those of you who do.

编辑:还想提一下,在 phpinfo() 屏幕上,加载的配置文件显示为(无)。不确定这甚至在谈论什么,但只是对你们中的那些人有更多的了解。

Oh, and PHP version is 5.4.6.

哦,PHP 版本是 5.4.6。

EDIT 2:Windows Version: Windows 7 Professional Service Pack: Service Pack 1

编辑 2:Windows 版本:Windows 7 Professional Service Pack:Service Pack 1

回答by Edward Ruchevits

Change:

改变:

PHPIniDir "C:/php/"

To:

到:

PHPIniDir "C:/php"

Load module:

加载模块:

LoadModule php5_module "c:/php/php5apache2_2.dll"

Add PHP handler:

添加 PHP 处理程序:

AddHandler application/x-httpd-php .php

Update directory index (optionally):

更新目录索引(可选):

DirectoryIndex index.php index.html

Include "c:\php" to the end of your Pathvariable.

Path变量的末尾包含“c:\php” 。

回答by user1793575

SOLVED - Can't be forward slashes, have to be back. took

已解决 - 不能是正斜杠,必须返回。拿

PHPIniDir "C:\srv\php5_4_8\"

回答by pang

My System: Windows with apache 2.2, php 5.3

我的系统: Windows with apache 2.2, php 5.3

Symptoms: PDO drivers not found.

症状: PDO drivers not found.

What I found: phpinfo() showed that the php.ini file was "C:\Windows"even though I expected it to be "C:\Program Files (x86)\PHP\"as specified in my httpd.conffile in apache\conf

我发现了什么: phpinfo() 显示 php.ini 文件"C:\Windows"即使我希望它与"C:\Program Files (x86)\PHP\"我的httpd.conf文件中指定的一样apache\conf

Problem was with the PHPIniDirstring in httpd.confso the php.inifile I intended to use was not found.

问题出在PHPIniDir字符串中,httpd.conf因此php.ini找不到我打算使用的文件。

FAILED:

失败的:

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

WORKED:

工作:

PHPIniDir "C:\Program Files (x86)\PHP"
PHPIniDir "C:/Program Files (x86)/PHP"
PHPIniDir "C:/Program Files (x86)/PHP/"

NOTICE:the extra "\" in the FAILED case. Remove it, save the conf file, and restart apache. Now phpinfo should show the php.ini file as coming from "C:\Program Files (x86)\PHP" and the PDO drivers had been loaded.

注意:FAILED 情况下的额外“\”。删除它,保存conf文件,然后重新启动apache。现在 phpinfo 应该显示 php.ini 文件来自“C:\Program Files (x86)\PHP”,并且 PDO 驱动程序已经加载。

回答by Rushabh

I found a way to install it properly, on IIS 7:

我找到了一种在 IIS 7 上正确安装它的方法:

Set IIS to allow 32-bits if you are on 64-bits

如果您使用的是 64 位,请将 IIS 设置为允许 32 位

cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1

cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1

Set enviroment variables

设置环境变量

PATH to, say, C:\php\

路径到,比如说,C:\php\

PHPRC to, that same dir

PHPRC 到,同一个目录

Go to Web Service Extensions: Add a new extension...

转到 Web 服务扩展:添加新扩展...

Name it for example php, and point it to the php5isapi.dll.

将其命名为例如 php,并将其指向 php5isapi.dll。

Set status to Allowed.

将状态设置为允许。

Right click Web Sites:

右键单击网站:

On the tab, ISAPI Filters, name it for example php, and point it to the php5isapi.dll

在选项卡 ISAPI 过滤器上,将其命名为例如 php,并将其指向 php5isapi.dll

Then go to Home directory tab:

然后转到主目录选项卡:

Click Configuration

点击配置

On Mappings, click add:

在映射上,单击添加:

Executable would be: php5isapi.dll Extension to: .php

可执行文件是:php5isapi.dll 扩展到:.php

Click OK, then OK.

单击“确定”,然后单击“确定”。

Then on the tab Documents click Add:

然后在选项卡文档上单击添加:

and add there what you want to load as default, say index.php

并在那里添加你想要加载的默认值,比如 index.php

Then stop, and start IIS.

然后停止,并启动 IIS。

This worked for me on a Windows 2003 Server, and WinXP 64.

这在 Windows 2003 Server 和 WinXP 64 上对我有用。

I hope this works for you too.

我希望这也适用于你。

回答by Shubham Goyal

I was facing exactly the same issue.

我面临着完全相同的问题。

In my case, the problem was that I had saved the php.ini file as a text file. As soon as I converted the text file to "All Files" in notepad and gave it the ".ini" extension, it became a "Configuration Settings File" and it worked.

就我而言,问题是我将 php.ini 文件保存为文本文件。一旦我在记事本中将文本文件转换为“所有文件”并给它一个“.ini”扩展名,它就变成了一个“配置设置文件”并且它起作用了。

(Working on Windows)

(在 Windows 上工作)

回答by Darius Miliauskas

Since I am running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was very sensitive to slashes. I needed to change from

由于我运行的是 Windows 7(Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a),文件“httpd.conf”中的语法(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf \httpd.conf) 对斜杠非常敏感。我需要改变

PHPIniDir 'c:\PHP'

PHPIniDir 'c:\PHP'

to

PHPIniDir 'c:\PHP'

PHPIniDir 'c:\PHP'

Pay the attention that the last slash disturbed everything!

注意最后一个斜线扰乱了一切!