Wednesday, June 19, 2013

VirtualBox, CentOS, Zend Server CE Oh My! - Part 2...

In my last post I went over how to set up VirtualBox for host-only networking and linked to setting up CentOS with these networking settings. Now I will go over getting Zend Server CE installed and configured for a development environment.

I am installing Zend Server CE 6.0.1 with PHP 5.4 which at this time was the latest and greatest hotness I could afford. Let's start by logging into the VM via ssh. Since I am sure you followed the instructions for installing CentOS from my last post I will not go over how you actually connect to your VM with ssh.

Install Zend Server CE

First we need to add the repo location for grabbing Zend Server.

Edit the following:
vi /etc/yum.repos.d/zend.repo

Insert the following into the file:
name=Zend Server 
name=Zend Server - noarch

Now run the install:
yum install zend-server-php-5.4

Wait for it... Zend Server is installed, yippee! So let's fire up the admin UI.



So, I guess we still need some configuration for CentOS to let us in.

Run the following in your terminal:

iptables -I INPUT 5 -p tcp --dport 10081 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 443 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 21 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 22 -j ACCEPT
iptables -L --line-numbers
/etc/init.d/iptables save
/etc/init.d/iptables restart

Now let's try that again.



Step through the Zend Server set up wizard and follow the instructions.

  1. License Agreement: Agree (otherwise I guess this was pointless).
  2. Launch Type: Development (That is what I chose, you may try anything you want though I guess).
  3. User Passwords: password (Whatever floats your boat I guess).
  4. Summary: Notice the license type, we will change that shortly (optional).

Optional - Change The License

To obtain the free Zend Server CE license key go to If you don't already have a login for Zend, go ahead and sign up.

Log into Zend Server using the admin user and password.
Go to the Administration tab and click on license.

Click on the Change License button.

Enter the details from the license page to apply the Community Edition license.

Once the details have been entered successfully you will see the confirmation of the features you will be missing out on in the Community Edition, not a huge loss in a development environment IMHO.

Click the Save License button and Zend Server should restart.

The confirmation window will appear, Continue using Zend Server...

Now your license details should reflect the Free edition (CE).

Zend Server is now installed and ready to roll. In the next part I will go over configuring Apache for the development environment.

Sunday, June 9, 2013

VirtualBox, CentOS, Zend Server CE Oh My! - Part 1

To get started in my Laravel experiment I needed a decent development environment. Since I have been using CentOS at work lately I decided this was the OS I would use for my development environment. Being mediocre at best with Linux this presented more of a challenge than I normally enjoy when working on a personal project. This is the kind of sacrifice I make for everyone reading this, so you are welcome!

I had a very specific environment I wanted to build. The newest CentOS version 6.4 on VirtualBox using a private virtual network running Zend Server CE 6.0.1 for the Apache and PHP portions of the stack.

VirtualBox Specs
So one of my pet peeves with VirtualBox as a development VM that most people seem to just accept and shrug off as normal is port forwarding. I despise port forwarding! Something about needing to remember another set of numbers that have perfectly good defaults just irks me to no end. It might be my inability to constantly remember things that are unimportant or something else in my brain. Regardless I think we all now understand I don't want to do it.

While using VMWare it configures the virtual network adapter by default to have it's own subnet so I get a unique network between my guests and my host. It also facilitates giving me access to the outside network (internet) from the guest OS. Having a fair understanding of networking I may use some incorrect terms here, please forgive me. By default on VirtualBox it is usually a bridged connection which is fine. I get an IP address from the network I am on for my guest OS. This is great until I have no network or I switch networks. Now my static little network has been disrupted and I must reconfigure. Sure I could update my hosts file. But why should I need to? So I want this in my life when using VirtualBox, subnet that never changes between the host and guest OS and internet access for the guest.

Come to find out, this is pretty easy to do. It seems no one else is bothered as much by this so you rarely see info on how to set it up.

Open your preferences in VirtualBox and go to the Network section.

Select the "Add host-only network (Ins)" button.

The new host-only network will be listed, select the Edit button.

This will open up the adapter settings which should have default settings for IPv4. No need to change unless you have a reason to. I left IPv6 blank as I don't have a reason to use it.

Next You will want to choose the DHCP Server tab and add the settings for it. I suggest copying the IPv4 Address for reference unless you can remember it easily enough.

  • Check Enable Server
  • Paste or enter the IPv4 address into the Server Address field that will be used for DHCP
  • Enter the Server Mask value which matches your Adapter settings
  • Enter the DHCP start and end addresses. These will be delegated to the guest like any other DHCP server would.

Now VirtualBox is setup and ready to use this host-only network for any guest OS you install. When setting up your guest OS you will assign this adapter to one of the network interfaces in the individual VM settings for networking as shown.

That's it! That is everything I ever wanted from VirtualBox but never knew existed.

CentOS Installation

I am going to cheat here. I followed a very detailed blog to finally get my CentOS installation right. I tried a few variations from these instructions and failed one way or another each time. So I am linking you straight to where I had success. If I attempt my own install again not using these instructions I will also link to that but for now here is what I did to get my CentOS install just right.

>>>> Best CentOS VirtualBox Installation Instructions EVER! <<<<

That concludes Part 1, next I will detail getting Zend Server CE setup along with the Virtualhost settings.

Tuesday, June 4, 2013

Why Use A Virtual Machine For Development?

As web developers sometimes we have a tendency to take the path of no resistance. See I went straight past least all the way to "no". Sometimes this is ok, others times not so much. One such area I have seen this happen in many times would be a development environment. I am no stranger to doing some of the worst possible things known to development. Editing on production, not using source control, etc. The list goes on for a very long time.

One of the common practices I see many developers do, that I think makes no sense, is using their development machine as the environment for development. If you are asking yourself right now "Why is that so bad?". Please, for the love of all that is good and wholesome in this world, do not stop reading!

Let's start with some of the reasons why having an *AMP stack on your computer would not be the most horrible thing in the world.

  • You don't really care about specifics you just want to run some test code. 
  • You are throwing together some crappy prototype that you know won't actually be used by anyone besides yourself.
  • The guy you are interviewing seems to think that a case statement doesn't need a break in order to stop executing.
  • Any other reason where the code will either be deleted, actually moved into a proper development environment before more than a few hundred lines of code has been produced, or no one will ever see this code besides you.

That is about the only reasons I can come up with to install your *AMP stack on your computer. Any other reasons I will immediately chalk up to laziness or not giving 2 shits about your craft. 

So what is so bad about a *AMP stack on your work computer?

You are locked into that specific environment. Is your code really going to be pushed to a production server that is running Windows 95/98/98SE/ME/2000/XP/7/8 and WAMP? If it is, well you have bigger problems and I don't mind if you stop reading now and continue to cry softly into your pillow at night. For those of you who are getting smug right about now because you run some flavor of linux, hold that smirk for a bit, I will get to you.

Do you work on a team? Is everyone running the exact same craptacular OS you are? Are they running all the same extensions as you? How many times have you needed to say "It works on my machine"? If any of those sound familiar to you, you are making this harder than it needs to be.

Haha, I run linux, I am immune! Not so fast bash master. So you're running Ubuntu, is your production box also running that? Same everything? I mean nothing could possibly be different. Surely you are not installing anything or compiling anything even remotely different from any other environment in your deployment process right?

So here's the deal. If you are doing this. You are causing yourself headaches or just waiting around for a headache to occur. It is not a question of if. This is definitely a when situation. Someone is bound to use a newer version of some part of your stack. Someone is definitely going to have an OS that ignores case for file names. When this gets pushed to QA you are now wasting their time running down bugs that could have been very easily avoided. Do you really have the time for this?

What can a VM development environment do for you?

Most important and really this reason alone is enough to do it. Consistency! By establishing a VM with the same specs as your other environments you can rest assured that if the code runs on the VM, it will run on all the other environments. Sure you will have other problems that a VM can't solve. Out of date data sets. Not updating your code. Bad configurations. All sorts of problems. You won't be hunting down that weird extension that Joe forgot to install though. Let's face it those are the worst kinds of things to debug usually.

How would you like to be running 2 completely different stacks on the same machine? How about 3 or 4 or 5 or 20? Want to experiment with all the new hotness that is in the newest version of your favorite database engine? Thinking about making an upgrade to your version of PHP and want to see how badly it breaks your application? Easy, fire up a new VM with whatever configuration you want and go to town. Bounce back and forth between that environment and your stable development environment with ease.

You get the ability to share with others. This would make your mother proud. By establishing a base VM you can now easily give others an environment to utilize to do work on that won't differ from yours. Making everyones life easier.

By abstracting your stack into it's own little isolated environment you get flexibility to have endless environments. Or at least as many as your poor little development computer can handle.

Monday, June 3, 2013

Setting Up A Development Environment For Laravel

As blogging is sort of a new thing for me. There needed to be some inspiration for me to write something. Many of you will find out, probably quickly, that English tends to be my second language. My first being silence, which I don't practice often enough.

So, for my first venture into blogging I decided to chronicle my setup of a brand spankin new development environment. After having spent numerous years using virtual machines for development this should be easy... or the exact opposite of easy. It never fails every time I set one up I stumble over the same problems I have forgotten about or new ones crop up. I prefer the new problems since it means I have ventured out of my comfort zone.

Now the inspiration side of things. For the last 5 years I have been primarily focused on developing PHP using Zend Framework. It seemed about time to learn something new. After thinking about it for some time I decided to check out Laravel. It seems to be a hot little framework that I keep hearing whispers about when talking to other PHP developers. I could have gone with Zend Framework 2 but I think it's time to venture outside of the Zend garden for a bit and see what else is going on.

Some of the reasons for choosing Laravel...

  1. Like I mentioned, I have been hearing some talk about it so I want to see if it lives up to the hype. 
  2. After reading some of the web site it claims to have great documentation. Something Zend Framework has been lacking for years and is just now starting to get better at. 
  3. Fast setup, get coding without needing to jump through a lot of configuration hoops. Although Zend Framework can be fairly quick to setup if you have worked with it for awhile. The problems usually start creeping up on you when trying to find out how to implement certain configurations. Since Zend Framework has been around for awhile there is a ton of information that is deprecated, or just too many choices. The sheer volume of ways to do something as simple as multiple database configurations for example, can be daunting.
  4. Something that I could learn and teach others about at my local PHP user group which I am involved in.

Keeping with the theme of development I also decided to take a TDD approach to my research and learning. I have outlined a set of test cases that I want to pass as I am setting up my environment and hacking away at Laravel. One of the test cases I had in mind was documenting my journey (blog). So here are my test cases which I will be blogging about over the course of the next several weeks.

    public function createBlogDetailingResearch()  

Clever, huh? Did I mention I was funny too?

OK, so maybe I lack skills as a comedian. Also I decided I was not going through all my test cases and actually try to make real associations to phpunit assertions and testdox test case function names.

As each test case is complete I will update with the following with permalinks when applicable.

Blog About My Setup

Still in progress but I have a start with this post.

Use VirtualBox For My Virtual Machine

I wanted to make sure that if I wanted to include others in a live coding session I can easily pass out something open source and cross-platform compatible. Since my VM software of choice is VMWare Fusion on a Mac I need to iron out some issues I have with VirtualBox.

Use A Production Quality OS

This is falling more on preference but I needed a good excuse. Ubuntu is fairly easy to get up and running and there is a ton of information on the internet about setting this up. The problem is I don't see a lot of people running Ubuntu in a real live production setting much. The OS of choice right now seems to be CentOS for production grade open source Linux OS. Also, since I use this primarily at work I have a few resources if I get stuck somewhere with my mediocre Linux skills.

Use Zend Server CE

I know this somewhat contradicts my previous statement of departing from the Zend garden. The choice was simple, I did not want to hassle with trying to get debugging going with XDebug. Using Zend Server I can get Zend Debugger running quickly. Having more experience with this debugging tool over any other will hopefully prevent me from patching holes in my walls. Again I have resources who can help when Google fails me. I want debugging so I can easily step into the code and see the inner workings of the framework. I find this is a great learning tool and exposes a lot more than just reading the code and executing it in my head. Too much recursion can be a problem when just reading a framework.

Use A Good IDE

I will most likely be praising and promoting the crap out of phpStorm. In the last year I have been using it, I wonder why I ever used Eclipse based IDEs. This will probably be my biggest bias when discussing how to do things in the code. Also somewhat goes against my "choose open source applications" for the development stack. I know plenty of people who will likely follow along in VIM though, so to each their own.

Establish Shared Code Between Host and VM

This is my favorite way to work with a VM development environment. Keep all the tools in the OS of choice and run the code on the VM. Preferably there is no deployment process to make this happen. Save your code, run your code.

Host The Code So Others Can Fork It

It is rare for me to ever start any coding without source control. Even if I know I won't be doing much with it. Easily the one tool no developer should ever be without. For this experiment I will be hosting my code on Bitbucket as I am partial to Mercurial.

Get Laravel Up And Running

Now we are getting somewhere. This will be the outline of how easy or difficult getting just the initial Laravel framework up and running anything. My hope is this post will be extremely short. I will also be concentrating on doing this manually unless when using predefined scripts that seems to be the way to go. I want to be intimate with Laravel not just a casual observer.

Configurationing With Laravel

Most of the time I can breeze through this with Zend Framework. OK, almost never because I seem to be on a every year or so cycle where I have a blank slate to configure. So either I reference what I have done in the past or I fire up Google and look for answers. My hope is this is straight forward. Even though I like flexibility to do things my way, bonus points if it is not a choose your own adventure.

Let's Make An App

I will keep it a secret for now what app I plan on making. Alright, I am still debating the exact project I am aiming for, but I have ideas. This post will concentrate on some specifics of what I hope to accomplish quickly. Since I know Laravel is an MVC framework much of the architecture and planning will revolve around that idea.

Making A Request

So many different paths to choose from anymore. Do you build a RESTful application? Stick with old school RPC? I find it can be a mix. Will Laravel let me do this easily? Can I choose the path that is right for me?

Forms And Validation

One of my favorite features in Zend Framework revolves around Zend Form, Validators and Filters. Does Laravel give me a good flexible option like Zend? Does the validation and filtering make sense? Do I need to struggle with decorators or will Laravel help me ditch that long lost pain in my ass?

Sexy, Sexy Models

I prefer skinny controllers, fat models and a good service layer. Does Laravel tie me into an Active Record pattern? Will it be flexible and allow me to create models of my objects while leaving the dependencies injectable? Oh, you thought I was going to talk about something else?

Good Service

If I have a 3rd party dependency or any kind of external dependency I want to keep that abstracted out into a service layer. How is Laravel's query abstraction for SQL? Does it have potential security flaws? Does it use PDO? Does the query language it provides make sense? Can I make complex queries easily that make sense?


When I put everything together how easy is it for me to test my application? Does Laravel supply me with patterns that make this task easier or more difficult? Obviously I can choose how to write my code in a way that is testable, but I want to see if the framework encourages this or gets in my way. I also want as much of the whole stack to be testable from the controllers to the services. Where if any are there gaps that I feel should be easier to test.

Plugins or Bundles

Since Laravel promotes bundles I want to see how this helps me. Does it really make it easier for me to stop re-creating the wheel? What if I want to make my own, how difficult of a process is this?

User Interface

How does Laravel help me integrate with some of the newer UI frameworks available. I will most likely look at using Twitter Bootstrap and trying my hand at HTML5. Will the framework help or hinder me?

Build A Presentation

As a final step I will bundle all the things I do and make a presentation for the Front Range PHP User Group . Keep an eye out for my presentation or join our Meetup group, you can even like us on Facebook. If you are in Denver, CO or anywhere close, come check us out!