6.1.3 Basic parameters and configuration of php.ini

TheHost php.ini Banner EN

php.ini is a configuration file containing the PHP settings of your web server. It allows you to control your sites’ PHP-related policies, such as setting file upload size limits and hiding error messages.

The location of the PHP configuration file depends on the web server. To change its settings, it must be edited using any text editor.

In most cases, the need to edit php.ini arises either when deploying a server, or to apply recommendations for improving the performance of your site from your CMS.

It is recommended that you read the official documentation and, if necessary, the full [list](https://www.php.net/manual /en/ini.list.php) possible directives.

Basic configuration file variables

In this material we will get acquainted with the main basic variables, changes of which may be required in the vast majority of cases:

1. Limitation on resource use:

  • memory_limit=. This limit sets the maximum amount of memory (in megabytes) that a PHP script can use during execution. If the script tries to use more memory than specified in this variable, a fatal error occurs.
  • upload_max_filesize=. Defines the maximum size of uploaded files via HTTP POST. Files larger than this value will be rejected for upload.
  • post_max_size=. Sets the maximum size of data that can be sent via the POST method in PHP scripts. If the sent data exceeds this value, it will be truncated.
  • max_execution_time=. Defines the maximum time (in seconds) that a PHP script can be executed. If the script does not complete within this time, it will be automatically aborted.
  • max_input_time=. Sets the maximum time (in seconds) that a PHP script can accept input (such as form data). If the time is exceeded, PHP terminates the script.
  • max_input_vars=. The number of input variables that can be accepted in one request (the limit is imposed on each of the global variables $_GET, $_POST and $_COOKIE separately).

2. Dealing with errors:

  • display_errors=. Determines whether PHP errors should be output directly by the web page or not. If set to On, errors will be displayed directly on the page opened in the browser, if any.
  • error_reporting=. Determines what types of PHP errors will be logged and output (if display_errors is set to On). It is generally recommended to set this to E_ALL to track all types of errors during development and testing. On a production server, it may be useful to set more restrictive settings such as E_ERROR or E_WARNING to avoid printing unnecessary information.

3. Security:

  • register_globals=. Determines whether automatic creation of global variables from input data such as GET, POST requests, and cookies is allowed. Starting from PHP 5.4, it is set to Off by default, as enabling it may cause security problems.
  • session.save_path=. Specifies the path to the directory where PHP stores session data for temporary storage. The directory must have the appropriate rights and permissions. The path value must be in quotes.

4. Mail:

  • sendmail_path=. Defines the path to the sendmail executable, which is typically used by PHP to send email. The path value must be in quotes.

Using php.ini you can also activate PHP extensions on your server after they are installed. For example:

extension=intl.so
extension=imagick.so

or:

zend_extension = /usr/lib/php/20210902/ioncube_loader_lin_8.1.so

The specific directives depend on your server configuration and the documentation of the relevant plugins.

php.ini on hosting

Important: on hosting services, such restrictions are set at the tariff plan level. Increasing the parameters in the php.ini file on the hosting above the tariff plan quotas will not have any effect. You can view the quotas of your tariff plan in the corresponding table by scrolling down and clicking Details under the tariff plan of interest.

On our shared hosting, php.ini is by default located along the path ~/php-bin/php.ini and looks like this :

register_globals= Off
display_errors= Off
log_errors= On
max_execution_time= 60
memory_limit= 512M
upload_max_filesize= 196M
post_max_size= 256M
max_input_vars= 20480

sendmail_path = "/usr/sbin/sendmail -t -i -f examplemail@exampledomain.com"
session.save_path = "/var/www/exampleuser/data/bin-tmp"

Most of the available PHP settings can be changed using the panel using the PHP Settings tab.

php.ini on virtual/dedicated server

On virtual/dedicated servers, the php.ini location can vary significantly. The simplest method to determine the file location is to connect via SSH and run the following command:

  1. php --ini
Output
Configuration File (php.ini) Path: /etc/php/8.1/cli Loaded Configuration File: /etc/php/8.1/cli/php.ini

Tip: If you have multiple versions of PHP installed on your server, simply use a command like this:

  1. php-7.4 --ini

Where 7.4 must be replaced with the version you are interested in.

After a fresh installation of PHP, the configuration file may not contain any custom directives at all. In this case, PHP will be initialized with default values.

Question: What PHP limit values should be specified for stable server operation?

This is a very non-trivial question that requires clarification of the context of your server configuration and the requirements of your site. General recommendations can be summarized as follows:

  • memory_limit=. At least 1024 MB and no more than half the size of the server’s RAM.
  • upload_max_filesize=. At least 1024 MB.
  • post_max_size=. Equal to or slightly higher than upload_max_filesize=. For 1024 in the higher one, it makes sense to set approximately 1060.
  • max_execution_time=. Depends heavily on the context. The value of 300 seconds can be considered average.
  • max_input_time=. 30 seconds unless otherwise required.
  • max_input_vars=. Many CMS require high values for this variable. Even 10240 as a limitation is unlikely to lead to negative consequences.

Important: after editing the specified files, you must restart the web server to apply the new settings. For ISPManager4, this can be done as root in the Services section. For servers without a panel, this is achieved using the corresponding commands.