How I Set Up a Coding Project Using Vagrant

When I first began using Vagrant, I had a heck of a time trying to figure out how to structure my project. Sure, there were tutorials on how to set Vagrant up but I wanted something even more higher level and in-depth. The following is how I now set up my personal projects. This isn’t set in stone; I modify it each time I find something better that works for me.

I use Vagrant for all development work since I don’t have to mess with my own set-up on my laptop. It makes development easier and quicker, since I mimic whatever server I plan on deploying the project to. For those who don’t know, Vagrant is a way to create development environments. It allows you to share those environments with other developers. Let’s get started!

First, you’ll want to put on some music. Something nice, something soothing ’cause the computer gods always have it in for us little peons and this might just make you frustrated. Personally, I’ve been digging Gracie and Rachel. Then, once you’ve got your headphones on and the music up, download VirtualBox and Vagrant. I run a Mac so this article is going to be geared toward Mac users; however, it should be fairly translatable to any operating system. Once you’ve got VirtualBox and Vagrant downloaded, install them on your computer (if you need help with installation, you’ll need to take a look at their respective documenation).

Okay, you’ve got those installed now? Awesome possum. Now we get to the nitty-gritty. Fire up your terminal. We’re going to take care of a few housekeeping things first before we get to Vagrant. In your terminal, type the following:

$ sudo vi /etc/hosts

Inside of that file, add the following line:

192.168.33.10  vagrant-tut.local

Then, save the file and restart the webserver with:

$ sudo apachectl restart

I use the 192.168.33.XXX addy’s just as a personal convention; right now in my /etc/hosts/ file, I’ve got close to 20 different entries all starting with 192.168.33.

Next bit of housekeeping is we need to add the base virtual box from which we’re going to build our development environment. You can find different boxes at Vagrantbox.es but for the purposes of this article, go ahead and type (or copy/paste) this into your terminal:

$ vagrant box add --name centos64-x86_64-tut https://github.com/2creatives/vagrant-centos/releases/download/v6.4.2/centos64-x86_64-20140116.box

That should be it for housekeeping.

Folder Structure and Files

Next up is the folder structure. It doesn’t matter where you place this folder, which is part of the gloriousness of Vagrant. Now, instead of throwing my websites in the Sites folder and other projects elsewhere, I just keep a Projects directory with code as a subfolder and all of my different projects inside.

vagrant-tut/
    .git
    .gitignore
    Vagrantfile
    data/
        bootstrap.sh
        initialize.sql
        httpd.conf
        nginx.conf
    src/
        index.php

Okay, let’s break this down. The .git and .gitignore files are for Git, your source control. The Vagrantfile should be part of the repository so other people can get up to speed quickly. The 2 folders in the project directory are data, which hold the various files to get the environment set up correctly and src, which is the actually project you’re working on. Inside index.php is just a phpinfo(); line.

Inside the data folder, you’ll notice 4 files. The bootstrap.sh is a shell script that is executed once Vagrant has started the virtual box. The initialize.sql, nginx.conf, and httpd.conf files are used by the bootstrap file. We’ll go into more detail further down, m’kay?

Vagrantfile

The Vagrantfile is a hot mess of confusing crap; at least, that’s what it was to me when I first started using Vagrant. However, I’ve got a minimal Vagrant file that works for me. Let’s open it up and take a look.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "centos64-x86_64-tut"
  config.vm.provision :shell, :path => "./data/bootstrap.sh"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network :forwarded_port, host: 8443, guest: 443
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "./src", "/var/www/html", type: "nfs"
end

A few things to note with this file. The config.vim.box line is referencing the name we gave the virtual box when we ran the vagrant box add command. You can add as many base boxes as you like and then reference them in the Vagrantfile. I usually prefer a CentOS box for most of my development but when I’m working on gitTasks, I instead use an Ubuntu 12.0 LTS base box.

The next line, config.vm.provision, tells Vagrant to run the shell commands in bootstrap.sh. The following 2 are forwarded ports and the private_network line gives a static ip address, which we have already placed in our /etc/hosts file. Now, when we go to http://vagrant-tut.local, our virtual machine will show up in the browser. The last line allows us to sync a folder on our host computer to that of the guest computer. By default, Vagrant syncs the folder that the Vagrantfile is in with /vagrant on the guest computer. If you were to open that location on the guest computer, you’d see the exact same folder structure that’s in vagrant-tut folder. However, I want to sync the src folder with the guest’s /var/www/html folder.

The type: "nfs" tells Vagrant to use an NFS server to sync the folders. I’ve noticed a lack of performance, especially when dealing with external API calls or with Sass files, and using the NFS option seems to help. Again, you don’t need to use NFS; your mileage may vary.

Bootstrap.sh

The bootstrap.sh file is pretty straightforward. It’s just instructions on how to update the box and add the packages you want. Since I plan on using PHP on this box, as well as Apache and Nginx, I’m just going to write the commands that I would normally type into the terminal in my virtual box. Open up bootstrap.sh:

#!/usr/bin/env bash

# Update yum and install packages
sudo yum -y update

# Want to include Remi's repo
sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

# Install necessary packages
sudo yum -y --enablerepo=remi,remi-php55 install wget nginx httpd php php-common php-cli php-mycrypt php-mbstring php-mysql php-pdo mysql-server mysql-client

# Set up configurations
sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bk
sudo cp /vagrant/data/nginx.conf /etc/nginx/conf.d/default.conf
sudo mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bk
sudo cp /vagrant/data/httpd.conf /etc/httpd/conf/httpd.conf

# Update the timezone, which always throws an error if not set
sudo sed -i 's/;date.timezone =/date.timezone = EST/g' /etc/php.ini

# Start services
# sudo service mysqld start
sudo service httpd start
sudo service nginx start

# Not using MySQL yet but, if I was, here's how I set it up
# if [ ! -f /var/log/databasesetup ];
# then
    # /usr/bin/mysqladmin -u root password 'vagrant'
    # echo "CREATE DATABASE cms" | mysql -u root -pvagrant
    # echo "GRANT ALL ON cms* TO 'root'@'localhost'" | mysql -uroot -pvagrant
    # echo "flush privileges" | mysql -uroot -pvagrant

    # touch /var/log/databasesetup

    # if [ -f /vagrant/data/initialize.sql ];
    # then
        # mysql -u root -pvagrant cms < /vagrant/data/initialize.sql
    # fi
# fi

# Need to restart afterwards
# sudo service mysqld restart
# sudo service httpd start
# sudo service nginx start

Once Vagrant gets the box running, the next step is to run all of the above commands. You can pretty much put any commands in here. For more information, head on over to Vagrant’s documentation.

Let’s start the VM!

Now that everything’s in place, cd into the folder where Vagrantfile is located. In your terminal, run the following:

$ vagrant up

Vagrant will start the VM, run your bootstrap.sh file, and run through everything. It can take a while the first time you run it since the update and packages are installed for the first time. Barring any issues, you’ll get the terminal prompt back. Now you can head on over to your browser, load up http://vagrant-tut.local, and you should see the output of the PHP configuration page.

When you’re done developing and you want to shut down the VM, in your terminal:

$ vagrant halt

The halt command shutdowns the VM. When you are ready to start developing again, run the vagrant up command once more. The only difference now is that the VM doesn’t have any services running (i.e. mysqld, httpd, nginx) so you need to log into the VM and issue the following commands:

$ vagrant ssh
$ sudo service httpd start
$ sudo service nginx start

Everything’s up and running again! If you want to completely remove the VM, $ vagrant destroy will do that for you. Just remember, when running $ vagrant up again, it’ll load the bootstrap.sh file.

Phew! This was a long article. I’ve put all the files into a Github repo: Vagrant Bootstrap; please feel free to clone and take for a spin. If you have any improvements, please don’t hesitate to make a pull request.

The Danger of Not Belonging

In my world, in the world of software and tech and women and the beginning stages of middle age, I often feel like a fraud. I feel like I’m going to get caught for faking it. My heart beats rapidly and the hot, thick sheen of sweat gathers on my forehead and upper lip. Hands that feel disconnected tingle and shake; the fear a hard, knotted rock stuck in my throat. I’m waiting for them to ask me into another room and, when I finally sit in that chair, their barrage of disappointment, anger, confusion and vitriol will shatter me. My confidence is a house built upon the burnt posts and beams of experiences and failures. Rarely does a success prop up my house in any substantial way.

I was promoted a few weeks ago at work to a management position. We’ve got a new hire that I’ve been tasked with on boarding, bringing him up to speed with our codebase, our coding standards, helping him start to figure out our convoluted hackery that is the natural occurrence of 3+ years of going from idea to product. And each time I see him sitting at his desk when I walk into the office, I think to myself, “Man, what a disservice this dude is getting…having me for a boss. What the fuck do I know?” And I know he feels this, sitting there with his sweet smile, politely nodding when my inadequacies come tripping off my tongue and I see the flash of confusion come across his eyes, asking himself, “How in hell did she get promoted?!”

Indubitably, it’s all in my head. It’s my own silly, little mind praying on an already fragile ego. There’s been much written on Impostor Syndrome, where one is unable to internalize their accomplishments. This feeling rears up and kicks me in the gut most days I sit at my desk in the open floor planned office that I find myself in day in and day out. This feeling has intensified over the past few weeks since the promotion. I question my thoughts, my decisions, and if I’m passing on the correct information to the software engineers I manage. I read management books and subscribe to management newsletters. I vacillate between what I would do and what I think other managers would do. It’s a constant internal battle between “What the hell do I know?” and “Who the hell do I think I am?”

Then I remember what got me here. I remember the minor victories of my early days at the company. At running my own design shop. Of sticking to my values and ethics when they were tested at another company. I remember that my ideas are my ideas and I have valid reasons for doing things the way I’ve ended up doing them. I remember that I wouldn’t have been promoted to a management position if those above me didn’t have confidence in my ability to be a good manager. I remember that my brother is now a developer, which I had a hand in helping getting him there (his thankful notes to me has been a boon to my confidence lately).

My natural reaction is to always doubt myself first and look for external validation for what I’m doing. When I catch myself thinking less than of myself, I’ve been stopping the thoughts before they gather enough momentum to roll me over. And then I don’t ask. I don’t ask my boss if he thinks it’s a good idea. I don’t ask my coworkers how they feel about whatever I’m about to do. I’m trying to retrain my patterns to act first, ask after. It’s a way for me to start trusting my instincts. I won’t always get it right but I have faith that there will be more ticks in the Success column than the Failure column.

I’ve been a manager at many jobs in the past but this is the first time in a tech role. It’s the first time where there is no definitive rulebook to tell me when I’ve done something right. Tech, as much as it is a logical world, is very subjective to the whims and thoughts of each software engineer. And this wide open expanse of difference is both what causes me stress and what gets me excited. Excitement because it’s so limitless and stress because there are no clear boundaries. I’ve had to start creating my own boundaries. One example is that I’ve had to make a decision about coding standards. Taking the reigns, nudging the team into the direction I think we should go, has been eye opening.

Learning to belong has been a slow process. Even after 3 and a half years, there is still a large part of me that can’t believe the dumb luck that a team like Aereo actually wanted me to be one of them. I’m reeducating myself. I’m learning to push away the nagging insecurities. I’m starting to own my position, not just as a manager but as a coworker and employee.

Every Day is a Good Day

A few months ago, I walked into Witch City Ink (Paul Martinez worked on me; highly recommend him) and had the phrase Every day is a good day inked on my left forearm. It’s actually a quote by Ummon, a Chinese Zen master born in 862 or 864 CE. It was something I came across while reading a book on Zen buddhism and had stuck around in my head for quite a while. For some reason, I felt the need to tattoo it on my arm.

I know, I know…a bold statement. And one I put permanently in a visible place. It is a reminder. A constant method of checking myself and the state of my thinking. When a project at work starts to get out of hand and I’m being run over by code, I feel my blood begin to rise. The first few moments of a mini-eruption inside the monkey mind begins to boil. My natural reaction to change and hardship makes itself known. And then, I look down at my arm, read Every day is a good day and take a breath. The eruption recedes away. The ink has done it’s job.

I think it’s easy to get caught up in the speed our negative emotions maintain. One thing cascades into another and, all of a sudden, it’s anger and frustration sitting in the pool of emotion. My dearest friend has told me that our thoughts take these neural pathways that are much like a stream through rock. The thoughts one thinks slowly grind away at the rock, burrowing deeper into the same path day after day, thought after thought. If all we think about are the negative aspects of any situation, those neural streams dig themselves deeper into our minds and the first reaction to a situation is our pessimistic, change-is-no-good attitude. But these neural pathways can be reconfigured. New streams and inlets can burrow into a more positive thinking pattern (or, at the least, a neutral pattern). Every day is a good day is a way to remap my mind, a way to slough off the past 3 1/2 years of Boston banality.

It’s been working. I read my arm and think just how amazingly wonderful my life is. Sure, sure…I’ve got things I want to improve. Sure, sure…I’ve made mistakes in my past. Sure, sure…I’m not where I want to be just yet. But damn, life is pretty sweet. I wake up each morning with a little, old pug who likes to spoon. I work at a job that I adore. The small amount of friends I do have are loyal, kind, and would go to the ends of the earth to help me (and vice versa). I have a close-knit family. And hey, I’m sitting here this morning, warm, comfortable and writing. How can life be so wonderful?

I do strive to improve my life. But I need to remember that right here, right now is perfect. This moment is perfect. To just be in this world as Nikki is such a random, chaotic act of nature; I can’t take it for granted.

Every day is a good day.

Finger Vomit

Last night as I sat on the couch, a feeling of boredom and a sense of pathetic-ness washing over me, I became despondent. It’s a feeling of not knowing what’s going on with my life, of questioning my decisions, of realizing just how sad my life can be. This isn’t how I feel all the time; actually, it’s not how I feel most of the time. But last night, well that damned, little imp of self-doubt and confusion was creeping around messing with the wires in my head.

It’s usually the cause of being in a bad mood during the day. The endless questioning. A strong dislike of who I am cascading into my walking day. Relationships at work become strained as I fight internally over the ridiculousness of me and the wonderfulness of me (I know, lots of ness’s). It is hard to explain to coworkers why I stay quiet, why my brow burrows deeper in between my eyes, why my responses are short, succinct, directly to the point. If I were to speak more than a few words, tears would come running out of my eyes; a mass exodus of marathon running tears pushing their way past the start line when the starting gun fires. Days like yesterday are the days where I want to stay home, wrap myself in my comforter, and drink endless bottles of beer to alter my mood.

So, when I came home, after cleaning up after a sick dog and berating myself for not being a good mother, I made myself a decent meal and a strawberry-banana smoothie. I sat on the couch watching Burn Notice. My mood slightly changed but then I grabbed a beer and after the first half of the beer was gone, felt the swooning wash of slight inebriation envelope me (yes, I really am that much of a lightweight). I started flipping through YouTube videos on my Roku, something that is a rarity for me, and happened upon a movie trailer for a movie I just can’t remember the name of. The male protagonist of the story says, and I’m paraphrasing here, “Loving you is like shouting into the void!”

And I thought, “Now, there’s something!”

Take off the love part, make the phrase present-tense, and you’ve got a shout into the void. What better way than to summarize what I’m doing here, on this blog, in my journal, trying to figure out my head than that simple little phrase? I write but no one reads, at least to my knowledge. And, if they do read, how are they to contact me to let me know? I’ve had this dualistic desire for many years: to give credence to my voice, to scream until I’m hoarse but not wanting to own my words, my feelings, afraid of the consequences being true to yourself can bring. It’s a definite selfish trait. As I write more and more, I’m learning to let that go. I’m learning to recognize my voice. I’m finding out that it’s okay to have an opinion and put it out there.

And, I’m learning that it’s okay to just start typing, having no real direction, and finger vomit all over this screen.

Morning Ritual

It’s Friday morning, a quarter to six. I’ve been up for the past 45 minutes. The calm that comes from meditation still surrounds me.

This is my morning ritual: I rise around 5 and make a cup of tea. Once it’s done steeping, I meditate for 10 minutes, pick up the tea from the kitchen counter that is now cool enough for me to drink, and sit down at my desk to write longhand for another 10 minutes. In these 10 minutes of writing, I allow myself to write anything, so long as my hand continues to move without any editorial demons screaming at me for the alleged ridiculousness I may put down on paper.

This practice has slowly started to build a base on which I am able to stand on throughout the day. It is a base that stays solid; that no matter what may happen today-whether good, bad, or indifferent-tomorrow I will get up and perform the same ritual. This act of love toward myself has no basis in what happened the day before or what may come in the day in front of me. I come to the meditation with monkey mind (a sort of horror realizes itself at having a monkey mind upon first waking. Does one’s mind ever turn off?) and by the time the gong has been rung, I feel more calm and focused. The meditation is completely my time to allow everything-the dire situations or petty concerns-to slide off my shoulders. The floor around my zabuton is littered with the hollow shells of discarded concerns that no longer have a hold over my mind.

This is not to say that the dire situations and petty concerns do not plague me. Far from it. A project at work that is falling behind, the heating oil gauge delicately kissing EMPTY, a sick dog that I’ll be picking up after all day; these are still real problems that need real solutions. But, for those 10 minutes of meditation, I do not worry about them. I come back to the breath. I breath in and out and, when monkey mind starts to creep back in, I count breaths in stanzas of 4.

Writing afterward gives me the chance to explore, wail, scream, lament, or be a giddy schoolgirl without any judgement. Free reign to be as small and petty as I feel myself to be. However, looking back through the past month and a half of daily entries, I see that I am not as petty or pathetic as I feel. Entries of hopes and dreams, working through feelings, coming to terms with my divorce, little snippets of a short story are more of what I find. Once I’ve given myself the 10 minutes to explore and the gong has rung again, I feel more grounded. I am beginning to understand myself, my mind, more each day. Peace has been slowly folded into my daily life.

This morning ritual seems to work. First, the act of following through on a promise I made to myself is a feeling of accomplishment. Even if everything I set out to do that day fails in one way or another, I know I have completed one thing. The days I do not perform my morning ritual, which have been few and far between over the past month and a half, I feel a sense of unease. A malaise settles in at the back of my head. I have learned that on the mornings when I do not want to go through the motions, that sense of malaise is worse than actually sitting my butt on my mat and in my chair.

Secondly, I find that I have a better understanding with whatever problem or experience I end up writing about. 10 minutes is just long enough to write a full page. I need to be succinct and get to the heart of the issue quickly, rather than take my normal circuitous route around it. Allowing the space between my mind and the issue when meditating dulls the sense of urgency. Writing about it, even if it’s only to lament, gives me a clarity that I don’t think can be realized if thoughts only stay in our head.

Finally, the morning ritual just seems to make me happier. I’m starting to smile more. I’m starting to become friends with myself. Creative ideas are flowing a bit more freely and my writing outside of the notebook has started to increase. The morning rituals are my markers; little cairns on the side of the path that I am walking, marking each day. I’ll always be able to find my way back by just following them.

Previously, my morning ritual was to wake, make coffee, and start coding. More than likely I would be working on a freelance project, sometimes working on a personal project, responding to emails, and getting all worked up before the sun even rose. Now, I carve out the morning for me and me alone. It is one of the best things I’ve done to increase my happiness, sense of self, and confidence. It has allowed me to let go of a lot, to focus, and to keep me from reacting immediately. The morning ritual has given me a solid base on which I can explore and experience my life.