简体   繁体   中英

How update php.ini on a Mac OS X Mojave?

I'm on Mac OS X Mojave

Step 1

I ran

php -i | grep php.ini

I got

Configuration File (php.ini) Path => /usr/local/php5/lib
Loaded Configuration File => /usr/local/php5/lib/php.ini

Step 2

I open up the ini file

vi /usr/local/php5/lib/php.ini , 

and update memory_limit to -1 

在此处输入图像描述

Step 3

I ran

php -i | grep memory_limit

I got

memory_limit => 256M => 256M                                                                                      

Step 4

I restart my

sudo apachectl -k restart

and type in my password

and tried

php -i | grep memory_limit

again, I still got

memory_limit => 256M => 256M                                                                                      

Seems like my chages never take any effect...

Do I need to start any service on a Mac? If so, what command to do that?

phpinfo

在此处输入图像描述

Edit:

Create an empty php file with:

<?php phpinfo(); ?>

Load it with your web browser (localhost/yourfile.php).

Check that:

  1. "Loaded Configuration File" match the configuration file you changed.
  2. "memory_limit" has the value it is supposed to have.

I usually install a "clean" php using Brew . So here a few questions to be sure:

  1. Do you use php as cli or with Apache/Nginx? (It might be 2 config files)
  2. If you're using Apache, did you restart it? (sudo apachectl -k restart)
  3. Did you try with a more conventional value (like 2048M)? I'm not sure -1 is always supported.

The answer is simple.

The PHP INI file which you have edited and the INI file that is loaded in Apache server is different..

You have to update the PHP loader in the apache httpd.conf file.

After that restart the apache server with sudo apachectl restart .

Finally, now you can test the PHP ini file loaded in apache2 with phpinfo();

Though It is old question still many people struggle. So thought to answer it.

  • Installed php.ini is located at /usr/local/php5/lib/php.ini (or it can be at /usr/local/etc/php/7.3/php.ini )

  • php.ini used by Apache are different, which is /etc/php.ini.

    vi /usr/local/php5/lib/php.ini

so above changes to php.ini does not reflect in Apache. Solution is to point to correct PHP in your apache config file.

sudo vi /etc/apache2/httpd.conf

Search for pattern "LoadModule php" and comment the existing line with libexec and add below line to your installation.

#LoadModule php7_module libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so

Restart your apache

sudo apachectl restart

Check log file

tail -f  /var/log/apache2/error_log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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