<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Wordpress – Yeri Tiete</title><link>https://yeri.be/tag/wordpress/</link><description>Yeri Tiete's blog</description><language>en</language><copyright>© Yeri Tiete</copyright><lastBuildDate>Thu, 22 Feb 2024 11:24:50 +0100</lastBuildDate><atom:link href="https://yeri.be/tag/wordpress/index.xml" rel="self" type="application/rss+xml"/><item><title>WordPress unable to connect to SQL database</title><link>https://yeri.be/wordpress-unable-to-connect-to-sql-database/</link><pubDate>Thu, 22 Feb 2024 11:24:50 +0100</pubDate><author>Yeri Tiete</author><guid isPermaLink="true">https://yeri.be/wordpress-unable-to-connect-to-sql-database/</guid><description>&lt;p&gt;Yesterday, three blogs I'm hosting suddenly went offline and &lt;a href="https://yeri.be/?s=betteruptime"&gt;alerts&lt;/a&gt; went off.&lt;/p&gt;
&lt;p&gt;They all had the same error that they couldn't connect to their SQL database, and it seemed that &lt;a href="https://hub.docker.com/_/mariadb" target="_blank" rel="noreferrer noopener"&gt;the container&lt;/a&gt; recently was auto-updated. &lt;/p&gt;
&lt;p&gt;Docker logs also showed (which may or may not have been related):&lt;/p&gt;
&lt;pre class="wp-block-code"&gt;&lt;code&gt;2024-02-21 7:30:29 97 &amp;#91;Warning] Aborted connection 97 to db: 'unconnected' user: 'unauthenticated' host: '192.168.200.4' (This connection closed normally without authentication)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This was odd. I started the usual troubleshooting:&lt;/p&gt;</description><content:encoded><![CDATA[<p>Yesterday, three blogs I'm hosting suddenly went offline and <a href="https://yeri.be/?s=betteruptime">alerts</a> went off.</p>
<p>They all had the same error that they couldn't connect to their SQL database, and it seemed that <a href="https://hub.docker.com/_/mariadb" target="_blank" rel="noreferrer noopener">the container</a> recently was auto-updated. </p>
<p>Docker logs also showed (which may or may not have been related):</p>
<pre class="wp-block-code"><code>2024-02-21  7:30:29 97 &#91;Warning] Aborted connection 97 to db: 'unconnected' user: 'unauthenticated' host: '192.168.200.4' (This connection closed normally without authentication)</code></pre>
<p>This was odd. I started the usual troubleshooting:</p>
<ul>
<li>As these containers have their own network, maybe the IPs changed and as the SQL users can only access from a certain IP range, something broke there -- nothing seemed to have changed and I could connect from the nginx container to the other just fine</li>
<li>Password somehow changed -- nah, connections were accepted</li>
<li>Roll back to a previous version of MariaDB -- didn't do anything, odd</li>
<li>This was not actually a MariaDB problem but a WordPress problem? Was there an auto-update? Didn't make sense because one of the blogs is running a very old WP version</li>
<li>Worth noting that I also host two Ghosts blogs using the same setup (nginx+mariadb in container) and they were unaffected and humming along just fine...</li>
<li>At this point I was starting to think something was massively corrupt and this was gonna be a long day.</li>
</ul>
<p>I then continued and created a php (<code>testconnection.php</code>) file on the nginx:</p>
<pre class="wp-block-code"><code>&lt;?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Connection Details
$hostname = "container-mariadb";  // Your MariaDB hostname 
$username = "your_username"; // Your MariaDB username
$password = "your_password"; // Your MariaDB password
$database = "your_database_name"; // The database

// Create the connection
$conn = new mysqli($hostname, $username, $password, $database);

// Check for errors
if ($conn-&gt;connect_error) {
    die("Connection failed: " . $conn-&gt;connect_error);
}

// Print Debug Information
echo "Connected successfully\n"; 
echo "Host information: " . $conn-&gt;host_info . "\n";
echo "Client information: " . $conn-&gt;client_info . "\n";

// Close the connection
$conn-&gt;close();
?&gt;</code></pre>
<p>This threw the following error... We were getting somewhere:</p>
<pre class="wp-block-code"><code>Fatal error: Uncaught mysqli_sql_exception: Server sent charset (0) unknown to the client. Please, report to the developers in /var/www/domain/testconnection.php:13 Stack trace: #0 /var/www/domain/testconnection.php(13): mysqli-&gt;__construct() #1 {main} thrown in /var/www/domain/testconnection.php on line 13</code></pre>
<p>The charset I was using was <code>utf8mb4</code> with a collate of <code>utf8mb4_general_ci</code>:</p>
<pre class="wp-block-code"><code>SHOW CREATE DATABASE your_database_name;</code></pre>
<p>My <code>wp-config.php</code> file already had <code>DB_CHARSET</code>, but <code>DB_COLLATE</code> was not set. I added that in the config as well:</p>
<pre class="wp-block-code"><code>define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', 'utf8mb4_general_ci' );</code></pre>
<p>Sadly, that didn't fix it either. Still saying it can't connect to the database. Grmbl.</p>
<p>I then went ahead and checked <code>/etc/mysql/mariadb.conf</code> and the files in <code>/etc/mariadb.conf.d/</code>. It included <code>character-set-server = utf8mb4</code>, but not <code>collation-server = utf8mb4_general_ci</code>. The line was specifically in <code>/etc/mariadb.conf.d/50-server.cnf</code>.</p>
<p>Adding the latter solved the problem... 2hrs of my life gone. </p>
<p>As this file (likely) is managed in the container and changed by the OS (it's apparently based on Ubuntu, ewwww) or the MariaDB version, the easiest way was just creating another file: <code>/etc/mariadb.conf.d/51-&lt;something&gt;.cnf</code>.</p>
<p>This is my <strong>very dirty</strong> hack (as I'm not using Docker Compose for this):</p>
<pre class="wp-block-code"><code>docker exec -it container-mariadb bash -c "echo -e '&#91;mysqld]\ncollation-server = utf8mb4_general_ci'> /etc/mysql/mariadb.conf.d/51-yeri.cnf"
docker restart container-mariadb</code></pre>
<p>It now works fine again... </p>
]]></content:encoded><category>Linux</category><category>Software</category><category>www</category><category>mysql</category><category>nginx</category><category>wordpress</category></item><item><title>Wordpress iPhone plugin</title><link>https://yeri.be/wordpress-iphone-plugin/</link><pubDate>Fri, 29 Aug 2008 01:25:10 +0200</pubDate><author>Yeri Tiete</author><guid isPermaLink="true">https://yeri.be/wordpress-iphone-plugin/</guid><description>&lt;p&gt;For those using the &lt;a href="http://wordpress.org/extend/plugins/wp-pda/" target="_blank" rel="noopener noreferrer"&gt;PDA &amp;amp; iPhone wordpress plugin&lt;/a&gt;, which turns your blog into something more readable on a mobile device, don&amp;rsquo;t forget to add the Google analytics script to your footer.php (in both iphone-theme and pda-theme directory). As other plugins seem to be disabled.&lt;/p&gt;
&lt;p&gt;This is actually also meant for me, as a reminder, for when I update the plugin. ;)&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;a href="https://static.yeri.be/2008/08/photo.jpg" target="_blank" rel="noopener noreferrer"&gt;&lt;img class="size-full wp-image-401 aligncenter" title="iPhone's Safari with Tuinslak's blog" src="https://static.yeri.be/2008/08/photo.jpg" alt="" width="320" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;</description><content:encoded><![CDATA[<p>For those using the <a href="http://wordpress.org/extend/plugins/wp-pda/" target="_blank" rel="noopener noreferrer">PDA &amp; iPhone wordpress plugin</a>, which turns your blog into something more readable on a mobile device, don&rsquo;t forget to add the Google analytics script to your footer.php (in both iphone-theme and pda-theme directory). As other plugins seem to be disabled.</p>
<p>This is actually also meant for me, as a reminder, for when I update the plugin. ;)</p>
<p style="text-align: center;"><a href="https://static.yeri.be/2008/08/photo.jpg" target="_blank" rel="noopener noreferrer"><img class="size-full wp-image-401 aligncenter" title="iPhone's Safari with Tuinslak's blog" src="https://static.yeri.be/2008/08/photo.jpg" alt="" width="320" height="480" /></a></p>
<p style="text-align: center;"></p>
<p style="text-align: left;"><span style="color: #888888;"><em>(Howto <a href="https://web.archive.org/web/20090608030254/http://www.iphonealley.com:80/tips-and-tricks/take-screenshots-iphone-20-software" target="_blank" rel="noopener noreferrer">make a screenshot</a> on the iPhone)</em></span></p>
]]></content:encoded><category>Software</category><category>www</category><category>iPhone</category><category>pda</category><category>plugin</category><category>wordpress</category></item><item><title>Wordpress stats</title><link>https://yeri.be/wordpress-stats/</link><pubDate>Sat, 23 Aug 2008 17:25:42 +0200</pubDate><author>Yeri Tiete</author><guid isPermaLink="true">https://yeri.be/wordpress-stats/</guid><description>&lt;p&gt;Took me a while to figure out what went wrong.&lt;/p&gt;
&lt;p&gt;With the new Firefox (v3) and the wordpress update, I was no longer able to see my &lt;a href="http://wordpress.org/extend/plugins/stats/" target="_blank"&gt;Wordpress stats&lt;/a&gt; on my dashboard.&lt;/p&gt;
&lt;p&gt;Every (Wordpress) login attempt, to see the stats, resulted in&amp;hellip; Well nothing. I just kept getting back to the login page. No error.&lt;/p&gt;
&lt;p&gt;Actually, I have &amp;ldquo;third-party cookies disabled&amp;rdquo; on all my browsers; I don&amp;rsquo;t like to have cookies from sites I do not visit. And this was the cause of the problem.&lt;/p&gt;</description><content:encoded><![CDATA[<p>Took me a while to figure out what went wrong.</p>
<p>With the new Firefox (v3) and the wordpress update, I was no longer able to see my <a href="http://wordpress.org/extend/plugins/stats/" target="_blank">Wordpress stats</a> on my dashboard.</p>
<p>Every (Wordpress) login attempt, to see the stats, resulted in&hellip; Well nothing. I just kept getting back to the login page. No error.</p>
<p>Actually, I have &ldquo;third-party cookies disabled&rdquo; on all my browsers; I don&rsquo;t like to have cookies from sites I do not visit. And this was the cause of the problem.</p>
<p>Simply add an exception for &ldquo;*.wordpress.com&rdquo; and you&rsquo;ll be able to view all your stats again. :)</p>
]]></content:encoded><category>Errors</category><category>Software</category><category>www</category><category>stats</category><category>wordpress</category></item></channel></rss>