title: "MySQL server has gone away" when connecting to server with PHP
body: <p>So, I have a weird issue on my Ubuntu (18.04) server:</p>
  
  <p>I have PHP (7.2.10) and MySQL (8.0.12) running. When I try to connect to the MySQL database from a PHP page, I get the error "MySQL server has gone away". In <em>every</em> search I've done, all the fixes are for when that error appears when sending a query. (I'm not even getting to that point, yet.)</p>
  
  <p>The mysql.err and mysql.log files are either blank or have unrelated warnings (no errors). I've increased my timeout and max_allowed_packet to no avail. Also, I can connect to the database remotely with other programs, so I know the server is responding to requests.</p>
  
  <p>I set MySQL to allow connections from [User]@% (I know, that's a bad idea; I'll change it back once I get beyond this problem.)</p>
  
  <p>I'm using the same user I can use to access the database remotely.</p>
  
  <p>Any ideas?</p>
  
  <p>Relevant part of the script (Though, at this point, I'm >90% certain the problem isn't with the script itself)</p>
  
  <pre><code>&lt;?php
  
  $conn = new mysqli($servername, $user, $password, $DB, $port);
  
  if ($conn-&gt;connect_error)//Test connection
  { //On fail, send an alert and populate manually
    echo "&lt;script&gt;alert('Connection failed: $conn-&gt;connect_error! $conn-&gt;host_info');&lt;/script&gt;\n";/*populate manually*/
  }
  else //run query; it never gets here.
  ?&gt;
  </code></pre>