PHP CLI on OSX ignores php.ini settings - php

PHP CLI on my Mac OSX ignores memory_limit settings.
I located php.ini using
php -i | grep php.ini
Then I fixed it:
memory_limit = 1024M
I even restarted Apache
sudo apachectl restart
But still when I run
php -i | grep memory_limit
I get
memory_limit => 256M => 256M
What could it be?
Thanks in advance!!!

If you run this command
php --info | grep additional
You may see a result like this:
Scan this dir for additional .ini files => /usr/local/php5/php.d
This indicates that your PHP installation is also scanning an additional folder of .ini files that will augment your configuration - usually these are for extensions but any of these can override the settings that are in your loaded php.ini file. Check whether these are overriding your memory_limit:
cd /usr/local/php5/php.d
grep memory_limit *
In my case I had a developer extensions file that was resetting the memory_limit to 256M, which meant that making changes in php.ini had no effect. Perhaps this is the issue you're having.

CLI PHP may not be using the same php.ini as Apache uses, but you can specify which to use at command line..
php -c path/to/php.ini>|/path/to/php-file-to-run.php

Try to find on this file:
/usr/local/php5/php.d/99-liip-developer.ini # in my case 99- but i think it could be another number
and set this:
memory_limit = -1 #or another value to specify the limit Ex: 521M

Related

MacOS Laravel Valet increase memory_limit

I try to increase the memory_limit of php with Laravel valet.
What I see:
With phpinfo() I see:
memory_limit 128M
Configuration File (php.ini) Path /usr/local/etc/php/7.4
Loaded Configuration File /usr/local/etc/php/7.4/php.ini
Scan this dir for additional .ini
files /usr/local/etc/php/7.4/conf.d Additional .ini files
parsed /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
What I already do
I update php.ini and php-memory-limit.ini to edit the memory_limit from 128M to 256M: memory_limit = 256M
Then I have run the following command: valet restart
I also try to edit /usr/local/etc/php/7.4/php-fpm.d/valet-fpm.conf to add php_admin_value[memory_limit] = 256M
But after that the memory_limit stuck to 128M ( with phpinfo() )
the following command return me 256M: php -i | grep memory_limit
Any idea how to increase this value ?
I found a solution but I didn't understand why it works, but not what I did before. If anyone has an explanation, I'm interested.
I edit /usr/local/etc/php/7.4/php-fpm.d/valet-fpm.conf and replace following line php_admin_value[memory_limit] = 128M
With this line
php_admin_value[memory_limit] = 256M
Then I run the following command:
valet restart
brew services restart php#7.4
With just one of these two commands it doesn't work.
However valet restart is supposed to restart php, right?
One solution worked with me, editing the file:
/usr/local/etc/php/7.2/conf.d/php-memory-limits.ini
And change the value memory_limit, save and run the command (to make sure it was changed):
php -r "echo ini_get('memory_limit').PHP_EOL;"
Then, restart Valet:
valet restart
Check the memory limit using
php -r "echo ini_get('memory_limit').PHP_EOL;"
Then you can check the config file loaded
php --ini
Sometimes there are more than one, so please check all the config files.
I am using Mac intl chip. And in my case file is /usr/local/etc/php/7.4/php-fpm.d/www.conf
and further changes i did same as mentioned right answer.
Thank you so much for answer.
"I found a solution but I didn't understand why it works, but not what I did before. If anyone has an explanation, I'm interested.
I edit /usr/local/etc/php/7.4/php-fpm.d/valet-fpm.conf and replace following line php_admin_value[memory_limit] = 128M
With this line
php_admin_value[memory_limit] = 256M
Then I run the following command:
valet restart
brew services restart php#7.4
With just one of these two commands it doesn't work.
However valet restart is supposed to restart php, right?"

php ini setting upload_max_filesize not working

I need to change upload limit to 2GB on php 7.2 Ubuntu 16.04.
As a first step, when I check /etc/php/7.2 folder I can see cli and
fpm folders.
So to make sure the ini location I have print the php info using
echo phpinfo()
And I got the output
Server API : FPM/FastCGI
Virtual Directory Support : disabled
Configuration File (php.ini) Path : /etc/php/7.2/fpm
Loaded Configuration File : /etc/php/7.2/fpm/php.ini
And I have edited /etc/php/7.2/fpm/php.ini with
upload_max_filesize = 2048M
And restarted the apache but using phpinfo() still it print
upload_max_filesize 2M
So I have tried with command php -i | grep -i "loaded configuration file" but it print different configuration file,
Loaded Configuration File => /etc/php/7.2/cli/php.ini
On this file also I have changed upload_max_filesize to 2048 and restarted the Apache and still the result is same.
What could be the problem, any help will appreciated.
I got the problem resolved by the answer here Changes to upload_max_filesize in Ubuntu php.ini will not take effect.
Instead of restarting the apache I have to restart the php using
sudo service php7.2-fpm restart
You should also change in php.ini:
post_max_size=2Gb
first at all you should remove all older php version on your ubuntu.
what is your cli php version?
are you sure that you find correctly php.ini location?
please run this command " locate php.ini "
Sometimes due to error in php.ini files the configuration files are not loaded after that specific error line. In that case you have to thoroughly check the php.ini file and fix the errors.
Alternatively you can download fresh php.ini files for your php version and replace your existing file with the new one.
After making changes in the new file restart your server using service apache2 restart .
If changing /etc/php/7.2/fpm/php.ini and /etc/php/7.2/cli/php.ini still does not work out, try changing /etc/php/7.2/apache2/php.ini. Please note that you might have to restart the apache2 server using sudo service apache2 restart. (This solution is tested on server with Ubuntu installed. )

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:
"Loaded Configuration File" match the configuration file you changed.
"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:
Do you use php as cli or with Apache/Nginx? (It might be 2 config files)
If you're using Apache, did you restart it? (sudo apachectl -k restart)
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

php 7 php.ini upload_max_filesize not working

I have read many solutions on internet , but still cannot change upload_max_filesize value (upload_max_filesize always = 2M )
here is my loaded php.ini in phpinfo() :
Configuration File (php.ini) Path /etc/php/7.0/apache2
Loaded Configuration File /etc/php/7.0/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.0/apache2/conf.d
upload_max_filesize 2M 2M
post_max_size 8M 8M
here is my edited php.ini in /etc/php/7.0/apache2/php.ini
; http://php.net/post-max-size
post_max_size = 86M
; http://php.net/upload-max-filesize
upload_max_filesize = 40M
im using ubuntu 14.04,apache2,php7.0
(I have reset apache2 many time after each change in php.ini )
I had a fix for PHP-FPM 7.1
Edit your php.ini in
/etc/php/7.1/fpm/php.ini
Make changes to whatever option you want like, post_max_size, upload_max_filesize, max_execution_time & so...
save & close file.
run
sudo service php7.1-fpm restart
It will work!
I had an other fix for it.
os: ubuntu 16.04
phpversion: 7.0
I created a phpinfo.php file containing:
<?php phpinfo() ?>
place the phpinfo.php file in the root of your website www.mywebsite.com/phpinfo.php
Navigating to it and lookup the line:
Loaded Configuration File : /etc/php/7.0/cgi/php.ini
Now you know what php.ini file is loaded.
ssh into the server and use your favorite editing tool (mine is nano) to adjust the php.ini
change the values to meet your preferences.
post_max_size = 128M
upload_max_filesize = 64M
Save and close the file.
Restart apache
sudo service apache2 restart
__
check the phpinfo.ini if the new values are as set.
and if they do you are set to go.
i fingured out !
in my loaded php.ini config , my error_reporting values is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED-> this is wrong!, so i changed it to
error_reporting: E_ALL and then restart apache2 server,
now everything working fine !
so please note : if php.ini have any error , it will use default value (which means upload_max_filesize always 2M )
For php7.2-fpm
Ubuntu php-fpm located at /etc/php/7.2/fpm so
cd /etc/php/7.2/fpm
sudo nano php.ini
Search for post_max_size = 512M and add your fav size that you really needed
Search for upload_max_filesize = 512M and add your fav size that you really needed
Save File
And Last DO NOT FORGET TO RESTART PHP7.2-FPM to restart sudo service php7.2-fpm restart
Thats all!
I also found that restarting the httpd service didn't pick up changes in the loaded configuration file (/etc/php.ini on Fedora 29). It's worth listing all systemd units and doing a grep for the string "php":
# systemctl list-unit-files | grep php
php-fpm.service
Restarting php-fpm did the trick for me:
# systemctl restart php-fpm
I am using Nginx and my solution was to restart php-fpm.
Restarting Nginx didn't do anything.
sudo service php7.2-fpm restart
i also had this problem!
if you are using php-fpm service need to find php-fpm.conf and add line
php_admin_value[upload_max_filesize] = 100M
for changing other type of values
#just for example
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
After spending hours reading forum I've resolved this way:
cd /etc/php
find . -name "*.ini" | xargs grep -il upload_max_filesize
./7.1/apache2/php.ini
./7.1/mods-available/better.ini
./7.1/cgi/php.ini
./7.1/cli/php.ini
./7.1/phpdbg/php.ini
./7.1/fpm/conf.d/20-better.ini
./7.1/fpm/php.ini
./7.1/embed/php.ini
change upload_max_filesize in ./7.1/fpm/conf.d/20-better.ini then
/etc/init.d/php7.1-fpm restart
now phpinfo reports: upload_max_filesize 10G 10G
Hope this helps.
Most people are forgetting to restart their php via the terminal that's why it isn't working, if you think you've done everything correctly be sure to restart your php & the server.
Yeah, Actually I forgot to restart correctly.
sudo service apache2 restart is not enough
first add the configurations to /etc/php/7.1/fpm/php.ini and to /etc/php/7.1/cli/php.ini
#/php/ - then your php version here instead "7.1"
ACtually one of these configuration file is the active one (if you want to see what use <?php phpinfo() ?> command in indextest.php file and check it on browser)
Then change these parameters on each file with what you want:
post_max_size = 512M
upload_max_filesize = 512M
And then use following command to restart the php server:
sudo service php7.0-fpm restart #php<then your php version here> instead "7.0"
or
sudo /etc/init.d/php7.1-fpm restart #php<then your php version here> instead "7.1"
Now you should be able to see the changes of upload size. Cheers !
as shown in here you can get to know more about the php server controlls :
$ sudo service php7.0-fpmstart # <- restart it
$ sudo service php7.0-fpm stop # <- restart it
$ sudo service php7.0-fpm restart # <- restart it
$ sudo service php7.0-fpm reload # <- reload it
create two different files in the root of your project(if you are a Wordpress user,it is the root public_html folder).one is php.ini & the second one is .user.ini
and then simply add these two lines of codes in both files.
upload_max_filesize = 20M
post_max_size = 20M
don't forget to restart the server.
and also make sure the user.ini file must be starting with a dot (.)
systemctl restart apache2
In my case I was editing the wrong one. It turns out I should mondify this /etc/php/7.2/apache2/php.ini
After doing so, it worked!
For those who have all the obvious settings mentioned in other answers and PHP file uploads are stil not working.
Check php.ini for open_basedir value. If a value is set (which it should be for security reasons), make sure that /tmp is included there. Or choose a custom value in upload_tmp_dir and set open_basedir accordingly.
Then reload the FPM service.
I installed multiple versions of PHP on MacOS Big Sur following the steps here
I used command:
sudo /usr/local/bin/httpd -k restart
to load changes made to the php.ini file.
open your putty or bitvise ssh client login your server
sudo apt update
After that
cd /etc/php/7.4/apache2/
see the list to hit command below
ls -ltr
output
total 76
drwxr-xr-x 2 root root 4096 Sep 4 14:31 conf.d
-rw-r--r-- 1 root root 72540 Sep 7 09:28 php.ini
to open php.ini enter the below command
sudo nano php.ini
Move down Arow till not find the Below code
upload_max_filesize = 20M
change 20MB to your desired upload size Press ctrl+s to save php.ini and exit to the editor to command prompt hot ctrl+x after that to reload apache2 hit the below command
sudo systemctl reload apache2
Happy coding

Debian php.ini not updating

I can't seem to get my max_upload_filesize to change despite updating the the php.ini file. Here is a screenshot of the loaded config file, upload_max_filesize in the phpinfo() and the php.ini open along side it:
https://drive.google.com/file/d/0B3b3kShpACJHcFV6YU9XMkdyR0E/view?usp=sharing
after updating the file I've tried:
sudo /etc/init.d/apache2 restart
and I've also tried to stop/start it:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start
the phpinfo() says the config loaded is:
/etc/php5/apache2/php.ini
but when I run:
php -i | grep "php.ini"
it returns the following:
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
So I've updated this config file also to 100M and restarted apache, stop and started it again but yet my phpinfo() is still showing 2M max upload.
What could the problem be?
UPDATE! I have deleted both the php.ini files on my system in etc/php5/cli and etc/php5/apache2 and restarted but it still says its loading the config from etc/php5/apache2 hos is this possible when I've completely removed the file?
Your cli command php and your Webserver use different php.ini files. That why you have to change both of them.
And you have to change post_max_size in your php.ini, too. Otherwise you can't send enough data to your webserver.

Categories