Steven Benavides
Steven Benavides

Reputation: 311

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.

Upvotes: 30

Views: 30514

Answers (10)

RanDeh
RanDeh

Reputation: 11

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.

Upvotes: 1

Mantas Lukosevicius
Mantas Lukosevicius

Reputation: 2104

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.

Upvotes: 1

Csongor Halmai
Csongor Halmai

Reputation: 3915

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

Upvotes: 1

Quintin
Quintin

Reputation: 103

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.

Upvotes: 3

rafaelphp
rafaelphp

Reputation: 279

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

Upvotes: 1

Jekis
Jekis

Reputation: 4685

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

Upvotes: 88

Sid
Sid

Reputation: 4512

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

Upvotes: 18

Daniel Centore
Daniel Centore

Reputation: 3349

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.

Upvotes: 1

brettkelly
brettkelly

Reputation: 28235

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

post_max_size=10M

Try that.

Upvotes: 3

Spencer Cameron-Morin
Spencer Cameron-Morin

Reputation: 1430

Have you restarted apache2?

sudo service apache2 restart

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

Upvotes: 6

Related Questions