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

前端 未结 12 2102
醉话见心
醉话见心 2020-11-29 15:13

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.<

相关标签:
12条回答
  • 2020-11-29 15:23

    Answers from @Cronk and @Justin got me close on Mac OS X 10.9 Mavericks. In fact, on my system the /etc/php.ini file 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.default and adding the fully qualified path to the mcrypt.so library to the config file solved the problem:

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

    Then in /etc/php.ini add the following line (using the correct path to your mcrypt.so file):

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

    Then restart Apache2:

    apachectl restart
    
    0 讨论(0)
  • 2020-11-29 15:24

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

    enter image description here

    0 讨论(0)
  • 2020-11-29 15:24

    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.

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

    Command line: 5.3.26

    Web: 5.3.13

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

    Command line: /private/etc/php.ini

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

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

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

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

    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.

    To restart apache:

    sudo apachectl -k restart

    -- J

    0 讨论(0)
  • 2020-11-29 15:24

    You run php_info() and see line bellow :)

    Loaded Configuration File   /Applications/XAMPP/xamppfiles/etc/php.ini
    
    0 讨论(0)
  • 2020-11-29 15:30

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

    0 讨论(0)
  • 2020-11-29 15:31

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

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

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

    0 讨论(0)
提交回复
热议问题