php ini setting upload_max_filesize not working - php

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

Related

Lightsail Wordpress Instance Restart Apache

I am trying to import a sql file that exceeds the default file size in the phpmyadmin tool. So after some research, I discovered I needed to change some of the variables in the php.ini. Specifically the : upload_max_filesize, memory_limit and post_max_size in the php.ini. Easy enough, then I assumed I needed to restart the apache2 server and I did just that:
sudo /opt/bitnami/ctlscript.sh restart apache
Unmonitored apache
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd stopped
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80
Monitored apache`
However, the limit size did not change in the phpmyadmin tool. I also printed out the phpinfo() command to see if there are multiple versions of the php.ini file which there isn't. So now I am really stuck. Any ideas?
The main php.ini file path :- /opt/bitnami/php/etc/php.ini

Why isn't Php not loading values from php.ini? [duplicate]

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

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.

Opcache does not get enabled

I've installed Apache 2.4.x webserver on Ubuntu and also PHP5.5.x from sources. I go to php installation folder and do find . -name "opcache.so". Then, to php.ini (same as in phpinfo()), I add zend_extension=/php5/lib/php/extensions/no-debug-zts-x/opcache.so, and opcache.enable=On (or 1) and restart Apache with apachectl restart. Then I check phpinfo() but opcache does not get enabled! Please help.
I think a wrong php.ini file might be used, but in phpinfo() it shows the path to file which I do edit. When I change maximum upload filesize from 2M to 4M in the php.ini, and restart Apache, it does not get changed in phpinfo()
Turns out, after compilation PHP would look for the ini file in /usr/local/lib rather than where I installed it despite
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
To check it, you can run php --ini to see if the file has been read fine.
But now I'm seeing white screen when trying to load php files :)
Hope it helps.

Changes to upload_max_filesize in Ubuntu php.ini will not take effect

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Categories