How can we help you today?

How to Override PHP Settings

Created by: Rens Zuurbier

Modified on: Tue, 16 Jun, 2020 at 3:40 PM


Introduction

Sometimes you want to use software inside your Magento shop, that require some other settings for PHP then the defaults supply. For example changing the `max_execution_time` for a PHP script in a certain directory.

TABLE OF CONTENTS

What settings can be overriden

Some examples of settings you might want to override are:

  • upload_max_filesize
  • post_max_size
  • max_execution_time

PHP uses several modes to adjust settings. These modes determine when and where a PHP setting can be set or changed and by who.

For example, some settings may be set within a PHP script using ini_set(), whereas others that may only be changed by server administrators are set in the `php.ini` file in /etc/php*.

Every PHP setting has it's own mode and thus a place to configure. If a setting can be set in a .user.ini, you have the ability to change or adjust this setting yourself manually by adding it to .user.ini in a specific directory.

ModeMeaning
PHP_INI_ALLThis entry can be set anywhere
PHP_INI_USERThis entry can be set in user scripts (with ini_set() or with a .user.ini.
PHP_INI_PERDIRThis entry can be set in .user.ini.
PHP_INI_SYSTEMThis entry can only be changed by us. Please contact support.


The PHP_INI_SYSTEM settings can't be changed easily: We chose those values carefully to ensure stability and the most performant settings possible.

Entries in .user.ini are recursive

With a few easy steps, you can override php settings when running in PHP-FPM mode. PHP not only loads the php.ini file itself, but it also scans for INI files in each directory; First in the directory the executed script is loaded in, and keeps looking in higher up directories until it reaches the ~/public/ directory.

**Please note:** This would mean, for example, if you were to create the .user.ini within the ~/public/dir1/ directory, the changes are applied to the PHP scripts that are installed in that particular directory only.

Any subsequent PHP installations such as WordPress in a ~/public/blog/ directory, will not be affected by the changes in this .user.ini If you wish to change the settings for both directories, you'll have to install two separate .user.ini files, or place the .user.ini file in your ~/public/ directory. This will affect all PHP scripts running on your Hypernode.

More info can be found on the PHP documentation page .

## Changing your PHP settings
In this example we'll show you how to increase the max_execution_time in PHP. If you've created a .user.ini file in the right directory, all you need to do is open up your .user.ini file and add the following line:

max_execution_time = 3600

Keep in mind:

  • PHP Settings in .user.ini files are cached by PHP-FPM. When changing settings has no effect, try restarting the PHP-FPM workers: pkill -u app php-fpm
  • The memory_limit settings are hardcoded and thus cannot be overridden.
R
Rens is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.