Error Establishing a Database Connection in WordPress

I am working on a project with a friend. We are developing a new WordPress website. I am doing the background IT stuff and he is designing the web site.
I want to share my experience of handling the dreaded “Error Establishing a Database Connection” in WordPress. I have not found a similar case while researching this problem, and I want to share the “false” rabbit trails that I went down, trying to solve this problem.

A few nights ago, about 10:00, I received a text message out of the blue from my partner, saying we was busy developing the website, and all of a sudden he went to view it and he got a white screen saying “Error Establishing a Database Connection”. He wanted to know if I was doing something on the web site. I was not. He then informed me that he lost control of the “admin” side of the website as well.

I instantly got a knot in my stomach, as this website has to be up soon, and we have been having difficulties for a while and finally set up a new hosting account.

A little back story:
I used the easy 1 click WordPress install that many hosts have available. Why not? It’s easy!
I adjusted the php version to the latest, set some php parameters that are necessary for the website like the upload size, etc.
Uploaded the purchased theme we are using.
Installed and activated all the necessary plug-ins for the theme.
And set up an additional Admin user.

Perfect. Right?

My partner then went at his magic and started designing the website. As I mentioned before, after several hours of work, and about 10:00 at night, I received a text saying “I am getting an ‘Error Establishing a Database Connection”. Are you doing anything? My response “No, Arrrg!!!” He then said he just lost his admin login also.

The first thing on-line guides will tell you, is to check the database credentials: database name, database user name, password.  I knew these didn’t randomly change.  I tried running a small script to test the database connection and got a 500 internal server error. Ouch.

I logged into the hosting control panel and started fiddling around. I looked at the database, and it all looked ok… for a while. Then I lost connection and the control panel asked me for the password for the database user. Upon searching the web for solutions, the suggestion that the MySql server was down. That seemed likely to me, or at least trying to go down as things were intermittent. Little did I know, I was on a wrong rabbit trail. I fought with that for some time.

I looked into rebuilding the database within WordPress. There is a command that can be added to the end of wp-config.php, and go to a certain url withing your website (Google it), and you should come up with a little menu that enables you to check the database and fix things. I could not access that.

Using the control panel supplied file manager, I manually disabled all the plug-ins. I thought maybe there was a rogue one there somewhere. Ta da… I was able to access the database-fix url. I did that. Then I had admin access. I also had limited access to the actual web site, but some pages were blank. No error, just a white screen. I reactivated the plug-ins and boom, it went down again. I thought I would have to enable one at a time until the nasty one showed its ugly side. I had to do the database rebuild thing each time to gain access. Again, I was on a rabbit trail that I did not intend on being, without knowing it.

In the mean time, my mind was going a hundred different ways. I went to our theme’s web site to see if there was an update beyond the version we had.

There was one a couple of days ago. I looked at the version change log and there was nothing big to that update. BUT… I looked down the change log to previous versions and something caught my eye. An update a while back made the theme compatible with PHP V7.0. Hmmmm, PHP V7.0. When I set everything up, I set the php version to the latest which was….. V7.1! I went into the php configuration and set it from V7.1 down to V7.0. Bada bing bada boom! The site came up. PERFECTLY UP!

The whole time, I had the php version wrong. While my partner was coding away, it must have been hours before he hit a feature that was not compatible with V7.1 and down it went.

As I looked back, I did not come across any website that pointed to this type of problem. So, if you are having an unsolvable problem with your WordPress site losing communications with its database, and all the usual fixes don’t seem to work, maybe… just maybe, you might have the same problem we did. I hope this helps someone!

-John.

WordPress 3.9 Lost Functionality, Image Borders, and Margins

wordpress
With “Advanced Image Styles” plug-in, borders and margins can again, be easily set.

I just updated to WordPress 3.9 and with my first post, was disappointed. When an image is placed in a post, the text is smashed right up to the image.  In older versions, a margin of space could be put around the image, along with a border if wanted.  This needed functionality is now lost with WordPress 3.9.

Thankfully one of the developers created a plug-in called “Advanced Image Styles”.  This returns some of the functionality lost with this version of WordPress.  In older versions, there were more options to scale images that are gone now also.  It is kind of interesting that one of their own developers wrote this plug-in, to try to compensate what they took out.

For now at lease, install the “Advanced Image Styles” plug-in to get some of the functions back.  Maybe if enough people scream, they will put it back in.

**EDIT** It seems that when a caption is added to the image, as the one above, the caption width is not adjusted to compensate for the width of the image plus the margin widths.  I manually adjusted the code to make it look right.  I left a comment on the plug-in’s development page about it.

**Another EDIT** The plug-in author responded to my comment on the plug-in’s development page and pointed out that the caption width didn’t work in the previous version of WordPress either.  I all fairness, I realize that I should not suggest this is something he should fix in his plug-in.  As Gregory pointed out,

Ideally, this flexibility would be added to core.

-John. K7JM

WordPress 3.9 Jetpack Update Failure

wordpress I use WordPress as my blogging software.  Lately, my software updates have been failing.  Blogging software and other web/Internet software needs to be updated when there are discovered vulnerabilities just like other software.  I also use something called Jetpack that provides statistics and other functions for my blog.  It also needed to be updated and was failing.

To fix this:

  • First, log into your web site administration control panel however you do it.  For me, it is cpanel. Get into your file manager and find your plugin directory.  If you have ssh access, you can also do it via the command line.
  • Find the jetpack directory inside your plugins directory and delete the whole jetpack directory.  The plugins directory is inside of the wp-content directory.
  • Do a plugins update if required for other plugins
  • Do a WordPress update.  It took quite a while for me.  If it asks you to do a database update, do it.
  • Reinstall the Jetpack plugin and activate it if necessary.
  • Have fun.

I hope this helps someone with a similar problem.

-John – K7JM

The Amateur Amateur

Click to read “The Amateur Amateur”

I’ve enjoyed reading Gary Hoffman’s, KB0H, “The Amateur Amateur” on the ARRL (American Radio Relay League) web site for years.  The ARRL no longer publishes Gary’s articles, but he still writes them.  In Gary’s own words:

The Amateur Amateur is a column about my experiences in ham radio. Since I have little technical expertise and not much knowledge of electronics, I make a lot of mistakes. I consider myself to be just an amateur amateur radio operator, but I keep pressing on and trying new things. This column details my triumphs – and foibles – and I try not to take myself too seriously. Whether you are an experienced ham or new to the hobby, I hope you find these chronicles of my efforts to be entertaining.

Gary Ross Hoffman, KB0H

Gary’s “The Amateur Amateur” columns are available HERE.
Enjoy! -John, K7JM

Amazon Instant Video And Flash Update Fix

My family regularly view videos from Amazon’s Instant Video.  We went to rent a movie last night, and the Amazon Video screen said “Updating” and when it was finished, we received an error like that shown below.

After a lot of searching on-line, I found a discussion about the topic on Amazon’s Customers Discussions web site.  It appears that Amason’s Instant Videos, Flash, and Ubuntu all of a sudden don’t get along.  On the discussion page, there seems to be some fixes, mostly for Ubuntu 64 Bit operating systems.  I, however, run 32 Bit Ubuntu.  Thanks to one particular post by Erik, I found a solution that seems to work on 32 Bit Ubuntu systems.

Here is my solution based on Erik’s advice.

# Install the required packages.

sudo apt-get install hal

# Remove cached junk from Adobe and Macromedia.

# Back these up if you’re not sure what you’re doing.

rm -r ~/.adobe ~/.macromedia

# Reboot the computer.

#Start Firefox

# The Amazon player updates, and video rentals are now playable again.

Since I was trying all kinds of stuff, I didn’t really know what made if finally work, so to confirm my findings, I booted up the Alpha of Ubuntu 12.04 in Virtual Box, confirmed that Amazon Instant video choked, and repeated the above procedure. It worked for me. I am running 32 Bit Ubuntu.  I hopes this helps someone else!

John – K7JM

wview Weather On The SheevaPlug

I have, for a long time, wanted a real weather station at my QTH. For Christmas I received a LaCrosse WS-2315 weather system.  It measures temp, wind, wind direction, wind chill, heat index. barometric pressure, humidity, rainfall, and the dew point.

My computers run the Linux operating system.  Specifically, Ubuntu Linux.  I found some nice weather software called “wview” that is compatible with my weather station.  I put wview on my desktop, configured my weather station, and have it upload the weather data to my web site.  You can see it http://mcdougallshome.net/wx/.  The whole system worked real nice, but my desktop had to be powered on all the time, and for some reason, when one of my kids would get on it, the weather system would crash.

My solution is the “SheevaPlug” plug computer.  The SheevaPlug is slightly larger than a wall type transformer.  In fact, the SheevaPlug plugs into the wall just like a transformer “wall-wart.”  It also has an option for a power cord, which I find more convenient to use.

Here are some specs from this small box:

  • 1.2 GHz Arm processor
  • 1/2 GB RAM
  • 1/2 GB solid state memory
  • SD/MMC card slot,
  • USB port
  • Gigabit eithernet port
  • USB port to use your computer as a terminal for the SheevaPlug
  • It comes loaded with Ubuntu 9.04 for the Arm Processor

I added an 8GB SD card and upgraded it to Debian Squeeze since Ubuntu does not support the Arm processor anymore.  I then loaded up wview weather software, and my webcam software scripts.  And voila, it works!  It was a fun process and not as clear cut as one would think.  The SheevaPlug is a development kit; and therefore, has no instructions, but there is a lot of information on the Internet.

I made a video (actually three parts) showing an overview of the process that I took to get it all together.  Also, here are some pictures of the setup.

— John – K7JM

embedded by Embedded Video

YouTube Direktwview - SheevaPlug Part 1 embedded by Embedded Video

YouTube Direktwview - SheevaPlug Part 2 embedded by Embedded Video

YouTube Direktwview - SheevaPlug Part 3

Here is a list of web sites shown on my videos:

The Joy Of Ham Radio

Another Ham discovers Linux’s ham friendliness ARRL’s website has another nice story about a Ham using Ubuntu Linux and fldigi to renew his love for Amateur Radio.  Check out the post HERE.  Good going Steve (KØSRE)!  For more of Linux In The Ham Shack, check out “Linux In The Ham Shack” podcast.

– John, K7JM

Ubuntu and Ham Radio

The ARRL web site had a nice entry about Ubuntu for Ham Radio.  The article could have been four times as long and not cover all the aspects of why Ubuntu Linux is good for Ham Radio.  Also, several of the applications that the author mentioned in the ARRL article that he used with WINE, have alternates available for Linux, including PCB layout software, and Circuit analysis.  Almost ALL FREE.  Besides, Ubuntu’s super easy to install Ham Radio repository of applications, HERE is a page full of stuff, ranging from the latest and greatest to older Linux Ham Radio programs.  Ham Radio is about innovation, and experimentation.  It is sad to see so much of it is built up on a closed, unexperimentalable, unmodifiable, and costly solution like Windows.

73,
John – K7JM

It Happened!

I’ve been hacked! My web sites have been hacked.  Fortunately, the hack was so bad that it just broke the web site and I noticed it right away.  It looks as if they came in through my hosting company some how, but I have not received any notice that a server at the hosting company has been compromised.  I deleted the web site and restored it all from a reliable backup.  It was a learning experience; and I am glad that I am fanatical about backups!

73,
John – K7JM

How To Display A Text Document On Your Web Page

A Corner of My Web Page
The corner of my web page with a link to view my Ham Radio log file.

Being a Ham Radio operator, I’ve wanted, for some time, to display my log file on my web site. I’ve been researching it for some time, and mostly ran into methods that require java or php, or some sort of web scripting. This is beyond me and I wanted something simpler; and this is what I have come up with.

My computers run on the Ubuntu Linux Operating System.  I came across a small command line utility program called txt2html.  The name pretty much explains what it does.  It has many features that include many formatting options; one being, that I can pre-append a file to the front of another file.  I tested this feature to apply a preformatted html heading to my log page.  I made a simple sample of a text log page listing contacts, and ran it through txt2html and it attached my header to the log page and spit it all out as an html file ready to display on my web page.

My sample log page was called log.txt and looks like this:

call            QTH
k7jm            Helena, MT
wa7vxm          Butte, MT

My sample heading was called ‘log_file_heading.html’ and looks like this:

K7JM’s Log File

I put it all through txt2html with a command like this:

txt2html --append_head ./log_file_heading.html ./log.txt >./log.html

And the output file ‘log.html’ looks like this and is ready to display on your web page:

K7JM’s Log File

call            QTH
k7jm            Helena, MT
wa7vxm          Butte, MT

I wanted to automate a way to put this file on my web site without getting too complicated.  The simple ftp command would work, but it takes a bit to automate it. After a bit of research, I came across ‘kermit‘.  ‘kermit’ is a simple program that takes data from a file and performs the commands listed in the file.  Perfect.  I put the following commands in a file called ‘log.kermit’:

ftp open ftp.myhostsite.net /user:myusername /password:mypassword
put ./log.html /www/whereyou/wantit/log.html
exit

I then called kermit like this:

kermit ./log.kermit

and it is done.

To make things a bit cleaner and more automatic, I created a script file called ‘log_doit.sh’ that looks something like this:

txt2html –append_head /home/john/Desktop/log_file_heading.html /home/john/Desktop/cqrlog.html >/home/john/Desktop/log.html
kermit /home/john/Desktop/log.kermit
exit

Now, to do the whole process, I just had to update my log file, save it, and run the script ‘log_doit.sh’ and it would be on my web site.

A New Way – With cqrlog

After I put all this together, I remembered hearing about a Linux logging program called cqrlog, on the ‘Linux In The Ham Shack‘ (link updated 9/2010) podcast.  If you are a Ham Radio Operator or use Linux, I strongly suggest you give this great podcast a listen.  It is always entertaining, and they have covered some very useful stuff for the Ham that is running a Linux operating system.

Anyway, I downloaded and installed ‘cqrlog’ and started playing with it.  I was specifically looking for a way to export the log file so I could run it through ‘txt2html’.  Lo and behold, ‘cqrlog’ does one step better; it exports the log right into the ‘html’ format.  Wow! Perfect!.

I learned a lot by using txt2html, but now I can skip that step completely and just export the log file in html format and run a simpler script that runs ‘kermit’ to upload the file to my web site.  Click HERE to see the actual page on my web site.  As of when this was written, the file is a test one that was created by playing with ‘cqrlog’.  It will change once I start using ‘cqrlog’ for real.

John – K7JM

K7JM’s Log File

call            QTH
k7jm            Helena, MT
wa7vxm          Butte, MT