John Davidson

laravel - increase memory_limit doesn't work in PHP Container in Docker

0 comments
Message:


I'm using a container in Docker to host my Laravel app and this container is connected to another container using Nginx to host it. I'm trying to import a SQL file into my Laravel app with a seeder that's like this


$path = public_path('sql/2022_11_16_import_table.sql');
$sql = file_get_contents($path);
DB::unprepared($sql);

However, it displayed the error



Symfony\Component\Debug\Exception\FatalErrorException : Allowed memory size of 134217728 bytes exhausted (tried to allocate 186885432 bytes)
at /var/www/database/seeds/SqlFileSeeder.php:16



I have figured this is due to my memory_limit in php.ini is being 128M so I went ahead and changed it by changing the php.ini-development and php.ini-production file inside the PHP container and then restart the whole container and the Nginx container. However, when I tried


php -ini 

again the memory_limit is still 128M=>128M despite both the php.ini file has been changed. I have also tried ini_set('memory_limit','200M'); but it still seems to have no effect.



My Answer:
It seems like the changes you made to the php.ini file are not being reflected in the PHP container. One possible reason for this could be that the php.ini file you edited is not the one being used by the PHP container.

To ensure that the changes are being applied, you can try the following steps:

1. Check the location of the php.ini file being used by the PHP container. You can do this by running the following command inside the PHP container:
bash
php -i | grep php.ini

This will show you the path to the php.ini file that is currently being used.

2. Make sure that you are editing the correct php.ini file. If the path shown in step 1 is different from the one you edited, then you need to edit the correct php.ini file.

3. After editing the correct php.ini file, restart the PHP container to apply the changes. You can do this by running the following command:
bash
docker restart

Replace `` with the name of your PHP container.

4. Check the memory_limit value again by running `php -ini` inside the PHP container to verify that the changes have been applied.

If you have followed these steps and the memory_limit is still not being updated, there may be another issue at play. In that case, you may need to troubleshoot further or seek additional help.

Rate this post

5 of 5 based on 4359 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us