As WordPress is a CMS (Content Management System) with the possibility of using external themes and plugins, it is common for some errors to occur after installing, even for testing, 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 compatible with the most current versions of these software.
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, either the PHP language or the Apache HTTP server or Nginx.
However, even after you analyze, study and decide for upgrades, errors can happen in your installation.
Some will give you an indication on the website pages, others will allow you to check in the WordPress administrative environment but there are errors that will completely break access to the website, returning the infamous
Memory limit in PHP
One of the most common problems of this nature is related to the exhaustive consumption of memory, which often happens when installing or updating a buggy theme or plugin.
In fact, memory limit errors can affect other systems developed in PHP, as in Laravel framework, for example.
The general 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:
Fatal error: Allowed memory size of 41943040 bytes has been exhausted (attempted to allocate 20480 bytes).
Another way the message with this error can appear is:
PHP Fatal error: Out of memory (allocated 4193040 bytes) (tried to allocate 20480 bytes).
The free translation would be:
PHP Fatal Error: Out of memory (allocated 4193040 bytes) (attempted to allocate 20480 bytes).
These error messages mean that WordPress needed more memory to run a script in one click. Http Request, greater than what is allowed in your PHP installation configuration.
In this example PHP has already allocated 4193040 bytes (around 40M) and the attempt to allocate the next 20480 bytes was not possible because the limit was exceeded.
This allowed memory usage ratio is configured in the directive memory_limit of the file
php.ini of your installation.
Defines the maximum amount of memory in bytes that a script can allocate. This helps to prevent poorly written scripts from consuming all available memory on the server. Note that for there to be no memory limit, this directive must be set toPHP manual
-1. When an integer is used, the value is measured in bytes. The abbreviated 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 executing PHP scripts, below I start showing the global configuration format on the server, in general, the most indicated.
Next, how to configure it in the root of any PHP project, and finally, how to increase it within a specific script.
Setting memory limit in php.ini file
In general a change to the file
php.ini, following the example below, can solve. Look in the section
resources limits, change the configuration variable
In general I start conservatively and go up from the traditional 40M to 64M, but nothing prevents you from going up to 128M as an example to follow.
Remember, the following snippet is a sample of the lines where you should find the configuration, in the file
php.ini, of maximum limit for PHP on 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 PHP memory limit in .htaccess configuration
It is possible to set the PHP execution memory limit setting directly in the file
.htaccess of a project. When to do this:
- in some situations why you don't want the configuration of a particular project to impact the global configuration of the server
- why you are not allowed to change the file
To do this, open the file
.htaccess that you use for your PHP project and add the following line:
php_value memory_limit 128M
Note that depending on your server configuration, the possibility of overriding settings using the
.htaccess may be disabled.
Increasing memory limit in WordPress configuration
In case you are working with a shared server host and you are not allowed to change PHP settings.
Or, in cases when you have more than one software installed on the same server and you don't want to generally increase this limit to maintain a more granular level of control.
You can opt for the strategy of changing the memory threshold value on WordPress execution by changing the file
To do this, just add the following line to the beginning of the file:
It is necessary to maintain constant organization and maintenance in your WordPress installation so that your website, in addition to being safe and stable, remains in constant operation, avoiding loss of access and audience for your company or content.
keep up to date
Don't forget to follow me on twitter and sign the Mazer.dev channel on Youtube to receive updates on new articles, video lessons and courses free software in computer programming, quality software development, software engineering and tools like WordPress, Git, Gitlab, Github, among others.