03
Sep 07

Migrating your MySQL database from Dreamhost

Those of you who are still using the Dreamhostess with the Mostest (downtime) are probably looking for another solution for your webby goodness after the networking train wreck of the past few months (1, 2, 3, 4, 5, 6, you get the picture. By the way, if this sounds like awesome hosting to you, by all means, use my referral link when you signup with them! ).

You know I’m in love with Slicehost, for all the wrong reasons (they tease me with wait lists to even sign up, then they hit me with the pure root goodness, and I’m jonesing for another hit). I’ve got my Debian VPS all setup to roll, just need to get my data from Dreamhost over to the new server.

Website files? No problem. I used handy old rsync, and even put together a little bash script that I reference from a cron job, to do regular syncing of the Dreamhost data until I’m ready to go live with the new site.

But what about the database? My websites are all database driven, which mean no MySQL migration = no website! I tried using the phpmyadmin interface first, and simply exporting / importing the database from one install to another. Well, the database file is about 30 MB (this is a pretty big blog we’re moving), so that’s right out!

What’s a noob server admin to do?

mysqldump

Command Line to the rescue! Shut down that phpmyadmin, and crank up ye olde terminal. SSH into your new server, the one you are migrating to, and run the following command. The username and password in the first part should be for the MySQL database you are migrating FROM, the second part of the command should use the username and password you are migrating TO. Everything in CAPS should be replaced with your own details. No line breaks, put the whole thing on a single line:

Now that is Easy Breezy Covergirl!

IP Access on Dreamhost

If you’re moving your database away from Dreamhost, you’ll need to do a little unlocking of the database first. Dreamhost restricts access to your databases by IP address (or the resolved domain name equivalent). This a good thing, a security feature, but it will thwart our attempts to use mysqldump from our new server. No worries, you can add access for whatever IP your new server is on. Here’s how it works.

From your Dreamhost control panel, hit Goodies >> Manage MySQL. Locate the database you’re migrating, then click on the USERNAME next to the database. It will take you to a page that lets you manage the privileges for that user. Toward the bottom, find the option for “Allowable hosts.” It will look something like this:

allowable hosts

The %.dreamhost.com line should be there by default, allowing any dreamhost server to get at your data.

You will need to add a new line, containing the IP address (or IP range using wildcards) for the server you intend to migrate to. Note that the IP address they list beneath this is the IP address for your current browser connection to the control panel, not the IP address you need to use in order to allow server access from your new machine. Don’t be fooled!

If you are on Slicehost, you have a dedicated IP number that you can use here.

Save, exit, run the command line for mysqldump from your new machine, and you should get a clean import of your database into the new server.

Taste the Freedom!

PS. Don’t cancel that dreamhost account just yet, though. Sometime in the future, I’ll show you how I used .htaccess on my new server to treat my dreamhost account like a big ole’ hard drive for storing and serving large media files.

Make Dreamhost your bandwidth bitch!

Popularity: 26% [?]


07
Aug 07

Plate Up! Bash Script for Apache VHost Setup

In the sisyphian marathon of blowing up and rebuilding my server, I’ve had to go through the process of reconfiguring my virtual hosts for Apache2 several times. Well, that gets a bit tedious. How can my hands do the very important jobs of holding a beer up to my lips whilst scratching my man candy if they have to keep typing “sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/newdomain.com” over and over again?

bash it!

Fear not, my young linux adventurers. There IS a better way! Pop that cold beer, pull up some sweats, and feast your eyes on my hand dandy little bash script for automatically setting up yon website. Here’s what it does, in a nutshell:

  1. Asks for the new domain name
  2. Creates a new folder in the user folder with the domain name (/home/user/DOMAIN.COM)
  3. Creates a basic index.html file in the new domain folder that displays the name of the domain when accessed.
  4. Rolls 2d6 for Hacker Shield, to prevent magic-based attacks against your website. (planned for version 0.2)
  5. Generates a vanilla Apache vhost config file spelling out how Apache should handle requests for that domain.
  6. Generates an access log and an error log
  7. Generates a cgi-bin folder within the DOMAIN.COM folder

The script assumes you have Apache 2.2+ installed.

The non-compliance disclosure

Keep in mind that this script was written by me, for me, to help save me some effort. Because of that, it uses some non-standard locations for things. Why? Because I likes my shit where I likes my shit, that’s why!

I like having my apache vhost config files in my user folder, so that I don’t have to hassle with permissions. You can do the same thing with these two commands. First, make yourself a few new directories:

mkdir -p ~/www-config/sites-available
Then, link the apache site config folder to your new folder. Make sure this all goes on one line:

sudo ln -s /home/USERNAME/www-config/sites-available /etc/apache2/sites-available/

So where are things placed with this script?

config:
/home/USERNAME/www-config/sites-available/DOMAIN.COM

website documents:
/home/USERNAME/DOMAINNAME.COM

index page:
/home/USERNAME/DOMAIN.COM/index.html

access log:
/home/USERNAME/logs/DOMAINNAME.COM/access.log

error log:
/home/USERNAME/logs/DOMAINNAME.COM/error.log

cgi-bin:
/home/USERNAME/DOMAIN.COM/cgi-bin

The Script

Here ’tis. Click here to view or download a .txt file with the script.

http://commandlineidiot.com/scripts/siteup.txt

To use it, do the following:

mkdir ~/bin
cd ~/bin
wget http://commandlineidiot.com/scripts/siteup.txt
mv siteup.txt siteup
chmod 755 siteup

Now, to invoke the script, type the following:
. ~/bin/siteup

If you want to find out more about bash scripts, including how to handle permissions and setting paths so that your scripts can be called by name, I highly recommend the following tutorial by William Shotts Jr. at LinuxCommands.org: Writing Shell Scripts

Questions? Comments? Feck Off! I’m too busy drinking this cold beer and fiddling my diddly.

Popularity: 27% [?]


07
Aug 07

postfix, dovecot, emailtastic!

I’ve gots the email! I gots the email!

Christopher Haas has written what might be the best tutorial I’ve ever run across for linux. It’s accurate, complete, breaks things down into manageable steps, and explains what you’re doing while you do it. It also contains several “check” steps, where it shows you how to check your system logs to see if the previous steps went as planned.

This is what a tutorial should be!

Howto: ISP-style Email Server with Debian-Etch and Postfix 2.3

If you’re trying to get email up and running on your debian VPS, this is the place to start. It shows how to use postfix and dovecot, with secure login, spam and virus checkers. Everything you need for POP or IMAP.

Take note of the warning up front about the proper naming scheme for your host. Almost every VPS image that I’ve run across uses a default naming in /etc/hosts and /etc/hostname that is incorrect for proper configuration of postfix (or even apache!). This article explains why and what to do about it:

Naming Issues with Linux and xBSD

Happy installing of email!

Popularity: 14% [?]


02
Aug 07

show version

Just ran across a very useful little utility called apt-show-versions. It shows you the version installed for each of the apps you have on your server, along with whether or not they are the latest version. Used in conjunction with the apt-cache show command, this makes for a handy little set of tools for working your way through tutorials.

It’s available through the repository on Debian Etch and Ubuntu

sudo apt-get install apt-show-versions
To see everything installed via apt, use the bare command
apt-show-versions
Or you can use it to check on a single package
apt-show-version nano

Popularity: 14% [?]


25
Jul 07

Why I Wrote *that post*

One of the first posts I wrote on this site was about my frustration with getting good data on the difference between linux distros. It was titled, “Linux Users Are All Crazy Fundamentalists.” It has generated a ton of traffic, and comments from all perspectives.

I’ve held off on responding to the comments here because, for the most part, the article stands on its own. I feel like I need to respond, however, to Nick and James, and some of the other comments, to clarify my intent and purpose.

I do not expect anything to be handed to me. Never have. I understand the tradeoffs between proprietary solutions and open-source, and I am willing to embrace the challenges in order to use a free and open system. What I think you’re not understanding is that I want to become part of the contributing community surrounding linux. I want to understand, and help others to understand, how this things works. I’m not looking for someone to hand me a turn-key solution that involves no effort on my part. I want to build a server, I want to know how it works, and then I want to become part of the beautiful social cycle of reciprocation, where I pass that understanding on to those who stand where I stood.

I wrote this post out of the frustration that grew up because of that desire. I approached people with an open mind, a willingness to learn, a pretty sharp brain, and a idea of what was I was looking for in a linux platform. I wasn’t looking for someone to make a choice for me, I was looking for some reasonable basis from which I could make that decision on my own. I was confronted with a barrage of awful information, people barracking for their own cult-of-distro, rather than giving any consideration to the possibility that their might be reasonable choices outside of their own preference.

If I’m trying to build a fast and stable server, why the hell do I care if Debian does or doesn’t support a certain video card? Who cares which desktops interfaces are compatible? I’m going to use the command line, and the box will never have a monitor plugged into it. Yet, everywhere I went, there was some Ubuntu fanboy telling me that I was an idiot if I chose debian, or gentoo, or whatever, because it wasn’t compatible with xyz soundcard, or video card. Repeat 20x, for each distro, for a dozen different reasons that had nothing to do with what I actually needed out of my install.

And that, my friends, smacks of fundamentalism. When you remove yourself from reasonable discussion, and instead rely on the loudest rhetoric to make your point, you’ve lost me. Maybe that’s how the linux community protects its borders, by making bloodsport of noobies. Maybe it’s how the 12-year-old fanboys express the eternal adolescent insect of social herding. Either way, it’s frustrating and counterproductive.

I am not frustrated by choices. I’m frustrated by people who want to make those choices for me, who want me to fall in line with their gospel, and then insult my intelligence by not offering a reasonable basis for their loudly proffered opinions.

Popularity: 21% [?]


25
Jul 07

RSS into Facebook

Taking a detour from setting up the server to look at Facebook for a little bit.

I teach at a local University, and I use a course website very aggressively – lecture video podcasts, additional materials for them to research, sample projects, everything they need is posted on the course site. I also update the course schedule, lectures I’m going to miss, changed dates for exams, etc.

The course site is using WordPress as the platform, which means feeds are generated for everything. This should make it trivial for students to stay updated with the changing content, but very few of my students understand RSS feeds. Many of them don’t even check their email, which makes RSS-to-email options untenable. They all have facebook though. Every single one of them.

I’d like to find a way to integrate an external RSS feed into the facebook notification system for students who opt-in. That way, I can update the course site, say post a lecture video, and the students who have opted-in will automatically be notified of the update, along with a link back to the original post.

It looks like the new facebook apps development platform is the best bet for getting this done. Anybody have any experience in developing for Facebook, or know of some code out there in the world that already does something like this?

Popularity: 10% [?]