I've see a few other similar questions on here, but most of the answers are Apache specific (dealing with their .htaccess file) and I'm using nginx.
I'm having trouble making my change to the upload_max_filesize in php.ini stick. I'm using nginx, php5 and wordpress on Debian.
When I run phpinfo() I see the following output:
Loaded Configuration File /etc/php5/cgi/php.ini
I then go to the relevant .ini file, change a few values, and then restart nginx. When I fire up a phpinfo() plugin I got for wordpress, it reports the values as unchanged.
I'm at a loss because phpinfo() reports that it is loading config values from the file that I've changed, but it doesn't report the changes.
You might be using FAST CGI:
[webserver] <----> [fcgi daemon]
`- [php]
If you restart the webserver, PHP is not restarted, so still has the old ini values because it didn't reload the ini file.
Restarting the fcgi daemon solves that issue, PHP will be restarted, re-reading the ini.
Some fcgi daemons have a command that reloads the child processes more gracefully. Depends on what you use.
For me the problem was a syntax error in the custom php.ini file, which I found after checking the error logs.
This might help the ones that are using php -i from the terminal to check php.ini settings.
In my case, I increased the upload_max_filesize from 2M to 20 MB by editing /etc/php/7.3/apache2/php.ini and restarted the apache by apachectl restart command.
I used php -i command from the Debian terminal to see the changes are in effect but upload_max_filesize was still 2M.
Then I realized settings readings came from /etc/php/7.3/cli/php.ini because I was using php -i from the terminal instead of phpinfo() function in a web page.
$ sudo service php7.4-fpm restart
Resolved my problem. change the php version to the one you using.
Related
I've had a problem for a while now where I can't upload anything larger than 8 megabytes. I've narrowed it down that it's the actual php.ini file, which is not updating.
So far I've found 3 different php.ini files, all which I've changed the post_max_size to more than the default 8 megabytes. I've tried changing other values too, nothing updates. It's just stuck at 8M
The three different files are located
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/cli/php.ini
/etc/php/7.4/fpm/php.ini
When I add a test.php to my website and do phpinfo(). It tells me that the loaded php.ini file is located in the apache2 folder.
However when I do php --ini in my EC2 instance, it shows that the loaded php file is in the cli folder. Like I said I've edited all of them and double checked, all 3 php.ini HAVE changes to them.
Checking the actual php.ini through the command line with php -info
I found that it actually had accepted the changes. And I guess this is the CLI php.ini, so that one has updated. But not the apache2 or fpm one.
I've tried restarting apache2 service. And restarting fpm service according to: changing php.ini has no effect on my EC2 instance's PHP config
However in my system it's called php7.4-fpm instead of php-fpm.
So for me: sudo systemctl restart php7.4-fpm.service
Nothing works.
I can confirm that the services I am restarting ARE the actual services (Or at least the apache2) I'm viewing live on my website. If I close the apache2 service down, my website will stop working. So I'm confident in that at least. I've tried viewing the files I've edited through just editing them via the command line and downloading through ftp. My changes are apparent all the time, but they are just not apparent in practice.
The EC2 instance I'm running is a t2.xlarge, running: Ubuntu 20.04 LTS (Focal Fossa) LAMP Stack - Linux Apache MySQL/MariaDB PHP
I found a solution for the problem. However a little unconventional, after reading A LOT on the internet finding various solutions and fixes like above mentioned. I finally found something from 7 years ago that still works today!
https://serverfault.com/questions/683026/post-max-size-will-not-change-stuck-at-128m-other-settings-work
Here the OP fixed the problem by editing the virtual host config. I did the same and it turns out doing this actually does changes to the php.ini shown with phpinfo() on the website. Why this is the case, I have no clue, but it's the ONLY way to change specific variables like:
post_max_size
upload_max_filesize
memory_limit
So like the OP of the link you would find the sites-available/000-default.conf wherever it's located in your apache folder usually etc/apache2/sites-available/000-default.conf
Add this before the closing tag </VirtualHost>:
php_value post_max_size 16384M
php_value upload_max_filesize 16384M
Then restart php-fpm (in my case it's called php7.4-fpm) and apache2 services in the command line (I'm using the EC2 instance connect)
sudo systemctl restart php7.4-fpm
sudo systemctl restart apache2
And now you'll see in the phpinfo() that it actually changed the local value of the variables we changed in the apache config.
The master value is still the default, but the site accepts the new local value as the relevant one.
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. )
I just can't get php_info() values to change on my localhost setup, or the related phpMyAdmin maximum file size.
So I have located the PHP file that phpinfo states is being loaded. I have changed the three parameters:
upload_max_filesize
post_max_size
memory_limit
Saved the file, restarted Apache and MySQL, reloaded the phpinfo() page... no changes.
I've also tried putting a .htaccess file in the web root folder with changes to these parameters. This is reflected in phpinfo in the local value (the master value still says 2M for maximum upload size), and then when I go to phpMyAdmin the maximum upload size is still 2M...
I've looked for a php.ini file in C://windows as this is where phpinfo() states the master value is derived from. But there isn't any php.ini file there. So I created one with the values I wanted... no success!
How can I fix this?
I came across the same issue.
Check if php-fpm is running by this command:
ps aux | grep php-fpm
php-fpm stands for "FastCGI Process Manager" for PHP and it was probably built in your system.
If so, you have to restart it. Assuming you are on a Linux system type:
For Red Hat Linux, CentOS, Fedora, etc.
sudo systemctl restart php-fpm.service
For Debian-based systems (like Ubuntu)
sudo service php-fpm restart
or
sudo service php7.0-fpm restart
Don't do what I did... I changed max_input_vars from 1000 to 10000 but never noticed that the line was commented out by default.
; max_input_vars = 10000
I couldn't figure out why the value displayed in phpinfo() wouldn't change.
Doh!
Have you attempted to look for php.ini-development / php.ini-production? If you update php.ini-development and then remove the -development then you should be good to go I believe.
Don't do what I did though and update the php.ini-development file and forget to remove the -development... I spent far too long wondering why the settings weren't updating!
That happen for me, php.ini changes do not affect in phpinfo()
The reason is, that several php-fpm installed into the system and command was not reload config
service php-fpm restart
Proper command to reload service php74-php-fpm restart in my case:
service php74-php-fpm restart
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.
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.