Site icon G Tech Group

Optimising PHP Configuration and PHP-FPM for Your Website

optimising the php and php fpm configuration for your website

optimising the php and php fpm configuration for your website

Configure correctly PHP and PHP-FPM is essential to ensure that your website functions efficiently and stably. In the following, we will go through the suggested settings, explaining each parameter and providing tips on how to optimise your configuration according to visits and website consumption.

PHP configurations

memory_limit: 2048M

Function: The parameter memory_limit defines the maximum amount of memory that a PHP script may use. If a script exceeds this limit, it will be terminated.

Council:

max_execution_time: 512

Function: The parameter max_execution_time determines the maximum time in seconds during which a script may run before being terminated. This prevents malfunctioning scripts from consuming resources indefinitely.

Council:

max_input_time: 512

Function: The parameter max_input_time specifies the maximum time in seconds during which a script may parse input data (e.g. form data or loaded files).

Council:

post_max_size: 128M

Function: The parameter post_max_size defines the maximum size of data that may be included in a POST request.

Council:

upload_max_filesize: 256M

Function: The parameter upload_max_filesize defines the maximum size of an uploaded file.

Council:

opcache.enable: on

Function: Enable opcode caching to improve the performance of your PHP application.

Council: Keep this setting enabled to improve performance. Be sure to configure other opcache settings correctly to maximise benefits.

disable_functions: opcache_get_status

Function: Disables certain PHP functions for security reasons.

Council: Disable only those functions that are not necessary for your site to increase security.

Common PHP Settings

include_path

Function: The list of directories in which PHP scripts search for included or required files.

Council: Keep the default path unless there is a specific reason to change it. Add paths only if they are necessary for the operation of your site.

session.save_path

Function: The directory where the PHP session files are stored.

Council: The default directory is generally adequate, but make sure it has the appropriate permissions to read and write. If your site uses sessions heavily, consider using a more powerful session storage solution such as Redis or Memcached.

error_reporting: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

Function: The level of PHP error reporting.

Council: Maintain this configuration for the production environment to avoid non-critical error messages being displayed to end users.

display_errors: off

Function: Determines whether PHP errors are to be displayed as part of the output.

Council: Keep this setting disabled in production for security reasons. Only enable it in a development environment.

log_errors: on

Function: Enables access to PHP errors, recording them in a log file.

Council: Keep this setting enabled to be able to solve any problems. Check error logs periodically to identify and correct any bugs.

PHP-FPM Settings

pm.max_children: 12

Function: The maximum number of child processes that PHP-FPM can create.

Council:

pm.start_servers: 2

Function: The number of server processes at start-up.

Council:

pm.min_spare_servers: 2

Function: The minimum number of idle server processes.

Council:

pm.max_spare_servers: 4

Function: The maximum number of idle server processes.

Council:

pm.max_requests: 500

Function: The maximum number of requests each child process can execute before being recycled.

Council:

pm: dynamic

Function: It determines the behaviour of child process management.

Council: Keep dynamic for flexible management of child processes according to server load. In some cases, ondemand can be useful to save resources in times of low traffic.

Additional Suggestions

Resource monitoring

Use monitoring tools such as New Relic or server monitoring tools to keep an eye on memory and CPU utilisation.

Caching

It implements server-side caching (e.g. Varnish) and/or application-side caching to reduce the load on the server.

Regular updates

Ensure that all server components and libraries used are up-to-date to benefit from performance improvements and security fixes.

Using these configurations and tips, you should be able to effectively manage PHP-FPM memory and improve the performance of your website.

Exit mobile version