Since WordPress is a CMS (Content Management System) with the possibility of using external themes and plugins, it is common for some errors to happen after the installation, even for testing, of a new extension of this nature on your site.
It is also susceptible to some errors when a PHP or Apache or Nginx version upgrade occurs, due to the complexity of keeping all these plugins and themes up to date and with compatibility with the most current versions of these softwares.
The ideal is to check in the official documentation of the extensions if they already support a new version of WordPress that you intend to update, or the PHP language or even the Apache or Nginx HTTP server.
However, even after you review, study, and decide on upgrades, errors can happen in your installation.
Some will give you an indication on the pages of the site, others will allow you to check in the administrative environment of WordPress but, there are errors that will totally break the access to the site, returning the infamous 500 ERROR
.
Memory limit in PHP
One of the most common problems of this nature is related to exhaustive memory consumption, which often happens when installing or updating a buggy theme or plugin.
In fact memory limit errors can hit other systems developed in PHP, such as in the Laravel framework, for example.
The overall message is as follows:
Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 20480 bytes)
The values may appear different for your server.
The free translation would be:
Erro fatal: Tamanho permitido para memória de 41943040 bytes foi exaurido (tentativa de alocar 20480 bytes).
Another way that the message with this error may appear is:
PHP Fatal error: Out of memory (allocated 4193040 bytes) (tried to allocate 20480 bytes).
The free translation would be:
PHP Erro fatal: Sem memória (alocados 4193040 bytes) (tentativa de alocar 20480 bytes).
These error messages mean that WordPress required more memory to run a script in a click of Http Request, larger than allowed in the configuration of your PHP installation.
In this example PHP has already allocated 4193040 bytes (around 40M) and the attempt to allocate the next 20480 bytes was not possible because it broke the limit.
This allowable memory usage ratio is configured in the memory_limit directive of the php.ini file
of your installation.
memory_limit
Sets the maximum amount of memory in bytes that a script can allocate. This helps prevent poorly written scripts from consuming all available memory on the server. Note that in order for there to be no memory limit, this directive must be set to -1
. When an integer is used, the value is measured in bytes. The summarized notation, as described in this FAQ, can also be used.
Increasing the memory limit in PHP
There are some ways to increase the memory limit for running PHP scripts, then I start by showing the global configuration format on the server, in general, the most appropriate.
In the sequence how to configure in the root of any PHP project, and finally, how to increase within a specific script.
Setting the memory limit in the php file.ini
In general a change in the php file.ini
, following the example below, can solve. Look in the Resources limits section
, to change the configuration variable memory_limit
.
In general I start conservatively and climb from the traditional 40M to 64M, but nothing prevents you from climbing to 128M as an example to follow.
Remember, the following excerpt is a sample of the lines where you should find the configuration, in the
php file.ini
of maximum limit for PHP in this server.
; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M
Setting the PHP memory limit in the .htaccess configuration
You can set the PHP execution memory limit setting directly in a project’s .htaccess
file. When to do this:
- In some situations, why do you not want the configuration of a particular project to impact the global configuration of the server
- Why do you not have permission to change the PHP file `.ini'
To do this, open the .htaccess file
that you use for your PHP project and add the following line:
php_value memory_limit 128M
Note that depending on the configuration of your server, the possibility of overlapping settings using .htaccess
may be disabled.
Increasing the memory limit in WordPress
configurationIf you are working with a shared server host and do not have permission to change PHP settings.
Or, in cases when you have more than one piece of software installed on the same server and do not want to increase this limit in general, to maintain a more granular level of control.
You can opt for the strategy of changing the memory limit value when running WordPress by changing the wp-config file.php
.
To do this, simply add the following line at the beginning of the file:
<?php
ini_set('memory_limit','128M');
Final
considerationsIt is necessary to maintain constant organization and maintenance in your WordPress installation so that your site, in addition to being secure and stable, keeps itself in constant operation, avoiding loss of access and audience for your company or content.
Comments