Mac OS X Lion 中的 PHP.ini 在哪里?以为是在 /usr/local/php5/lib

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

Where is PHP.ini in Mac OS X Lion? Thought it was in /usr/local/php5/lib

macosphp

提问by Orun

I wanted to run some PHP right on my Mac, uncommented httpd.conf, activated web sharing, installed MySQL etc. I can't seem to find my PHP files, most importantly, PHP.ini.

我想在我的 Mac 上直接运行一些 PHP,取消注释 httpd.conf,激活网络共享,安装 MySQL 等。我似乎找不到我的 PHP 文件,最重要的是 PHP.ini。

On my old machine it was located in /usr/local/php5/lib But php5 directory doesn't exist in /usr/local..

在我的旧机器上,它位于 /usr/local/php5/lib 但 /usr/local 中不存在 php5 目录。

Do I need to get a package or am I looking in the incorrect place?

我需要拿包裹还是我找错了地方?

Running OS X 10.7.3, PHP 5.3.8, Apache/2.2.21

运行 OS X 10.7.3、PHP 5.3.8、Apache/2.2.21

回答by rkmax

To locate the ini file on your machine, open Terminal.appand run the following command:

要在您的机器上找到 ini 文件,请打开Terminal.app并运行以下命令:

php --ini


If you need a template for Lion, try this.

如果您需要 Lion 的模板,请试试这个

回答by mac

You should find it in /private/etc if it exists, otherwise:

如果存在,您应该在 /private/etc 中找到它,否则:

sudo cp /private/etc/php.ini.default /private/etc/php.ini

回答by SpoBo

In terminal do php -i | grep php.ini. Should give you some clues ;)

在终端做php -i | grep php.ini。应该给你一些线索;)

回答by Peter Gluck

Answers from @Cronk and @Justin got me close on Mac OS X 10.9 Mavericks. In fact, on my system the /etc/php.inifile was missing completely, and it wasn't until I ran phpinfo()on the web server that I observed there was no configuration file. Copying the file from /etc/php.ini.defaultand adding the fully qualified pathto the mcrypt.solibrary to the config file solved the problem:

@Cronk 和 @Justin 的回答让我在 Mac OS X 10.9 Mavericks 上接近了。事实上,在我的系统上,/etc/php.ini文件完全丢失了,直到我phpinfo()在 Web 服务器上运行时才发现没有配置文件。从复制文件/etc/php.ini.default并添加完全合格的路径mcrypt.so库配置文件解决了这个问题:

cp /etc/php.ini.default /etc/php.ini

Then in /etc/php.iniadd the following line (using the correct path to your mcrypt.sofile):

然后/etc/php.ini添加以下行(使用mcrypt.so文件的正确路径):

extension="/usr/local/Cellar/php54-mcrypt/5.4.29/mcrypt.so"

Then restart Apache2:

然后重启Apache2:

apachectl restart

回答by Joat

As pointed out, the php --inicommand will tell you where PHP is expecting to find the php.ini file.

正如所指出的,该php --ini命令将告诉您 PHP 期望在哪里找到 php.ini 文件。

For a standard installation, it's likely to be looking for /etc/php.ini

对于标准安装,它可能正在寻找 /etc/php.ini

If you've used macportsthen PHP may be looking for /opt/local/etc/php5/php.ini

如果您使用过macports,那么 PHP 可能正在寻找/opt/local/etc/php5/php.ini

回答by Robert Rocha

Run phpinfo()from any file and it tells you where it is. Here is a screenshot.

phpinfo()从任何文件运行,它会告诉你它在哪里。这是一个屏幕截图。

enter image description here

在此处输入图片说明

回答by Justin

I have more than once instance of PHP running so the other answers did not work for me. This did:

我不止一次运行 PHP 实例,所以其他答案对我不起作用。这做到了:

Create a PHP file and open its local url in your browser:

创建一个 PHP 文件并在浏览器中打开其本地 url:

<?php phpinfo(); ?>

The PHP.INI path will be listed close to the top.

PHP.INI 路径将列在靠近顶部的位置。

回答by Cronk

This is rather old thread, but I would like to add a further clarification.

这是一个相当老的线程,但我想进一步澄清。

If you have a system that has multiple PHP installations (like mine did) the results you get from using the command line tools MAY BE different than what is actually used by the web server. If you are interested in what PHP is being used by the web server, only use the information gathered from a web page that uses the 'phpinfo()' function.

如果您的系统安装了多个 PHP(就像我的一样),则使用命令行工具获得的结果可能与 Web 服务器实际使用的结果不同。如果您对 Web 服务器正在使用的 PHP 感兴趣,请仅使用从使用“phpinfo()”函数的网页收集的信息。

For example, on my system the versions reported by the two different methods were:

例如,在我的系统上,两种不同方法报告的版本是:

Command line: 5.3.26

Web: 5.3.13

命令行:5.3.26

网络:5.3.13

For the php.ini file path things were different, too:

对于 php.ini 文件路径,情况也有所不同:

Command line: /private/etc/php.ini

Web: /long/path/to/the/file/php.ini

命令行:/private/etc/php.ini

网页:/long/path/to/the/file/php.ini

You can find all the possible php.ini files using this:

您可以使用以下命令找到所有可能的 php.ini 文件:

find / -name php.ini 2>&1 | grep -v "denied" | grep -v "directory"

find / -name php.ini 2>&1 | grep -v "拒绝" | grep -v “目录”

(the '2>&1' and 'grep' elements just restrict the output of the command to useful information, i.e. get rid of error messages)

('2>&1' 和 'grep' 元素只是将命令的输出限制为有用的信息,即消除错误消息)

On my system I found 3 INI files. Because I was interested in what the web server was using I knew that I should use the path returned from the web-page results. I made my changes to the php.ini file that was listed there, restarted apache, and re-ran the web page; the new edits were shown there.

在我的系统上,我发现了 3 个 INI 文件。因为我对 Web 服务器正在使用的内容感兴趣,所以我知道我应该使用从网页结果返回的路径。我对那里列出的 php.ini 文件进行了更改,重新启动了 apache,并重新运行了网页;新的编辑显示在那里。

To restart apache:

重启apache:

sudo apachectl -k restart

须藤 apachectl -k 重启

-- J

——J

回答by CenterOrbit

I start with the 'Hello World!', once I get that displaying in my browser I throw a phpinfo();in there and you can see all of the things. Tells you which configurations are loaded, everything.

我从“Hello World!”开始,一旦我在浏览器中显示了它,我就会phpinfo();在那里扔一个,你可以看到所有的东西。告诉您加载了哪些配置,一切。

<?php
   echo 'Hello World!';

   phpinfo();

回答by Quy Le

You run php_info() and see line bellow :)

你运行 php_info() 并看到下面的行:)

Loaded Configuration File   /Applications/XAMPP/xamppfiles/etc/php.ini