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
SymfonyComponentDebugExceptionFatalErrorException : 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.
4
Answers
Thanks for the suggestions. I have used php.ini based on the 2 files and after reloading nginx it worked as intended. Alternatively I also tried
ini_set
right beforeand it also did the job. Previously I ini_set in another file but after further reading I hace come to realized it just set for the current working file and not globally.
You can add a command at the end of your docker file to copy the
php.ini-production
orphp.ini-development
to/usr/local/etc/php/php.ini
.Something like this:
php.ini-production file will not read. PHP initialization work with
php.ini
files, which are end.ini
extension. You can addvolume
inDocker
for mainphp.ini
files like that:Content of php.ini
If you will do it manually after
docker compose up
, then you will need to run some commands:Enter to
Docker
containerRestart
PHP-fpm
andNginx
servicesIt’s work for me: