Versioning WordPress Content

Something that winds up being difficult when developing for WordPress (or Drupal, or any other database heavy CMS), is the versioning of content. Databases aren’t under your SCM directly. Because of this, deploying changes to production can be dicey.

The scenario is typically something like this:

  • Client wants 5 new pages, and a few revisions to existing pages.
  • Developer creates pages and makes modifications on staging environment.
  • Client requests revisions
  • Developer revises staging environment as requested.
  • Client approves
  • Developer has to remember what he did, and repeat those steps in production.

Needless to say, this practice is fraught with potential for error. If this is 80% successful, I’d be surprised. That’s not going to cut it for most clients however. If your doctor was 80% successful, you’d be very upset. If traffic lights were 80% successful, you might be dead.

So, there needs to be a way to snapshot your staging environment, and push it to production. Unfortunately, there aren’t many tools that do this sort of thing directly. Even the ones that do, are often not done very well. A hand-written solution is possible however. It’s really not even that hard to do.

Enter bash, and ant.

I suspect many of you are rolling your eyes right now. “BASH? ANT? That’s for nerds!” You’re right about that. However, to get across this issue, it’ll help you to learn from some nerds.

For this tutorial, let’s assume you have the following folder structure for your wordpress site:

ROOT
 - public (wordpress content)
 - var
 - - log
 - - backups
 - tmp (sessions, cache, etc)
 - etc (configurations)
 - bin (scripts)

Here’s a bash script you can run, to dump your database into 3 different formats (dev, staging, and production):

#!/bin/bash

#dump the database to var/backups, replacing local information
mysqldump -u root -p database_name > var/backups/dev.$(date +%Y-%m-%d).sql
mysqldump -u root -p database_name | sed 's/dev\.site_name/staging.site_name/g' > var/backups/staging.$(date +%Y-%m-%d).sql
mysqldump -u root -p database_name | sed 's/dev\.site_name/www.site_name/g' > var/backups/production.$(date +%Y-%m-%d).sql

# navigate to the backups folder, and create the updated symlink
cd var/backups

# remove old symlinks
rm development.sql
rm staging.sql
rm production.sql

# create new symlinks
ln -s dev.$(date +%Y-%m-%d).sql development.sql
ln -s staging.$(date +%Y-%m-%d).sql staging.sql
ln -s production.$(date +%Y-%m-%d).sql production.sql

That will dump the contents of your development environment, replacing anything that says “dev.site_name” into the appropriate substitution for your other environments. I use a development, staging, and production environment for most of my work, but you might have different ones. Adjust these scripts as necessary to accomodate what you require.

One more note: That script will ask you for the root password three times. You’re more than welcome to change the user from root as well. I do this, because typically I run these scripts on my local machine. I don’t really care about username / password security of the dev sites on there. I’m not using those credentials anywhere else.

So, to import these changes into a staging, or production environment, I typically use ant. This automates most of the work for me. Here’s an example script:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="sitename.com" default="build">

    <!-- build details left out for brevity -->

    <target name="backup-development">
        <exec dir="${basedir}" executable="bash" failonerror="true">
            <arg line="../bin/backup-development.sh" />
        </exec>
    </target>

    <target name="import-development">
        <exec dir="${basedir}" executable="mysql" failonerror="true">
            <arg line="-u mysql_user -pdatabase_password mysql_db_name -e 'source ${basedir}/../var/backups/development.sql'"/>
        </exec>
    </target>

    <target name="import-staging">
        <exec dir="${basedir}" executable="mysql" failonerror="true">
            <arg line="-u mysql_user -pdatabase_password mysql_db_name -e 'source ${basedir}/../var/backups/staging.sql'"/>
        </exec>
    </target>

    <target name="import-production">
        <exec dir="${basedir}" executable="mysql" failonerror="true">
            <arg line="-u mysql_user -pdatabase_password mysql_db_name -e 'source ${basedir}/../var/backups/production.sql'"/>
        </exec>
    </target>

    <target name="development" depends="clean,build,import-development" />
    <target name="staging" depends="clean,build,import-staging" />
    <target name="production" depends="clean,build,import-production" />
</project>

So, the process now goes like this:

  • Client wants 5 new pages, and a few revisions to existing pages.
  • Developer creates pages and makes modifications on staging environment.
  • Client requests revisions
  • Developer revises staging environment as requested.
  • Client approves
  • Developer runs backup scripts, and adds updates files to SCM.
  • Developer runs update on production, which should also fire the import-production target

There’s plenty more to this than what I’ve written so far, but this is the generality I’ve been working with for a while. It’s served me pretty well.

HTML5 and CSS3 Works in IE

Well, kinda …

CSS can be a major headache for unseasoned front-end developers. The intricacies of layout design and how different browsers interpret them is the bane of a designers existence. The most common problem we have is how IE has handled this.

With a few tools though, sanity can be restored to UI development.

First, always use a CSS reset stylesheet. This reduces the number of things to keep track of when doing styling by a ton. I’m personally fond of Eric Meyer’s CSS reset code.

Second, get the Modernizr javascript code on your site. There’s a number of things this will do for you, including adding css classes to the html tag indicating the browser’s capabilities, and modifying HTML5 markup to work in IE6. Trying to work in IE6 without javascript? Let it go. Somethings aren’t worth fighting for.

Third, I really recommend the HTML5 Boilerplate. Actually, just reading through that is a learning experience. Even if you d on’t use the templates, you’ll know much more about how to make a very accessible and cross-browser / cross-platform usable site.

So, with all of these tools in place, you can do a few things in your CSS that should work safely for any browser. I’m partial to Facebook-style transparent borders, so let’s start there. (Note: There is an excellent demonstration of this at CSS-Tricks that explains this very well)

HTML (5ish)
<section class="clear-borders">
<article>
<p>Lipsum, oh yeah</p>
</article>
</section>

CSS
.clear-borders {
/* the borders (older browsers will only read the first definition */
border: 10px solid #999;
border: 10px solid rgba(170,170,170,0.5);

/* again, older browsers won't understand these definitions, so they'll be skipped */
-moz-background-clip: border; /* Firefox 3.6 */
-webkit-background-clip: border; /* Safari 4? Chrome 6? */
background-clip: border-box; /* Firefox 4, Safari 5, Opera 10, IE 9 */

-moz-background-clip: padding; /* Firefox 3.6 */
-webkit-background-clip: padding; /* Safari 4? Chrome 6? */
background-clip: padding-box; /* Firefox 4, Safari 5, Opera 10, IE 9 */

-moz-background-clip: content; /* Firefox 3.6 */
-webkit-background-clip: content; /* Safari 4? Chrome 6? */
background-clip: content-box; /* Firefox 4, Safari 5, Opera 10, IE 9 */
}

The end result here is that older browsers will use the hex color border. So, when you create these colors, try to be pretty close to what your transparent color looks like in actuality. Newer browsers will pick up on the rgba and background-clip definitions.

Keep Your SSH Identity

So, I’ve been doing a ton of stuff lately on a ton of servers. Almost all of this involves using git to clone repositories into a multitude of servers. The problem with this, is that I’m limited to a single SSH key for all of my git clones. This is tricky, since shelling into a remote box doesn’t give you access to your remote key by default. But you can still keep your SSH identity …

There’s two ways to go about keeping the identity you require through multiple single-level-deep connections. That basically means, you can keep your SSH identity from one box to another. If you hop from one box to another and another, I can’t help you. There’s probably a way to do it. I don’t know it.

Anyways: TWO ways to do this. Both of these options assume you’ve got ssh-agent running on the machine you wish to transfer your identity from. To get this running, do the following:
eval `ssh-agent`
ssh-add

This ensures the ssh-agent daemon is running, to provide an identity when you request it to be forwarded. This also assumes you’ve created a public key to transfer your identity.

So, the ways to do this are:
1. Use the -A flag when you shell into a box.
This basically means whenever you shell into somewhere, you add -A to your ssh command. An example would be:
ssh -A username@awesome.server.com

2. Set the ForwardAgent flag to “yes” in your ~/.ssh/config file.
This is a synonym for the -A flag in an ssh command

Both of these options allow you to transfer the key you hold on one machine, to another. Don’t try to use ssh-agent on the machine you connect into though. If you do, you’ll lose your original identity.

So, all together now:

eval `ssh-agent`
ssh-add
ssh -A username@awesome.server.com

Questions are always welcome ;)

How To Incorporate In Florida

I’ve seen a lot of mis-information, and mis-guided information on how to start a corporation. The specifics of this vary by state to state. I live in Florida, and I went through the process on my own. The process was a bit difficult, but only because there wasn’t a clear guide on what to do.

Hence, this tutorial

First, you’ll need to download a form, that indicates the type of corporation you want to be. This is NOT to determine if you’re an S-Corp or C-Corp. The determination of S-Corp or C-Corp is done with the IRS. That determination is done later. For now, you’ll just need to decide which of the following you will be:

  • Non-Profit Corporation – If you want to be a 501c3, this one is for you. (form here)
  • Profit Corportation – S-Corp and C-Corp (form here)
  • Limited Liability Corporation (LLC) – Typical LLC (form here)

The forms will outline the specifications for each of the types of incorporation. While each of the forms contains the necessary questionnaire, I don’t recommend just filling in the blanks. There are a large number of templates for this. Google searches typically will bring up something to work with. Here’s the one I did for Hacked For BBQ, Corp.

Once  you get something written up, mail off the package with money included. Once you’ve gotten this done, you’ll have to wait a couple weeks for the state to get back to you. If everything looks good, you’ll get a letter of confirmation regarding your corporation.

Once you have this letter of confirmation from the state of Florida, it’s time to get your FEIN number and file your corporation type with the IRS. I did this as an S-Corp, so my experience may be different than some of the rest of you.

Go to the IRS’s online application for obtaining an FEIN number at the current website for this : http://www.irs.gov/businesses/small/article/0,,id=102767,00.html. You’ll click a link that says ‘APPLY ONLINE NOW’. Afterwards you’ll be sent to a page giving you the instructions on how to complete the FEIN process. The process itself is fairly self-explanatory. Completing this process immediately provides you with an FEIN number, with which you can open a bank account and start doing some business.

To close, I’d like to point out how unnecessary services like company.com are. These services are overpriced, and often put people in difficult situations. DIY business starting isn’t nearly as bad as it might seem at first. As always, any feedback is certainly welcome.

SSH Without Password

I used to always refer to a different site when I wanted to remember how to setup a machine to use SSH without a password. That site (I don’t recall what it is) isn’t around anymore. So, I guess I have to post the tutorial here.

SSH is one of the major tools in what I do. For any developers out there who don’t know about it, you’re missing out. Long gone are the days of requiring screen sharing or remote desktop to manage another computer. SSH is the bomb, and it’s been around for a long time.

Here’s how to use it, without needing to enter your password when you make a connection to a remote machine:

  • On the computer you’re making a connection from (i.e. your home computer)
    • If you do not have a ~/.ssh folder already, create one.
    • ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ''
    • scp ~/.ssh/id_dsa.pub <username>@<servername>:~
    • Make an old-skool connection to the server you just copied your public key to (i.e. your public webhost)
  • on that server:
    • cat id_dsa.pub >> ~/.ssh/authorized_keys2
    • chmod 0600 ~/.ssh/authorized_keys2

That’s it. Keep in mind, that you’ll still need to specify your username when connecting to the host (if it’s different than your username on your local machine). If you want to get around that, you’ll need to setup an SSH config file (future tutorial?).

XP Logs Off Automatically

So I got a call from a client today regarding a few issues they were having. Most of the problems weren’t all that difficult to solve, save one….

The boss’s computer would immediately log off after he tried to logon. While this might sound funny (in other circumstances, it really is), the client (who is a really cool guy, whom I respect a lot) did not think it was funny at all.

So, I dived into the Google to find out the issue. The short version; there was a bad registry setting. Basically, when this sort of thing happens, the first thing you should check is the registry. Now, you can’t connect to the registry locally, since you can’t logon to the computer with this issue.

So, the first thing you need to do, is logon to a computer on the same network as a user who has administrative rights on the computer concerned. Once you’ve gotten that far, you’ll need to open regedit. Something like this:

After that, you’ll need to connect to the computer in question. That’s easy, check the following pics:

then… 

The following key is what you should be looking for:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

That key should contain a string value for ‘Userinit’. If you’re confused, you should see something like the following:

Well, you probably shouldn’t see the green box, but you should see the string value for Userinit. If you don’t see that value in the root of key Winlogon, then you’ll need to create it. 

That’s not too bad either. First, right click the right hand pane of the registry editor:

Select the ‘String Value’ item in the right click menu. Once you’ve gotten that done, you’ll have a new string value in the right hand pane, awaiting you to name it. It’ll look something like: 

Name the string Userinit. After you’ve done that, right click the entry and select ‘Modify’. Make sure that the value for the key is:

c:\windows\system32\userinit.exe

Again, here’s a picture:

And that’s it. If you have any issues after you’ve gotten this done, I recommend an ERD disk or formatting your HD. Those are extreme options, I know. However, I don’t think you want to tool around with your computer for hours on end ( or maybe you do ).