Tag Archives: virtualbox

Error Establishing a Database Connection

I hadn’t started up my virtual test server since changing the network configuration to get port forwarding to work properly. Today when I tried it out, I got the dreaded “Error Establishing a Database Connection” message on all my local WordPress sites.

Even the mysql client couldn’t connect to the database, and of course neither could phpmyadmin. The database server was running and I had even restarted it multiple times to make sure. Removing it and installing it again didn’t help either.

I finally found the problem in the mysql config file in /etc/mysql/my.cnf. The bind-address setting was set to the old fixed IP address I had been using. I’m not sure why it hadn’t broken before when I first changed from a fixed IP to the Virtualbox NAT. I changed it back to ‘localhost’, restarted mysql server, and all my sites started working again.

EDIT: I realised from WordPress.com’s statistics page that there are quite some visitors landing here by searching for the title. The information above is probably not what you’re looking for.

If you’re getting this error on your WordPress.org self hosted install, check the settings in the wp-config.php file. If you’re unsure what the values should be, ask your hosts. Every host configures their servers in their own way. Some have the database on the same machine, so the DB_SERVER setting is ‘localhost’. Others might put it on a dedicated database server with its own hostname. Also make sure that your hosting plan lets you use a database. Some of the cheapest ones may not.

If you’re still stuck, post a question in the Installation or How-to and Troubleshooting sections of the WordPress.org forum.

Networking Woes

After changing ISP, I got a new modem with a built in wireless router. I managed to configure port forwarding and get it to work with my test server running on VirtualBox. Just for the record, the port forwarding interface on the device required me to select from a list of devices. I had to port forward to the host machine’s IP.

After some weeks of using the built in wireless router, I got tired of the weak signal strength. To be fair, it might be because it is placed in a less centralized location due to wiring constraints. I decided to connect my Linksys router to it and use the Linksys device for wireless service.

I had previously tried connecting a LAN cable from the local Ethernet port of the ISP provided modem to the WAN port of the Linksys device. That didn’t work at all. However, it does work when it’s connected to a LAN port on the Linksys device. I’m not sure why that’s the case as I thought putting it to WAN would just send all the packets through another layer of address translation.

Next step was to disable the wireless network on the built in modem and make sure that the Linksys router was configured with the desired settings. This was accomplished with the provided web administration interfaces.

When I tested the network, some devices could get Internet access, while some couldn’t. I had to disable and re-enable the wireless network adapter to get it to work.

Unfortunately, all these steps broke port forwarding to my guest OS. I had VirtualBox set up to use a bridged network, but it looked like the modem didn’t even recognize the guest as its IP did not show up in the list of connected devices.

I looked through the other network options in VirtualBox and looked up the documentation.

It turns out that with the NAT option, I could run a server on the guest OS if I configured port forwarding with VBoxManage. There’s even an example on the page.

Shut down the guest OS, change the networking option to NAT, and run the following command.

VBoxManage modifyvm "guest-name" --natpf1 "guest-https,tcp,,443,,443"

Restart the guest. As no IP address was specified with modifyvm, it is necessary to use DHCP on the guest. Change the networking settings, restart the eth interface, and try to access the web server.

A request to the web server now goes to the modem, where it is forwarded to the host machine, which then forwards it onwards to the guest! A little convoluted, but once again my test server is publicly accessible so I can ask friends for feedback.

Ubuntu 11.04 Colour Scheme

Once again the problem of an ugly colour scheme returned. Instead of a sleek looking theme, I got the root theme which looks like it came out of Windows 10 years ago.

A Google search with the keywords “virtualbox ubuntu 11.04 ugly theme” led me to a Ubuntu forums thread with a link to the Virtualbox forums.

Here’s the solution which worked.

Open a terminal window, go to your home folder (don't forget that) and type:

sudo gedit .gtkrc-2.0 (DO NOT forget the dot in the beginning of the filename)
Type your password and when gedit opens copy/paste the following two entries in that new file.

include "/usr/share/themes/Ambiance/gtk-2.0/gtkrc"
gtk-icon-theme-name = "ubuntu-mono-dark"

The second line will fix the icons in Nautilus.
Save the file, close gedit and restart your VM and...

VirtualBox Screen Resolution

After updating to Ubuntu 11.04, the screen resolution got messed up. It refused to recognize the native resolution of 1280×1024, but instead just used 1024×768. What’s the point of having a nice large monitor if the OS can’t recognize it?

I first tried editing the xorg.conf file, using the instructions at metafilter.

That didn’t work, but a few other posts suggested installing the VBoxAdditions. I thought I had already done so, but reinstalled it again to be sure. Sure enough, after the restart, the screen showed up at the full resolution.

Another problem was that the ugly root theme kept showing, no matter what I did. Although it seems a bit dangerous, I finally tried creating some symbolic links to get the root theme to look the same as what I want to use. Instructions are on tombuntu.com

Expanding VirtualBox Partition

Trying to update to Ubuntu 11.04 on my trusty virtual machine today, I got a message saying that the disk was full.

Since the VM is just a file on my windows hard drive on which I have plenty of space, I thought it would be fairly easy to just increase the size of the file and thus give me enough space. Turns out there are a few more steps than that.

The first thing to do is to increase the size of the VirtualBox file. This can be done with the VBoxManage command from the windows command line.

VBoxManage modifyhd d:\ubuntu.vdi --resize 12200

Replace the filename with your own vdi file and the number with the desired size in megabytes.

This only adds unallocated space to the virtual computer. The next problem is to add this to the root partition. This can only be done when the partition is not mounted and thus requires booting from a live CD. I don’t have live CDs around but I do have a USB thumbdrive with a copy of Ubuntu on it. However, it’s not that easy to boot to a USB drive from VirtualBox. It involves fooling the system into thinking that the USB drive is actually an IDE drive.

Follow the instructions at agnipulse.com to see how to accomplish this. When running the command line command and when adding the vmdk file, run the command line and VirtualBox in Administrator mode, or it’ll fail with funny errors. This was mentioned in some VirtualBox forum threads.

VBoxManage internalcommands createrawvmdk -filename d:\usb.vmdk -rawdisk \\.\PhysicalDrive1

Which PhysicalDrive number the USB drive is actually at should be checked from Disk Management.

After booting up to the USB image, run GParted. Delete the extended partition containing the swap partition. Extend the primary partition then add the swap partition back at the end of it.

That’s it! Enjoy the glorious extra space now available on the root partition.