Serving Web Sites from Virtualbox Guest to Windows Host

I’ve been going mad trying to understand how I’m supposed to set up my Ubuntu guest on Virtualbox so that it can serve web pages to my Windows host. I thought you were supposed to use the Bridged Adapter, but when I tried that Ubuntu lost its connection to the Internet.

Endless searching followed by a brief foray into the world of vbox IRC led to more dead ends. The IRC chat led me to the understanding that I needed to set a static IP address within Ubuntu. This led to more confusion and still no connections.

Finally, I discovered this post, leading me to further believe that one of the values of Drupal is that there is spin-off of documentation into many other areas other than Drupal:

http://friendlydrupal.com/screencasts/drupal-development-ubuntu-virtualbox-part-6-serving-websites-ubuntu-windows

The short-version of this solution is that you have to use two adapters: Host-only & NAT.

I can only surmise that NAT gives you access to the outside world, while Host-only allows your host to have access to your guest. Seems reasonable.

The very tricky part, that I still don’t understand is the configuration within the /etc/network/interfaces Ubuntu file:

auto eth1
iface eth1 inet static
name Ethernet alias LAN card
address 192.168.56.11
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0

auto eth1:0
iface eth1:0 inet static
name Ethernet alias LAN card
address 192.168.56.12
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0

auto eth1:1
iface eth1:1 inet static
name Ethernet alias LAN card
address 192.168.56.13
netmask 255.255.255.0
broadcast 192.168.56.255
network 192.168.56.0

I have a hazy idea of what it all means. The line “name Ethernet alias LAN card” did not appear in any of the posts I saw. And this post is pre VBox 4.1.8 which is what I’m using.

That concerns me a bit, because I believe this is the set up people needed to use before the latest VBox. The documentation suggests that using the Bridged Adapter is relatively configuration free when compared to previous versions. How, without configuration, you would access pages served from the Ubuntu guest, I do not know, which makes me wonder if I didn’t actually want Bridged Networking to begin with.

The phpMyAdmin Ubuntu Blues: Crank it up to 11!

Just set up LAMP in Ubuntu. Went to import Drupal database into MySQL via phpMyAdmin and this is what happened:

phpMyAdmin:

No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16.

phpMyAdmin documentation:

The first things to check (or ask your host provider to check) are the values of upload_max_filesize, memory_limit and post_max_size in the php.ini configuration file. All of these three settings limit the maximum size of data that can be submitted and handled by PHP. One user also said that post_max_size and memory_limit need to be larger than upload_max_filesize.

Where is the php.ini file in Ubuntu?  /etc/php5/apache2/php.ini

What should I set those values to? 11!! Actually 128M is the max. I’m doing this locally, so I’m not concerned about other repurcussions of maxing these values out.

I’m sorry Dave, I can’t do that. It’s not working?! Don’t forget the reboot:

sudo /etc/init.d/apache2 reload

VirtualBox User Groups in Ubuntu

If you want your guest installation of Ubuntu to have access to a shared file on your host machine, you need to add the Ubuntu user to the “vboxsf” group.

This post talks about how to do it in 11.04 but in 11.10 the user account menu does not have the Manage Groups option.

You apparently need to install the old user menu, which you can do following these instructions:

1. sudo apt-get install gnome-system-tools

2. go to the dashboard, search for “user” and click on “Users and Groups”

Now you have GUI access to groups.

The default location for shared files is /media where the file you set up to share in the VirtualBox preferences will be there with the sf prefix. Example: sf_MySharedFolder

Cheat Sheet for Adding Virtual Hosts in Ubuntu

I got most of this from here, except the hosts file editing, which seemed to be left out of every page giving instructions for setting up virtual hosts in Ubuntu that I came across.

1. mkdir /var/www/site1

2. cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site1

3. Add virtual host info to /etc/apache2/sites-available/site1

  • replace /var/www with /var/www/site1
  • Add “ServerName site1.local” (site1.local can be whatever you want your web site address to be locally)

4. sudo a2ensite site1

5. edit the /etc/hosts file: 127.0.0.1 site1.local

6. sudo /etc/init.d/apache2 reload

7. Forbidden!? If you try to go to your new site and are told that you are forbidden to do so, you may be trying to install Drupal. Or something else. In any case, change the permissions to your site’s directory and the world will be a better place:

sudo chmod 777 -R /var/www/site1

8. Clean URLs

  1. enable mod_rewrite by typing this in Terminal: sudo a2enmod rewrite
  2. Edit /etc/apache2/sites-available/site1 to AllowOverride All rather than AllowOverride None:

    <Directory /var/www/site1/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

  3. If you’re using Drupal, set up Drupal to use Clean URLs.

Setting Up Mercurial on Windows (Cygwin)

To make it a little less cumbersome, why not set your username:

http://www.selenic.com/mercurial/hgrc.5.html#contents

If I do not commit without adding a message I get an error stating

/bin/sh: vi: command not found
abort: edit failed: vi exited with status 127

Not sure why that is, but when I add a message, it works fine:

hg commit -m "Look, ma, I'm only bleeding."

Blogger to WordPress

It seems that with WordPress 3.3.1 the Blogger importer isn’t working. It could also have something to do with the fact that the Blogger blog I was using was on a personal domain managed by Google, causing problems with authentication.

The way around this is to export your Blogger blog through that functionality and then use the blogger2wordpress conversion tool. http://blogger2wordpress.appspot.com/

Then you use the WordPress import to import that file. However, that import did not import my tags and categories into my private WP install. So, I created a blog at WordPress.com and imported the file into that blog. That did import the tags and categories, however it seemed to make everything a category and now there are no tags. Good enough. I then exported that WordPress.com blog and imported that file into my persona WP installation.

Now, I’m just looking for a tool to dump my categories into tags.

…and there’s a tool for that. Manage -> Tools -> Import provides a Category to Tag exchanger: http://en.blog.wordpress.com/2007/10/08/category-to-tag-converter/

Sitemaps

You can put a reference to your Sitemap in your robots.txt file. Who knew?You can specify the location of the Sitemap using a robots.txt file. To do this, simply add the following line including the full URL to the sitemap:Sitemap: http://www.example.com/sitemap.xmlhttp://www.sitemaps.org/protocol.html

Drupal Backup error message: need to create temp directory

If you are trying to use the Drupal Backup module and get this error

* Your temporary directory is not writable. Backup and migrate
needs to be able to create temporary files.
* The file /backup_migrate_4ead6b393eb5e.
* Could not complete the backup.

Go to /admin/settings/file-system page. Just going there will create a temp directory. You should see a green message that says that the directory was created. But make sure the temp directory listed is a real directory. Even if it isn’t, you should be able to go back to the Drupal Backup and download your backup.

Password Protect Your Web Site

You can password protect your web site or just directories within the site using HTTP Authentication. In practical terms, that just means you need to create a .htpasswd file and a .htaccess file.

In my case, I’m password protecting a Drupal installation. Drupal already uses a .htaccess file, so I just tacked the necessary code onto the end of the existing .htaccess file, because I want to password protect the entire site. I could also just add these files to the /sites/default/files directory, for example, if I just wanted to password protect those files.

Htaccess Tools (http://www.htaccesstools.com/) is a nifty site where you’ll find everything you need. However, it can be a little overwhelming at first, and if you just want to slap a password on the site you’re developing, here’s what you need to do.

Go here to first create your .htaccess code: http://www.htaccesstools.com/htaccess-authentication/

When it asks for the path, that is the FULL PATH to where you plan on putting your .htpasswd file. This is not a relative path, so don’t uses something like “/.htpasswd”. That won’t work, and it’ll result in an error after you submit your user name and password. If you were using this on a local set up, and you had your web site files located in C:website and you wanted to protect your entire site, then your FULL PATH would be “C:website.htpasswd”.

The next thing you have to do is create the .htpasswd file. YOU CANNOT SIMPLY TYPE IN A LOGIN NAME AND PASSWORD! The password needs to be encrypted. And, of course, Htaccess Tools, has a tool for that!  Go to: http://www.htaccesstools.com/htpasswd-generator/

Just enter a username and password in the form and enter the result into a .htpasswd file.

Put both of those files into your directory. Then test it out. It should work fine, and you should only have to enter the login information once.