Posted 01.07.2015

The Lazy Smart Programmer’s way to set up a WordPress Site

Coding

When you get ready to set up a WordPress site, typically your process looks something like this:

  1. Download the latest version of WordPress from wordpress.org
  2. Unzip it.
  3. Copy and paste the files into a local directory (you are developing locally, right?)
  4. Create a MySQL database.
  5. Run the 5 minute WordPress install.
  6. Download your starter theme.
  7. Unzip it.
  8. Copy and paste the theme file into WordPress’s theme directory.
  9. Find your base plugins that you know you’ll need. Download each of them individually.
  10. Copy and paste the plugin files into WordPress’s plugin directory.
  11. Start your custom work.

That’s 11 steps, at least! I know, if you do it enough times you could probably get that down to a 15 minute setup, and that’s probably only if you have local versions of your boilerplate theme and plugins that you can quickly copy and paste into the respective directories.

But, why? Why would you even want to waste your time doing such mindless work every time you start a project when you could be spending that time designing and developing something beautiful and original?

What if I were to tell you that you could cut down that down to two minutes…on a bad day? Interested?

If you can hang with me for the length of this post, we can get you set up and you can start being more efficient.


Remember in English class, how they told us to (1) say what you’re going to say, (2) say it, and then (3) say what you said. I always remember thinking, “That sounds redundant.” Well, I’m going to take a lesson from Mrs. Nooks. I’ll tell you a little bit about the tools we’re going to put in our tool chest, then I’ll show you practically how to use them. It may get a little technical from time to time, but try to stick with it, it will be worth it.


Node.js

A lot of services are built on Node.js. If you visit the Node.js site it says it’s built on Chrome’s JavaScript runtime. Just know, that means f-a-s-t.

If we’re going to use it, we have to install it. Fortunately for us, this is easy. There’s a big green “install” button their site. Click it.

Node.js

Once the package is downloaded, unzip, and double click on the package to install it. Hooray!

Node successfully installed!

NOTE

Grunt and Gulp also run on Node. (Blog post for the future.) Just know, for now, we’re set up for success!

 

Yeoman

Yeoman is a project generator. It can do quite a bit, setting up sites and scaffolding (and not just for WordPress). We’re going to take the easy way out and use a generator Wesley Todd has already created specifically for starting a WordPress project: YeoPress.

NOTE:

To run YeoPress, Node is the only thing that is required (which we just installed), however, Wesley encourages you to have git and SASS installed, too. If you don’t, no worries, it’s pretty straightforward too:

git

You can go to the git website, download the file, unzip, and double click on the package to install it. Done and done.

SASS

SASS is a Ruby gem. If you’re working on a Mac, it comes with Ruby already installed. All you have to do is open up your Terminal (GASP I know, it will be OK.) and run the command:

gem install sass

If you get an error, chances are you need to run the sudo command:

sudo gem install sass

Sudo forces your computer to run the command. It will ask you to enter your computer’s password.

If you want to check to make sure everything was installed correctly, you can run:

sass -v

You should see it return Sass 3.4.9 (Selective Steve).

Now, for installing Yeoman (yo) and YeoPress (at the same time). Within the Terminal run:

npm install -g yo generator-wordpress

npm just means that it’s a node command.

Easy.

Now, within the Terminal, we just have to navigate to the folder we want to install WordPress inside of.

If I lost you at, “within the Terminal,” it’s OK.

For the longest time, I was uncomfortable inside the Terminal, too. But, I promise, the more you use the more comfortable you’ll become. As soon as you see the benefits that the Terminal provides your workflow, it will eventually become something you can’t / won’t want to ignore.

You can get started with the Terminal here.

Now, run:

yo wordpress

You’ll see the WordPress logo appear and it will start to ask you a series of questions about how you want to set up your WordPress install:

WordPress URL
If you’re doing local development (as you should), enter that URL in.

Running yo wordpress within the Terminal

Table Prefix
This is the table prefix for your WordPress database. By default it’s wp_. Stay with that. It makes it easy when you’re looking at your database to be able to tell which tables are related to your WordPress install.

Table prefix when running yo WordPress within the Terminal

Database Host, Name, User, Password

Entering Database credentials when running yo wordpress

I use a free app on my Mac, called Sequel Pro to manage my databases. But, if you’re using MAMP, you can do everything through PHPMyAdmin.

MAMP will also list all the credentials you need (host, user, and password) on the WebStart page.

Webstart Screen in MAMP

Use Git?
More on this later, too, but for now, take my word and just say “Yes”…err, rather “Y”.

use git inside yo wordpress

Would you like to install WordPress as a submodule?

There are people that sit on both sides of the fence on this one, people for and against.

My personal take?

First, let me explain what a submodule is. Submodules are a “Git thing”. It’s essentially an external Git repo that your repo references. Think of it as a nested repo that you can update it independently.

When you think of it in those terms, it makes sense to implement WordPress as a submodule. I don’t manage the WordPress core, so why not make it seperate and reference the actual WordPress repo itself?

If you implement WordPress as a submodule, you’ll using the following commands to update WordPress later:

cd wp
git fetch && git fetch –tags
git checkout 4.1
cd ..
git add wp
git commit -m “Updated to WP 4.1”
git push

Not too shabby.

NOTE:

If you get an error, when you try to update WordPress, like: Your local changes to the following files would be overwritten by checkout. Try forcing the checkout:

git checkout -f another-branch

So… “Yes” install WordPress as a submodule.

Wordpress as a submodule

WordPress install directory
My personal preference is “wp.”

This means when I log in to the admin panel, the address will be: http://SITENAME.dev/wp/wp-admin

WordPress content directory
I go with “wp-content.”

Directories for WordPress Install

Install a custom theme?
I choose “no.” But, I think this would be a good area, in the future, to streamline my process even more.

Does this all look correct?
It’s always comforting that it asks you to double check. “Yes.”

yo wordpress - all correct?

Boom! It will download WordPress for you and set up your config file. Granted, the set up may sound a little verbose, but we just condensed that 11 step process into a few lines of code.


For future reference:

If you clone your repo and the wp directory is blank (WordPress is a submodule, remember), run:

git submodule init && git submodule update

Also, if you need to update YeoPress, it’s as simple as running the following line:

npm update -g yo generator-wordpress



Posted 01.05.2015

Posted 01.05.2015

How to Overcome your Fear of the Terminal

Getting Started

For years, I’ve been afraid of the Terminal. I was scared that I would erase my entire hard drive with a single typo.

But, then I started using grunt. I found it to be so much faster and allowed far more task automation than the tools I had been using previously. IMHO, anything that will speed up your workflow is worth investing in (whether that’s time or money ).

Once I started spending more time in the Terminal, I became more comfortable and confident. Trust me, I still prefer a GUI (graphical user interface), but I’m no longer afraid I’m going to delete my entire harddrive. — And let’s be honest, you could delete your entire hard drive with a GUI too. Drag your harddrive to the trash and click “Empty Trash.” But, nobody in the right their mind would do that. Similarly, you’d have to type a very specific command in the Terminal to delete your entire harddrive and nobody in their right mind would do that either. — Plus if you have a typo in the Terminal, it will tell you and the command won’t run.


So, here are the commands that I’ve found to be the most useful:

NOTE:

When you see examples of command lines in the Terminal and you see a $. Don’t copy the $, it just signifies that it’s the beginning of a Terminal line.

cd stands for change directory. Similar to the Finder where you click on the folder, in Terminal, you just type in the directory that you want:

$ cd Sites

You can type cd .. to go up a level or cd ../.. to go up 2 levels. cd / will take you to your home directory.

The Terminal also supports tab auto completion. So you could type cd De<TAB> and it will fill in cd Desktop for you. Handy!

ls will list all files and directories in your current location.

pwd will show you the current file path to your current location.

mkdir FOLDERNAME will create a folder named FOLDERNAME. mkdir stands for “Make Directory.”

Anytime, you hit the up arrow on your keyboard, it will fill in the last command you ran. Hit it again and it will cycle to the command before that. The down arrow cycles in the opposite direction.

Just to give you an idea of how these commands are used together: when I first open the Terminal, I might type ls to see what my file / folder options are. Then:

$ cd Code/GIT/
$ mkdir NEWPROJECT
$ cd NEWPROJECT

This navigates to the GIT folder and then creates a new directory for a project. Then, navigates inside the folder I just created.

If this is still making your head spin, here’s a WYSIWYG way that I saved until the end: Open up your Terminal type in cd . Then, open up Finder, navigate to the Folder you want to open in Terminal and drag that folder from the Finder onto your Terminal window. It should enter the location for that file path for you. Now, hit <RETURN>. — You’re welcome.


If you’re feeling ambitious, a few other tips and tricks:

I use iTerm2 instead of Mac’s default Terminal. It has a little bit more functionality. My favorite feature, I have a shortcut set up so that any time I hit ALT + Cmd + Space, the Terminal overlays my entire screen. Using the same command sequence will toggle it off. This is great for quickly checking on a grunt or gulp task.

If you want to set this up:

  1. Download and install iTerm2.
  2. Go to iTerm > Preferences. Click on the “Profiles” tab.
  3. Click on the + button in the bottom left. I labeled my profile “Hotkey Window”

    iTerm Preference Window

  4. In the Window tab, I tweaked the transparency, checked Blur, changed the Style to “Fullscreen”, changed the Space to “All Spaces.”

    Screen_Shot_2015-01-02_at_10_26_51_PM

  5. Then, under the Keys tab, check “Show/hide iTerm2 with a system-wide hotkey. As I mentioned, I’m using ALT + Cmd + Space, but do whatever works best for you.

    Screen_Shot_2015-01-02_at_10_27_54_PM

  6. Also check “Hotkey toggles a dedicated window with profile:” and make sure “Hotkey Window” (or whatever you named your custom profile is selected from the dropdown.

Lightning Round.

I’ve always wondered how people were able to customize their Terminal to be all kinds of cool colors.

Then, I was introduced to Oh My Zsh = Awesome.

Even if you could care less about Terminal colors, there are other short cut codes packaged within Oh My Zsh that make Terminal life even better.

I took a leap of faith and trusted Robby Russell and simply ran his automatic installer via Curl. Just copy and paste the following line into your Terminal (remember you don’t need to copy the $ sign):

$ curl -L http://install.ohmyz.sh | sh

Then, you can start Zsh by simply restarting or opening a new command window.

There are plenty of themes to choose from. I went with the agnoster theme and then the colors in my Terminal to use the Solarized theme.

Slow down

Sorry.

To change the theme for Oh My Zsh, copy and past the following line into your Terminal:

$ nano /.zshrc

nano is a simple text editor that runs within the Terminal. So, we’re simply telling it to open our preference file in nano.

Go to the line that’s called ZSH_THEME=“”. Change that line to the name of the theme you want to use, in our case agnoster.

Screen_Shot_2015-01-02_at_10_49_10_PM

Then, type Ctrl + O for “Write Out” (also save). It will ask for the file name, just hit enter to keep the same file name.

Then, type Ctrl + X to exit.

To install the Solaraized theme, click on the download link on their site (also available on their GitHub page).

Unzip the file. Navigate to iterm2-colors-solarized.

Double click on the Solarized Dark.itermcolors file. It should launch iTerm2 with a pop-up message explaining that the color scheme has been loaded into the iTerm2 Preferences (Preferences > Profiles > Colors > Load Presets).

Screen Shot 2015-01-02 at 10.53.41 PM

Make sure your “Hotkey Window” profile is selected and choose “Solarized Dark” from the Load Presets… doprdown.

Screen_Shot_2015-01-04_at_10_29_59_PM

As you begin using the new theme, you may notice some of the characters are not appearing correctly.

I’m using Menlo for Powerline. You can go to their GitHub repository, download, and install the font. There are some other options in the Powerline font repo.

If you’re using a font manager like Suitcase, be sure to mark the font as permanent.

If you’re still having trouble, check the Text tab within iTerm2 and make sure the appropriate fonts are marked.

Screen_Shot_2015-01-02_at_11_01_19_PM

UPDATE JANUARY 25, 2015

Menlo for Powerline stopped working for me. So, I ended up downloading these Powerline fonts from GitHub and installing Meslo, using the same process as described above.


Tripe Bonus.

As I mentioned earlier, “Oh My Zsh” has several shortcuts included. For example, if you’re running Composer, instead of typing composer update, you can simply type cu. Instead of git status, gst. Still not convinced? Here’s one of my favorites: you can type stt and it will open the current directory within Sublime Text. These might not sound like much, but the more you live in the Terminal, the more time it will save you.

All of these shortcuts are considered plugins. You can check out all the ones that available on the Oh My Zsh’s wiki page.

Once you decide which plugins you want to use, you can activate them similar to setting the theme.

$ nano /.zshrc

Find the line that says plugins=()

Include the plugin name within the parenthesises.

Mine reads:

plugins=(git sublime sudo laravel4 Composer bower npm osx)

Last trick.

I have an alias set up so that anytime I type projects into iTerm, it will go directly to my projects folder, where I keep all my code. Essentially, it’s the same as typing cd ~/Code/GIT/ (just in case you were wondering the ~ references your home directory. If you’re not sure what I’m referring to, just type cd ~ and then pwd or ls in the Terminal. You’ll see.)

If you still have your preference file open (nano ~/.zshrc ), look at the bottom. There are a few examples already set up, but commented out (the # in front means the line is commented out). Add a line at the very bottom, below the examples, that reads alias projects="cd ~/Sites".

Then, write out the file (^O) and exit (^X). Restart iTerm2 (or open a new command window). Test it out. Nifty!



Posted 10.30.2012

I Decided to Look at Ruby on Rails

I’m a PHP girl. I’ve been writing PHP for the past 7 years. I’ve heard so much about Ruby lately that it’s hard not to wonder, “Is it really all it’s hyped up to be?” I’ve been reading plenty of blog posts (here and here) trying to decide if it’s worth investing the time to learn (yet) another programming language. Part of me is eager is to learn something new and is up for a new challenge. I like to think, the more tools I have in my toolbox, the better suited I’ll be for various projects. … So, this is my journey to learning to looking at Ruby and Ruby on Rails. Join me, if you want, we can struggle together.

…yes, the two (Ruby and Ruby on Rails) are different. Ruby is the programming language. Ruby on Rails is the framework that sits on top of Ruby. If I can put it in PHP terms, PHP is the language, CodeIgniter is the framework. Great, so, what’s a framework?

Well, for almost every project, there certain things you always have to do. Websites, for example, I (almost) always have to connect to the database. I could write that code every time, or I could use a framework that has built in functions that do the work for me. A framework gives me structure and a starting place.

While I’m eager to get my hands dirty and jump in with Ruby on Rails, I know I first need to learn Ruby before jumping in the deep end. Rails will make a whole lot more sense and I’ll be able to go a whole lot further in the long run, if I have a foundation first.

I’ve seen The Well Grounded Rubyist mentioned several times on various sites, so I decided to buy the book and start reading. Call me old school, but I prefer books over videos. I like being able to set my own pace, actually see the words, highlight and take notes. I’ve also looked at Code School, but for where I’m at right now, I feel like it moves a little fast and I’m having trouble connecting all the pieces together. I might find it more helpful, though, after I have a few chapters with this book under my belt.


Installing Ruby

I work off a MacBook Pro, running Snow Leopard (I know). It came with Ruby already installed, but it wasn’t the latest version.

I found an excellent blog post by David Benjamin explaining how to get everything up to speed.

I don’t want to be redundant, so I’ll let you click over (just this once) and read his post. –However, I will share a few of my hold ups:

I don’t have a lot of experience with the terminal.

I took a C++ class in college where we had to use the Terminal, so I at least have a basic understanding, but it’s been a while and really, the only commands I still remember are:

cd change directory
pwd display the current path
ln display the contents of the current directory

NetTuts has several posts that will help you get comfortable with the Terminal:

I use Sublime instead of TextMate.

So, instead of using the mate command (as listed in the instructions) to create a new file, I figured out how to call Sublime from the command line:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

So instead of saying mate ~/.profile, I used subl ~/.profile

I had trouble finding the bin folder.

I finally found it. If you go to the root directory > usr directory, it’s there.

Terminal - Finding the bin Folder

With those things out of the way, I was able to easily follow Dan’s instructions.


Understanding the difference between Ruby and ruby

(Apparently) the difference between Ruby and ruby is more than just an upper and lowercase letter. Ruby is the actual language, while ruby is the interpreter.

So, you’ll write Ruby files (with the extension .rb). Then, when you get ready to run the file, you’ll use ruby in the command line to interpret the file for you.


Your first Ruby Program

Create a folder called Ruby for all our code. Mine’s sitting in my Documents folder. Don’t worry, I didn’t do anything fancy like use the Terminal. I simply created it in finder. I’ll keep all my Ruby code there (crazy, I know).

In Sublime, I’ll create a new file and save it to that folder. I’ll call it “first_program.rb”

…BUT… if you did want to be fancy and feel really smart, you could do all this from the Terminal:

Terminal - mkdir for first Ruby program

Inside the file, I’ll type:

puts "I'm writing Ruby"

Save!

Now, in the Terminal, I’ll navigate to that folder. I’ll run the interpreter:

Terminal - ruby first_program.rb

Magic!

…If you don’t see this and got something like this, go back to your file in Sublime and make sure that you have code quotes " " and ' and not fancy ones.
Terminal - error when running ruby first_program.rb

OK, so what just happened in our code?! (It drives me crazy when authors say “Write this.” I write it and they say “Good job!” and I don’t even know what I wrote or what I did! For me, it’s just as much (if not more) about understanding the code, so I can use it in various circumstances in the future, as it is about completing the exercises.

In Ruby puts just means print. Send it to the screen. If you’re a PHP person (like I am), it’s just like echo. The only difference, is that puts adds a line break automatically to the end. So, none of this “\n” junk.

NOTE: Where did they get puts anyway? That doesn’t even sound like good English! Well, it’s an abbreviation for put string.

What if you want some of that “\n” that junk? Well, Ruby has another method you can use called print that doesn’t add “\n” to the end. I’ll show you what I mean. Open your first_program.rb back up. Update it to look like this:

puts "I’m writing Ruby"
print "This is my first program and "
print "it runs like a champ."

Save. Now, back in the Terminal, run your ruby first_program.rb command again.

NOTE: In the Terminal, you can hit the up arrow on your keyboard and it will automatically pull up the last command you entered. Keep hitting the up arrow and it will keep cycling back, showing the command before that. This makes it helpful, especially if you keep running the same commands over and over again.

See what I mean with the difference between puts and print?

Terminal - puts and print


OK, so, this might seem super simplistic, but the important part is we’ve started(!) and that’s something worth celebrating!

Below, I’ve listed a few tutorials that I’ve dabbled in, if you want to jump in a little deeper or move a little faster!

Tutorials