Showing posts with label virtualbox. Show all posts
Showing posts with label virtualbox. Show all posts

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:
[Zend]
name=Zend Server 
baseurl=http://repos.zend.com/zend-server/6.0/rpm/$basearch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key
  
  
[Zend_noarch]
name=Zend Server - noarch
baseurl=http://repos.zend.com/zend-server/6.0/rpm/noarch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key

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.

http://[vm_ip_address]:10081

OH NO!



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.

http://[vm_ip_address]:10081

SUCCESS!


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 http://www.zend.com/products/server/license/product?edition=FREE. 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.

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()  
    {  
        $this->assertTrue($this->blog->hasPosts());  
    }


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?

Testability

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!