php.ini directives cheat sheet

This cheat sheet brings together the php.ini directives you actually change, from upload size and memory limit, through error display, sessions, and security, to OPcache, with a short explanation, an example value, and where you can change each directive. You can search for a directive, filter by topic, and copy it with one click.

File uploads and forms

  • upload_max_filesize = 64M

    The maximum size of a single file uploaded through the website. The default is 2M, so uploading a large image, theme, or plugin often fails until you raise the value. The value should be smaller than post_max_size. Can be changed in php.ini and in .user.ini (INI_PERDIR).

  • post_max_size = 72M

    The maximum size of all the data sent in one request, including every file uploaded with it. When the request is larger than the value, $_POST and $_FILES arrive empty, and the form looks as if it was sent without data. The default is 8M, and it is common to set a value slightly higher than upload_max_filesize. Can be changed in php.ini and in .user.ini (INI_PERDIR).

  • max_file_uploads = 20

    The maximum number of files that can be uploaded in one request. Upload fields left empty are not counted. The default is 20. Can be changed in php.ini and in .user.ini (INI_PERDIR).

  • max_input_vars = 3000

    The maximum number of input variables in a request, counted separately for each of $_GET, $_POST, and $_COOKIE. When the number exceeds the value, a warning is shown and the remaining variables are dropped, so long forms, large menus, and busy settings screens in content management systems are saved only in part. The default is 1000. Can be changed in php.ini and in .user.ini (INI_PERDIR).

  • max_input_time = 60

    The maximum time in seconds for receiving the request data, such as a form or an uploaded file, before the script starts running. By default, the value of max_execution_time is used, and 0 removes the limit. Can be changed in php.ini and in .user.ini (INI_PERDIR).

  • file_uploads = On

    Turns file uploads through website forms on or off. The default is On. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

Memory and execution time

  • memory_limit = 256M

    The maximum amount of memory a single script may allocate. Exceeding it causes the Allowed memory size exhausted error, and the page stops loading. The default is 128M. You can remove the limit completely, but on a live website it is better to set a defined value. Can be changed anywhere, including ini_set() in code (INI_ALL).

  • max_memory_limit = 512M

    A directive available in recent PHP versions that sets a ceiling for the value of memory_limit, both in the configuration file and at runtime. An attempt to set a higher value shows a warning, and the value is capped at the ceiling. By default, there is no ceiling. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • max_execution_time = 60

    The maximum run time of a script in seconds, after which the script stops with the Maximum execution time exceeded error. The default is 30 seconds, and on the command line it is 0, meaning no limit. On Linux, usually only the script's processing time is counted, without time spent waiting for file and network operations, and the web server may have a time limit of its own. Can be changed anywhere, including ini_set() in code (INI_ALL).

  • set_time_limit(120);

    A function that sets a new maximum run time for the current script, and the count starts again from the moment of the call. Suitable for a single long script, such as a data import, without changing the directive for the whole website.

  • default_socket_timeout = 60

    The maximum time in seconds to wait for network connections opened as files, for example a call to an external URL with file_get_contents(). The default is 60 seconds. Can be changed anywhere (INI_ALL).

Errors and logs

  • display_errors = Off

    Sets whether error messages are shown on the page itself. In a development environment it is convenient to show them, but on a live website you should turn the directive off, because the messages reveal file paths and internal details to visitors. The default is On, and the sample production configuration file (php.ini-production) turns it off. Can be changed anywhere (INI_ALL).

  • display_startup_errors = Off

    Shows errors that occur while PHP starts up, before the script runs. The default is On, and the official documentation recommends keeping the directive off, except while troubleshooting. Can be changed anywhere (INI_ALL).

  • log_errors = On

    Writes errors to a log instead of showing them on the page. This is the recommended approach on a live website: visitors see nothing, and every error is saved for review. The default is Off. Can be changed anywhere (INI_ALL).

  • error_log = /home/example/logs/php-errors.log

    The path of the log file that errors are written to. The web server needs write permission for the file, and the value syslog sends errors to the system log. When the directive is empty, errors are written to the server's error log. The path on this line is an example only. Can be changed anywhere (INI_ALL).

  • error_reporting = E_ALL

    Reports all types of errors, warnings, and notices. This is the default, and it also suits a live website when display on the page is off and logging is on. Can be changed anywhere (INI_ALL).

  • error_reporting = E_ALL & ~E_DEPRECATED

    All errors, without notices about features scheduled for removal in future versions (Deprecated). Useful on an older website whose log fills up with such notices, but it is best to fix them before moving to a new version.

  • html_errors = Off

    Error messages as plain text, without HTML tags. Suitable for logs and APIs. The default is On. Can be changed anywhere (INI_ALL).

Sessions and login

  • session.gc_maxlifetime = 3600

    The number of seconds after which unused session data is considered old and may be deleted. The default is 1440, that is, 24 minutes, and this is a common reason users are logged out after a short time without activity. Cleanup runs with a certain probability when a session starts, so old data is not always deleted right away. When several websites store sessions in the same folder, the lowest value among them applies. Can be changed anywhere (INI_ALL).

  • session.cookie_lifetime = 0

    The lifetime of the session cookie in the browser, in seconds. The value 0 means until the browser is closed, and this is the default. Can be changed anywhere (INI_ALL).

  • session.cookie_secure = 1

    The session cookie is sent only over an HTTPS connection. Suitable for every website that runs with an SSL certificate, but while the directive is on, sessions do not work over an unencrypted connection. Off by default. Can be changed anywhere (INI_ALL).

  • session.cookie_httponly = 1

    The session cookie is not accessible to JavaScript code on the page, which makes it harder to steal through code injection. Off by default. Can be changed anywhere (INI_ALL).

  • session.cookie_samesite = "Lax"

    Sets the SameSite attribute of the session cookie. With both Lax and Strict, the cookie is not sent with POST requests that come from another website, and the difference is that with Lax it is sent when a visitor follows a link from another website, and with Strict it is not. An empty value, which is the default, does not add the attribute. Can be changed anywhere (INI_ALL).

  • session.use_strict_mode = 1

    The server rejects a session ID it did not create and sends the browser a new ID. The official documentation describes the directive as mandatory for session security and recommends enabling it on every website. Off by default. Can be changed anywhere (INI_ALL).

  • session.save_path = "/home/example/tmp/sessions"

    The folder where session files are stored, when sessions are stored in files. A private folder for the website is better than a folder shared by all users on the server. The path on this line is an example only. Can be changed anywhere (INI_ALL).

Security

  • expose_php = Off

    Hides the X-Powered-By header, which shows the name PHP and the version number in every response. Turning the directive off does not fix vulnerabilities, but it makes life harder for automated scans that look for old versions. Can be changed only in php.ini.

  • allow_url_fopen = On

    Lets file functions, such as file_get_contents(), read http:// and ftp:// URLs as well. Many systems and plugins rely on this to reach external services, so turning it off may break them. On by default. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • allow_url_include = Off

    Prevents loading code from a URL with include and require, an action that allows running code from an external website. Off by default, the directive is marked as deprecated in the documentation, and it should stay off. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • disable_functions = exec,passthru,shell_exec,system,proc_open,popen

    Disables functions from a comma-separated list, usually functions that run system commands. Before disabling them, make sure the website and its plugins do not use them, or parts of the website will stop working. According to the documentation, do not rely on this directive as your only protection. Can be changed only in php.ini.

  • open_basedir = /home/example/public_html:/tmp

    Limits the files scripts can open to the listed folders and the folders below them. On Linux, folders are separated with a colon, and on Windows with a semicolon. Can be set anywhere (INI_ALL), but at runtime you can only narrow the list.

Date, encoding, and output

  • date.timezone = "Asia/Jerusalem"

    The time zone for all date and time functions, when no other zone is specified. The default is UTC, so times shown on the website or saved in logs may be off by a few hours from local time. Use a name from the official list of time zones, and a wrong or empty value shows a warning. Can be changed anywhere (INI_ALL).

  • default_charset = "UTF-8"

    The character encoding sent in the Content-Type header when the script has not set another encoding, and also the default encoding of htmlspecialchars() and similar functions. The default is UTF-8, which suits websites in any language. Can be changed anywhere (INI_ALL).

  • output_buffering = 4096

    Buffers output in memory before it is sent to the browser, up to the given size in bytes. The value On enables buffering with no size limit, and Off disables it. Buffering sometimes solves the headers already sent error, which appears when code sends a header after output has already been sent, but it is better to fix the code itself. On the command line, buffering is always off. Can be changed in php.ini and in .user.ini (INI_PERDIR), but not with ini_set().

  • short_open_tag = Off

    Sets whether the short tag <? is treated as the start of PHP code. When the directive is off, write the full <?php tag, and the <?= tag for printing a value is always available. The default is On, and in new code it is best to use only the full tag. Can be changed in php.ini and in .user.ini (INI_PERDIR).

OPcache

  • opcache.enable = 1

    Enables OPcache, which keeps the compiled code of scripts in memory and speeds up page loading. On by default. Can be set anywhere (INI_ALL), but ini_set() can only disable the cache, not enable it.

  • opcache.enable_cli = 0

    Enables OPcache on the command line as well. Off by default. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • opcache.memory_consumption = 256

    The size of the cache's shared memory, in megabytes. The default is 128 and the minimum is 8. On a large website with many plugins, raise the value when the cache fills up. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • opcache.interned_strings_buffer = 16

    Memory in megabytes for storing constant strings from the code, such as class and function names, once for all scripts. The default is 8. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • opcache.max_accelerated_files = 20000

    The maximum number of scripts kept in the cache. The default is 10000, the allowed range is 200 to 1000000, and the actual number is rounded up to one of the values from a fixed list. On a website with many files, such as an online store with many plugins, raise the value. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • opcache.validate_timestamps = 1

    Checks whether code files have changed since they were cached. When the directive is off, file changes take effect only after the cache is reset, for example with opcache_reset(), or after the web server restarts. On by default. Can be changed anywhere (INI_ALL).

  • opcache.revalidate_freq = 2

    How often, in seconds, files are checked for changes, when checking is enabled. The value 0 checks on every request, and the default is 2. Can be changed anywhere (INI_ALL).

  • opcache.jit = tracing

    Enables the JIT compiler in tracing mode, which the official documentation recommends for most users. In recent PHP versions, the default is disable, and the memory allocated to JIT is set with opcache.jit_buffer_size. Can be changed anywhere (INI_ALL).

Where to change directives

  • upload_max_filesize = 64M post_max_size = 72M memory_limit = 256M

    Sample contents of a .user.ini file in the website folder, which changes directives for that folder and every folder below it without access to the main configuration file. The search for the file starts in the script's folder and ends in the website's root folder. The file is read only when PHP runs as CGI or FastCGI, and it accepts only directives in the INI_PERDIR and INI_ALL modes.

  • user_ini.cache_ttl = 300

    How often, in seconds, .user.ini files are read again. The default is 300, so a change to the file may take up to five minutes to take effect. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • user_ini.filename = ".user.ini"

    The name of the file PHP looks for in each folder. An empty value turns the search off completely. Can be changed only in php.ini or the server configuration (INI_SYSTEM).

  • ini_set('memory_limit', '512M');

    Changes a directive from within the code, for the current script only, and the value returns to the previous one when the script ends. Works only for directives in the INI_ALL mode, such as memory_limit and max_execution_time, and not for directives such as upload_max_filesize or post_max_size. The function returns the previous value, or false when the change fails.

  • php_value upload_max_filesize 64M php_flag display_errors off

    PHP directives in a .htaccess file, which work only when PHP runs as an Apache module and the AllowOverride setting allows it. The php_flag directive is for on and off settings, and php_value is for all other values. When PHP runs as CGI or FastCGI, use a .user.ini file instead.

  • php -d memory_limit=512M script.php

    Runs a script on the command line with a different value for a directive, for the current run only.

Checking active directives

  • php --ini

    Shows the php.ini file that was loaded and the additional configuration files that were scanned. Useful when it is not clear which file to edit.

  • php --ini=diff

    Shows only the directives whose value differs from the default. This option exists only in recent PHP versions.

  • php -i | grep -i memory_limit

    Shows all the command line directives and filters them by name. The command line directives may differ from the website's, because each of them can have a separate configuration file.

  • php -r "echo ini_get('upload_max_filesize'), PHP_EOL;"

    A quick check of one directive on the command line. Within the website's code, the ini_get() function returns the value actually in effect for that request.

  • <?php phpinfo(INFO_CONFIGURATION);

    A test file that shows the directives as the website sees them. The Local Value column shows the value in effect in that folder, and the Master Value column shows the value from the main configuration file. The page reveals a lot of information about the server, so delete the file right after the check and do not leave it open to visitors.

The php.ini file is the main PHP configuration file, and it is read when PHP starts. So a change to the file takes effect only after the web server or the PHP service restarts, depending on how PHP is installed, and on the command line the file is read again on every run. Sizes are written in short form, for example 64M or 1G, and on and off directives accept On or Off, as well as 1 or 0. The paths and values on this page are examples, so adjust them to your website.

Each directive has a mode that sets where you can change it, and on this page it appears in parentheses:

  • INI_ALL - anywhere, including the ini_set() function within the code.

  • INI_PERDIR - in php.ini, in .user.ini, or in the server configuration, but not within the code.

  • INI_SYSTEM - only in php.ini or the server configuration.

  • php.ini only - directives such as expose_php and disable_functions, which can be changed only in the main file.

On a web hosting plan, there is usually no access to the main php.ini file. You change common directives, such as upload size, memory limit, and execution time, in the hosting control panel, when it has a PHP settings screen, or in a .user.ini file in the website folder. On a VPS, you edit the configuration file directly, after checking with php --ini which file is loaded.

The value of post_max_size should be larger than upload_max_filesize, and memory_limit is usually larger than post_max_size as well. After every change, it is best to confirm with phpinfo() or ini_get() that the new value is in effect, and to delete the test file as soon as you finish.

To convert between size units, you can use the data storage unit converter, and to check whether your website still sends the X-Powered-By header, the HTTP header analyzer. End-of-support dates for each PHP version appear on the PHP lifecycle page.

Did you know?

With Linux hosting and WordPress hosting plans, PHP websites and content management systems run on fast, secure servers, with personal support via HelpDesk.

Linux hosting plans

php.ini FAQ

How do I increase the maximum upload size on my website?

The upload size is set by two directives: upload_max_filesize sets the size of each file, and post_max_size sets the size of the whole request. Raise both, with post_max_size slightly higher, for example 64M and 72M. On a hosting plan, you change them in the control panel, when it has a PHP settings screen, or in a .user.ini file in the website folder, and on a VPS in the php.ini file. Neither directive can be changed with ini_set() within the code.

What is the difference between upload_max_filesize and post_max_size?

The upload_max_filesize directive limits each file separately, and the post_max_size directive limits all the data sent in one form, including files and text fields. When the request is larger than post_max_size, the form reaches the server completely empty, so this directive should be larger than upload_max_filesize. When you upload several files together, their total size must fit within the post_max_size limit.

How do I check which PHP settings are active on my website?

The accurate way is a temporary test file in the website folder that runs phpinfo(), because it shows the values as the website sees them, including changes from a .user.ini file. The active value appears in the Local Value column, and you should delete the file when you finish. On a server with command line access, php --ini shows which configuration file is loaded, and php -i shows the command line settings, which may differ from the website's.

What is a .user.ini file, and when do I use it?

A .user.ini file is a small configuration file you place in the website folder to change PHP settings for that website only, without access to the main php.ini file. It suits common changes such as upload size, memory limit, and execution time, and it is read when PHP runs as CGI or FastCGI. By default, the file is read again every five minutes, so a change may take a few minutes to take effect.

Which error settings suit a live website?

On a live website, turn display_errors off, so visitors do not see error messages with paths and internal details, and turn log_errors on, so every error is saved to a log. Leave error_reporting at E_ALL, so every issue is recorded. In a development environment, you can turn display_errors on and see errors directly on the page.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement