6

I can't seem to get the php.ini file in the website's root (/var/www) to override the php.ini value in /etc/php5/apache2

/var/www/php.ini contents

upload_max_filesize = 64M
post_max_size = 64M

But a phpinfo() page in the same directory shows the default values for them 2M and 8M respectively. And wordpress shows that the max upload size is 2MB.

OS: Ubuntu 14.04 LTS PHP: 5.5.9-1ubuntu4

Any thoughts?

3
  • 3
    Why do you think a php.ini file in the wrong directory would be read? Jul 25, 2014 at 20:13
  • the phpinfo page will also show you from where it is reading the php.ini file. You can remove the default and put your new one there, or symlink it to yours. Jul 25, 2014 at 20:14
  • 2
    @MichaelHampton, You are able to put an INI file in directory of your website as well and it is supposed to override the values of the master INI file. Jul 25, 2014 at 20:18

4 Answers 4

6

If you are using PHP >= 5.3, then you can override configs per directory by creating a file called .user.ini.

In your case, I believe it's the filename that is the problem.

The name of the file is configurable in your primary php.ini as user_ini.filename. If that is set to an empty string, then the feature is disabled.

4

In addition to ".user.ini", another way to do it on production web server/system-wide is to create a /etc/php/x.x/apache2/conf.d/99-custom_overrides.ini (or similar name) so it's read in last.

(x.x = your PHP version currently used on Apache)

Just put the directives you wish to override in that file and save it.
For example:

display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On
upload_max_filesize = 8M
post_max_size = 32M

Then restart webserver and recheck your phpinfo() webpage. Check the area "Additional .ini files parsed" to see if it's reading your .ini last. If you do not see the file, you did something wrong and values will not be overridden. If you do, check same page to see the value are now being overridden.

Example phpinfo() displaying Additional .ini parsing areas

That way you will not wipe it out on a system file update. Directly editing 'php.ini' is not advisable.

Please note: This is based on a Debian/Ubuntu package/repo version of PHP 5.x or 7.x. The conf.d or 'scan directory' area needs to be set and adjusted if you compile it yourself.

Also answered here: https://stackoverflow.com/a/39669862/503621

3

You can also do this via the command line

php --ini
Configuration File (php.ini) Path: /etc/php/7.0/cli
Loaded Configuration File:         /etc/php/7.0/cli/php.ini
Scan for additional .ini files in: /etc/php/7.0/cli/conf.d
0

Hello you just got to do this open the phpinfo() page in the browser from your web server directory.

Then take note of the location directive that says the source of the php.ini file being loaded and then open it as a superuser and find the max_filesize directive and set it accordingly.

The file section is as follows and tells you which file to find and edit. Cherio! enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .