Warning: mysqli::query(): MySQL server has gone away error php
Hi friends, Today we will learn how to resolve Warning: mysqli::query():MySQL server has gone away error PHP in a few steps.
After lots of searching, I find out an easy to resolve this issue without too much waste of time.
so let's start.

Note - follow the steps.

1- Steps   Open your terminal and go in your root path  with use this command  
  •      sudo su
2 - Steps After running this command it will ask your password just enter your password.

    Yeah! now you have root access.

3 - Steps In your root folder, you have php.ini.default file. you have to make a copy of this file name with php.ini.

      use this command
  •            cp /etc/php.ini.default /etc/php.ini


                                       |

                                       |

                                      \ / 

php-fpm.conf.default  php-fpm.d/   php.ini         php.ini.default       

sh-3.2# cd /etc/php



4 - Steps  After running this command you will see a file with name php.ini which is a copy of php.ini.default.

      Now just open your php.ini file using this command.
  •        sudo vi /etc/php.ini.    (without sudo you can also run this command)

Here I am using vi editor which you have you can use that editor.

you can use vim editor also instead of vi editor.

sh-3.2# sudo vi /etc/php.ini


5 - Steps After running this command your php.ini file will look like this.

[PHP]


;;;;;;;;;;;;;;;;;;;

; About php.ini   ;

;;;;;;;;;;;;;;;;;;;

; PHP's initialization file, generally called php.ini, is responsible for

; configuring many of the aspects of PHP's behavior.


; PHP attempts to find and load this configuration from a number of locations.

; The following is a summary of its search order:

; 1. SAPI module specific location.

; 2. The PHPRC environment variable. (As of PHP 5.2.0)

; 3. A number of predefined registry keys on Windows (As of PHP 5.2.0)

; 4. Current working directory (except CLI)

; 5. The web server's directory (for SAPI modules), or directory of PHP

; (otherwise in Windows)

; 6. The directory from the --with-config-file-path compile time option, or the

; Windows directory (C:\windows or C:\winnt)

; See the PHP docs for more specific information.

; http://php.net/configuration.file


; The syntax of the file is extremely simple.  Whitespace and lines

; beginning with a semicolon are silently ignored (as you probably guessed).

; Section headers (e.g. [Foo]) are also silently ignored, even though

; they might mean something in the future.


; Directives following the section heading [PATH=/www/mysite] only

; apply to PHP files in the /www/mysite directory.  Directives

; following the section heading [HOST=www.example.com] only apply to

; PHP files served from www.example.com.  Directives set in these

; special sections cannot be overridden by user-defined INI files or

; at runtime. Currently, [PATH=] and [HOST=] sections only work under

; CGI/FastCGI.

; http://php.net/ini.sections


; Directives are specified using the following syntax:





6- Steps     Now search  default_socket_timeout  press  slash with name of (/default_socket_timeout ) and press enter.

; Please see the actual settings later in the document for more details as to why

; we recommend these changes in PHP's behavior.


; display_errors

;   Default Value: On

;   Development Value: On

;   Production Value: Off


; display_startup_errors

;   Default Value: Off

;   Development Value: On

;   Production Value: Off


; error_reporting

;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

;   Development Value: E_ALL

;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT


; html_errors

;   Default Value: On

;   Development Value: On

;   Production value: On


/default_socket_timeout   <======= search     


Now you will see of value is set 60 by default.

; Define the anonymous ftp password (your email address). PHP's default setting

; for this is empty.

; http://php.net/from

;from="john@doe.com"


; Define the User-Agent string. PHP's default setting for this is empty.

; http://php.net/user-agent

;user_agent="PHP"


; Default timeout for socket based streams (seconds)

; http://php.net/default-socket-timeout

default_socket_timeout = 60     <======= by default is 60  


; If your scripts have to deal with files from Macintosh systems,

; or you are running on a Mac and need to deal with files from

; unix or win32 systems, setting this flag will cause PHP to

; automatically detect the EOL character in those files so that

; fgets() and file() will work regardless of the source of the file.

; http://php.net/auto-detect-line-endings

;auto_detect_line_endings = Off



7- Steps   Press i key for edit this then change this value 60 to 300.

; Define the User-Agent string. PHP's default setting for this is empty.

; http://php.net/user-agent

;user_agent="PHP"


; Default timeout for socket based streams (seconds)

; http://php.net/default-socket-timeout

default_socket_timeout = 300   <======= now value is 300 


; If your scripts have to deal with files from Macintosh systems,

; or you are running on a Mac and need to deal with files from

; unix or win32 systems, setting this flag will cause PHP to

; automatically detect the EOL character in those files so that

; fgets() and file() will work regardless of the source of the file.

; http://php.net/auto-detect-lin


8- Steps  After changing the value Save this file  using these
  1. shift + esc 
  2.  :wq!
  3.  enter key

; ... or under UNIX:

;

;   extension=msql.so

;

; ... or with a path:

;

:wq!  <======= save file 



   Make sure After saving the file you have to restart the server using this command 
  • apachectl restart

sh-3.2# 

sh-3.2# apachectl restart  <======= restart the server


Yeah! You have learned ЁЯШК

This is a short way to fix Warning: mysqli::query():MySQL server has gone away error PHP issue.
I hope you understood this and like this article. if you like it so, please give feedback in the comment section.

If any mistakes I made here, so please let me know and improve me.
If you have any query, feel free to ask me  ЁЯШК

Post a Comment

Please do not enter any spam link in the comment section.

Previous Post Next Post