<>
If your WordPress site is hosted on a hosting o alojamiento Web compartido, es probable que puedas encontrarte alguna vez con the error message indicating that the allowed memory size has been exhausted.
Web servers are practically the same as a computer, they need memory to process requests and scripts of the hosted sites. When an amount of information is executed, when you reach the memory limit, and you will end up seeing this error.
In this short basic tutorial, we will explain a simple solution to aumentar el límite de memoria PHP en tu server, con una selección de 3 métodos.
We know that error messages can be annoying, therefore Take a look at this guide if at the same time you find that WordPress is stuck in maintenance mode.
First of all, contact your provider hosting
You may need to contact your web host before starting, as Some hosting or web hosting does not allow users to increase PHP memory.
In some cases, only the hosting provider can change the PHP memory limit on the server.
Ask your hosting provider what is the best way to change the PHP memory limit.
Method 1) Edit the wp-config.php file
With WordPress, you can change the memory limit by editing the file wp-config.php:
- First conéctate a tu servidor con un software FTP, or inicia sesión en tu cPanel to use the File Manager.
- The file wp-config.php must be located in the root folder where do you have WordPress installed.
- Open the file for editing and Add next line: define ('WP_MEMORY_LIMIT', '256M')
Method 2) Edit the file php.ini
If you have access to the file at your disposal php.ini (note that some hosting providers do not give access to the php.ini file), you can locate the memory limit code and change it to 256MB.
- Open the php.ini file for editing by aggressing the code: memory_limit = 256M; Maximum amount of memory a script may consume (64MB).
Method 3) Edit the .htaccess file
At the same time you can edit the file .htaccess located in the root folder of WordPress.
- Add the line of code at the end of the text to increase the PHP memory limit: php_value memory_limit 256M
How to Increase Max Upload file size
By default, WordPress and your hosting provider limit the file upload size for technical reasons. Users who need to upload files that exceed the preset limit usually get an error and the operation fails.
The two most common reasons for this problem are due to file size upload restrictions added to the following two areas:
- The upload_max_filesize directive in php.ini
- Un error fatal: Tamaño de memoria permitido de xxxxx bytes agotados (intentó adjudicar xxxxx bytes) en /home/su nombre de Username/public_html/wp-includes/plugin.php en línea xxxx
There are several ways to increase the maximum WordPress upload file size limit. In this article, I am going to discuss only the most popular ways that have worked for most WordPress websites. But before entering the discussion, I will talk about three variables that play an important role in this problem.
- Upload_max_filesize: This variable defines the maximum upload size for a single file.
- Post_max_size: Esta variable define el límite máximo de carga para una solicitud POST. Tenga en cuenta que una sola solicitud puede incluir varios archivos.
- Memory_limit: This variable defines the memory limit for a single script. This limit can be equal to or greater than upload_max_filesize.
Note: There is a relationship between upload_max_filesize and post_max_size. In several cases, the size post_max_size is set higher than the upload_max_filesize size. Here's an example: if you have a lot of 5MB files and the file size upload_max_filesize is set to 20 MB, the size post_max_no it can contain more than 4 files.
Confirm WordPress Max Upload Default File Size Limit
The default file upload size limit can be found by navigating to Media >> Add new.
As you can see from the following screenshot, the default maximum upload file size is 10 MB.
In this tutorial, I will set the limit of 20MB. As previously discussed, there are several ways to increase the upload file size limit.
Let's start:
Check with the hosting provider
Hosting providers that specialize in WordPress hosting have a default option to increase the file upload size limit (usually located in the control panel).
A modo de ejemplo, si usted es un client de Cloudways, ingrese a su plataforma, navegue a la Servers tab and then to Configuration and Packages. In the countryside LOAD SIZE, enter the file size you want. Once done, don't forget to click the button Save Changes at the bottom of the page.
Modify (or Create) php.ini
php.ini (ubicado en el root directory de la cuenta de hosting) es un archivo de configuración que personaliza el comportamiento de PHP en tiempo de ejecución. Contiene una lista de ajustes que incluye el tamaño máximo del archivo de carga, el tiempo máximo de ejecución, el directorio de carga, las variables globales y los errores de visualización.
Due to security concerns, almost all hosting providers keep it hidden. To access the file, log into your hosting account, navigate to the root directory and search for php.ini. You may have to check "Show hidden files". If no such file exists, create a new one with the name: "Php.ini". Make sure the file includes the three variables mentioned above
Since I need to set the maximum file upload size to 20MB, I will change the values from upload_max_filesize to 20MB and post_max_size to 25MB so that a single 20MB file can be used in the body of the message. Good practice is to establish a size post_max_size Older than him size upload_max_filesize.
upload_max_filesize = 20M
post_max_size = 25M
memory_limit = 30M
Note: "M" refers to "MB", the memory limit must be equal to or greater than the upload_max file size. To be safe, I have set it to 30MB.
Note that some hosting providers rename the file to php5.ini.
Modify (or Create) the .htaccess file
.htaccess es la abreviatura de Hypertext Access, un archivo de configuración utilizado por los servidores Apache. Típicamente, se encuentra en el directorio raíz. Si el archivo no está ahí, créalo con el nombre y la extensión exactos «.htaccess»
I assume you already have the file, copy and paste the following lines of code just below where it says #End WordPress.
php_value upload_max_filesize 20MB
php_value post_max_size 25MB
php_value memory_limit 30MB
Note: While searching for .htaccess, don't forget to check «Show hidden files«. It could be hidden by your hosting provider.
Modify WordPress files
The above three methods are the most recommended ways to increase the file upload size. However, for whatever reason these methods don't work, it's time to add them to WordPress files. Open the wp-config.php or functions.php files and paste the following lines of code:
@ini_set ('upload_max_size', '20MB');
@ini_set ('post_max_size', '25MB');
@ini_set ('memory_limit', '30MB');
Increase WordPress Max Upload File Size Through Plugin
La belleza de WordPress es que siempre encontrarás un plugin para solucionar el problema. Si no pretendes aumentar el tamaño del archivo subido manualmente, hay un excelente plugin llamado Increase Max Upload Filesize que seguramente te ayudará. Sólo recuerde introducir los valores en bytes (1024000 bytes = 1 MB). Para 20 MB, multiplique 1024000 por 20 e introduzca 20480000 en el cuadro de texto. Haga clic en Guardar cambios y listo!
Does the problem persist?
There is a slight chance that none of the above methods will work for your website. In such cases, don't panic. Contact your hosting provider and they will help you!
Upload files via FTP
FTP is very useful when you need to upload large files. Note that the files uploaded via FTP in the directory / wp-content / uploads / they are not displayed in the media library. There is an excellent Media FTP plugin that registers these files to the library in just a few clicks.
conclusion
If you think I've missed a popular method, feel free to mention it in the comment section below. If any of the mentioned methods worked for you, please share the details in a comment.
If you've tried all of the above and nothing has worked, contact your web host and tell them about the problem.
It is possible that the hosting do not allow users to change the PHP memory limit, or have a different way of doing it.
At the same time, they may not be able to offer you to increase the memory limit, thus, you should think about migrating the site or making other adjustments so that the operation of your site consumes less memory.
Thanks again for reading!
2Ncc03l