30

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.

Sid
  • 4,302
  • 3
  • 26
  • 27
Steven Benavides
  • 311
  • 1
  • 3
  • 3

10 Answers10

86

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:

  1. Eval phpinfo();
  2. Search for 'Scan this dir for additional .ini files' text in phpinfo() output
  3. It will be something like this /etc/php5/apache2/conf.d
  4. Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
  5. Use this ini file for custom settings.
  6. 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
Jekis
  • 4,274
  • 2
  • 36
  • 42
18

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

Sid
  • 4,302
  • 3
  • 26
  • 27
6

Have you restarted apache2?

sudo service apache2 restart

The new php.ini configuration is only applied when apache starts.

  • it appears that NO changes I make to the php.ini file are taking affect. Now i know what you will think...I am editing the wrong php.ini file...i have triple checked that I am editing the php.ini file that is displayed via phpinfo – Steven Benavides Jan 14 '13 at 22:20
  • this is article i was referring to about the error in php.ini:http://stackoverflow.com/questions/11662295/php-ini-changes-but-not-effective-in-ubuntu – Steven Benavides Jan 14 '13 at 22:22
  • I looked at the article. It could have just been user error on his part. I've personally never experienced a default install being broken out of the box. I've been using apache with ubuntu for quite a few years now. If you would like, zip up a copy of your php.ini or otherwise make it available and let us take a look at it. – Spencer Cameron-Morin Jan 14 '13 at 22:36
  • FOUND IT...it was an error in the php.ini file...commented out line Development Value: E_ALL | E_STRICT – Steven Benavides Jan 14 '13 at 22:49
  • Hm. How did that get uncommented? O.O – Spencer Cameron-Morin Jan 14 '13 at 22:51
3

You might also need to increase the maximum size of a post:

post_max_size=10M

Try that.

brettkelly
  • 27,655
  • 8
  • 56
  • 72
3

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.

Quintin
  • 103
  • 1
  • 9
1

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.

Daniel Centore
  • 3,220
  • 1
  • 18
  • 39
1

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

rafaelphp
  • 279
  • 2
  • 11
1

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

Csongor Halmai
  • 3,239
  • 29
  • 30
  • Thanks! I just tripped over a similar issue, upgrading from php7.2, where my hash(#) comments were seemingly fine, to 7.3, where they are not. Swapping them all out for semicolons (;) did the trick. – beltouche Sep 09 '20 at 03:46
1

After reading great @Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):

  1. After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory

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

  3. Then I restarted apache (httpd)

And then changes were picked up.

Mantas Lukosevicius
  • 1,914
  • 2
  • 9
  • 13
1

Changes to Ubuntu php.ini will not take effect.

Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.

  1. Check the php version you are running: php -v
  2. Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
  3. Use your favorite editor to fix syntax errors.
  4. 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.

RanDeh
  • 11
  • 4