简体   繁体   English

PHP无法在Mac OS X上使用php.ini文件

[英]php not working with php.ini file on mac os x

I'm running a local server on my macbook (os x 10.9.2) 我在Macbook(OS X 10.9.2)上运行本地服务器

I'm trying to install mcrypt and I've run into a problem that I can't add the extension to my php.ini file, because apparently my php installation doesn't use a php.ini file. 我正在尝试安装mcrypt,但遇到了无法将扩展名添加到php.ini文件的问题,因为显然我的php安装未使用php.ini文件。

Looking at phpinfo(), I see this: 查看phpinfo(),我看到了:

Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)

In my /etc folder, a php.ini file doesn't exist. 在我的/ etc文件夹中,没有php.ini文件。 I do have a php.ini.default, but when I make a copy of that and name it php.ini, and restart apache, PHP just stops working entirely (my php code isn't interpreted and shows up when viewing the web site's source). 我确实有一个php.ini.default,但是当我复制它并将其命名为php.ini并重新启动apache时,PHP完全停止工作(我的php代码无法解释,并且在查看网站的内容时会显示资源)。

Is there something in the php.ini.default file I have to change before copying it to php.ini? 将php.ini.default文件复制到php.ini之前,我必须进行更改吗?

Edit: Upon further trial and error, I have found that if I create a blank php.ini file and restart the server, PHP runs just fine. 编辑:经过进一步的试验和错误,我发现如果我创建一个空白的php.ini文件并重新启动服务器,PHP可以正常运行。 There must be an error in php.ini.default that is killing PHP on my local server. php.ini.default中必须存在一个错误,该错误正在杀死本地服务器上的PHP。 I've tried using php.ini.default~orig too and the same problem happens. 我也尝试过使用php.ini.default〜orig,同样的问题也会发生。 Any way to find out what is wrong with the php.ini.default file? 有什么办法找出php.ini.default文件出了什么问题?

Edit2: Upon further random trial and error, if my php.ini only contains: Edit2:如果进一步的随机试验和错误,如果我的php.ini仅包含:

[PHP]
short_open_tag = On

PHP works. PHP的作品。 If it only contains: 如果仅包含:

[PHP]
short_open_tag = Off

PHP doesn't work. PHP不起作用。 I'm so confused. 我很混乱。

Edit3: Oh! Edit3: 哦! The php.ini.default file had short_open_tag = Off , and of course I'm using short open tags everywhere. php.ini.default文件的short_open_tag = Off ,当然我到处都使用短打开标签。 Edit2 clued me in. Wasted half a day on this. Edit2吸引了我。为此浪费了半天。 This is so embarrassing. 真尴尬 Everything is working now. 现在一切正常。

In case someone else runs into the missing php.ini problem on OS X 10.9 or 10.10: 如果有人在OS X 10.9或10.10上遇到缺少的php.ini问题,请执行以下操作:

I ran into the same problem after trying install the latest php through homebrew. 在尝试通过自制软件安装最新的php后,我遇到了同样的问题。 Turns out mac comes with php already installed, but no config file. 原来mac附带已经安装了php,但没有配置文件。 Homebrew won't overwrite the system php binary, which remains the default. Homebrew不会覆盖系统php二进制文件,它仍然是默认值。

Try sudo rm /usr/bin/php then brew install homebrew/php/php55 . 尝试sudo rm /usr/bin/php然后brew install homebrew/php/php55

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM