Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincentsanity's avatar

Mysql error PDOStatement::execute(): MySQL server has gone away using Laravel and curl request

I am using a 3rd party API to insert data in the database. I encountered this problem already in my local computer and I set the max_allowed_packet as what other posts said and it worked for me. But now I am using our linux remote server to insert the data. I cant find the my.ini or some config file but there are similar file and here named 50-server.cnf are some he contents of it

#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 1024M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam_recover_options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

#
# * Query Cache Configuration
#
query_cache_limit   = 32M
query_cache_size        = 1024M

I have also written a bunch of queries in our linux remote terminal in order to set the global variables. Here are some of it

sudo mysql

SET SESSION wait_timeout = 999999;

SET SESSION net_read_timeout = 1000

SET GLOBAL connect_timeout = 1000;

after that i run sudo /etc/init.d/mysql restart then I execute my controller function but I still get PDOStatement::execute(): MySQL server has gone away

I am using

Mysql: mysql Ver 15.1 Distrib 10.1.43-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Linux: Linux ip-172-31-16-16 4.15.0-1054-aws #56-Ubuntu SMP Thu Nov 7 16:15:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

PHP: Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

MariaDB: mariadb Ver 15.1 Distrib 10.1.43-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Can someone tell me what is the problem with this?

0 likes
1 reply
optic4predator1's avatar

Hello @vincentsanity i had the same issue but i will ask you to check if the user of your database had all priveleges to create, update and delete. so for exmple in my case i went to phpmyadmin i was searching fro the user which i use in my .env file for example login :root passwod : root so the user in my case is root i went to phpmyadmin to the home then in the user acount server privileges make sure the user had the same config root localhost YES ALL PRIVILEGES YES

Please or to participate in this conversation.