Tag Archives: GNU Linux

Hypervisor Troubleshooting for Linux Web Development Servers

There are a few things that can cause problems accessing your virtual machine fully from your host machine. Lots of cases work straight away, but some may come about from mucking with settings your first time out, or from importing the virtual appliance from another machine. The following are the key sources for the causes of connectivity problems.

  • Router
  • Hypervisor
  • Virtual Machine
  • Hosts file

Here are some troubleshooting notes that cover most of the problems that I have encountered since I have learned how to set up virtual machines for website development. The following are still loose notes cleaned up from my own local notes file.

Router

Don’t be above rebooting your router if you have a problem. See if it works after that on the same settings you are on, especially if the virtual machine and host interaction works as you expect it to work. If you are in a web cafe, and you cant get it to work, use your mobile phone as a wireless access point. It will likely be more stable than most web cafes out there.

In the hypervisor

Moving a vm over to a new host machine? Turn off appliance, turn off network>enable network adapter, exit virtual box, restart virtual box, re-enable same adapter, boot up vm.

When moving over to my macbook pro, I had to change the name of my bridged adapter to en1. ( how would I find that out?) I also had to change Advanced > Adapter type to Intel PRO/1000 MT Desktop (82540EM). So be aware of your adapter type.

How I usually operate is this way:

I have an internet connection, even if it is only provided by my mobile phone. Mobile phones are very handy for this purpose.

With your virtual appliance turned OFF:

  • Select the virtual machine > Settings > Network > adapter 1
  • If this is a virtual appliance you have
  • Check enable network adapter. Toggle and close and reopen settings if this is an imported VM.
  • Attached to: Bridged Adapter.
  • Name: Your Ethernet connection, basically. On my Mac it says en1: Wi-Fi (AirPort)
  • Advanced: Cable Connected is CHECKED.

In the Linux virtual machine

Find eth0. I want to see my IP addy in my ifconfig like I do in ipconfig in my win7 host.

Use
ifconfig or  ifconfig –a

to see what is up in the terminal window.

Ideally you should be seeing eth0 and a normal looking IP. Something like 192.168.1.80.

Sometimes, eth0 disappears. Are you on NAT? Try bridged.

Try restarting the network interface. Release dhcp…

  • sudo ifconfig eth0 down
  • sudo ifconfig eth0 up
  • sudo dhclient eth0
  • sudo dhclient –r
  • sudo dhclient

http://www.ubuntugeek.com/how-to-release-and-renew-a-dhcp-ip-address-in-ubuntu-10-04-lucid9-10-karmic9-04jaunty.html

Things to do to get eth0 back – try editing your network rules.

Sudo Vi /etc/udev/rules.d/70-persistent-net.rules

Look for eth0 in the NAME= attribute. If there are others, delete them. If there is eth1 but no eth0, You can overwrite eth1 with eth0, save and reboot the virtual machine.

Note, if you have this problem, it seems to work better to remove any superfluous entries in 70-persisiten-net.rules and overwrite the eth# that is up in your ifconfig –a result, then reboot the virtual machine, go to ifconfig –a, and you will see it up.

So now ifconfig –a tells me that my inet addr is 10.0.2.15. a step forward, but we still aren’t talking to the virtual machine seamlessly like it were a remote server.

Zurmo.org has a tutorial for installing their CRM software with a virtual machine. Consider trying their software to get started with virutalization. http://zurmo.org/wiki/how-to-install-zurmo-virtual-machine

NAT – When using NAT, its like putting the virtual machine behind a virtual router. Just like a router at home. Never mind port forwarding. I am at a new place, and bridged doesn’t seem to work. OK, so try NAT. NAT at least allows me to ping a website on the internet, which mysteriously doesn’t work anymore in Bridged. NAT gives me an ip address on eth0 of 10.0.2.15. Bridged gave me 192.168.1.113. I don’t remember what I did. I rebooted my router.

The normal settings are what works consistently. It does take some practice to get it to work, so don’t give up.

Hosts file

  • General: Any time you move your computer to a different network, or reboot your router, your computer gets assigned a new IP address. You have to keep close tabs on your hosts file so it can be updated. Any line in a hosts file that starts with a  ‘#’ is not executed.
  • Windows: C:\Windows\System32\drivers\etc\hosts – find it, right click on it, and allow permissions for the current user to modify contents of the file. Save a shortcut to where you are going to have easier access on it.
  • Mac: /etc/hosts – Mac users should know the password for their user profile. Open Terminal, and use a command line editor such as vi or emacs to open your hosts file. If you don’t know how to use vim or emacs, go find a tutorial on the web and practice it. You must open the file with the sudo command, and correct password challenge, such as sudo emacs /etc/hosts.
  • Ubuntu Desktop: /etc/hosts  - as above, know your user account password, hoping it has privileges to modify the hosts file with sudo. Get a tutorial on using vi, nano, emacs, or other editor when you get into Terminal so you know what to do when you are there.

There are probably more cases where the connectivity to the virtual machine is lost. I will add more solutions to this problem as I encounter and solve the cases for it.

Virtual Machines for Web Development

  • Use case
  • How to with screenshots
  • Link to trouble shooting on blog.

Use case

If you are a web developer, it is your responsibility to have a development environment to build your sites before building them on the server. We get away with all sorts of things for years that looking back would be called insufficient. As we improve and get more serious about our work we need better systems. I am a small independent developer; I use Mac, Win, and Ubuntu desktop environments interchangeably. I want a system that is common everywhere I go. I want it to be as close to a real web server as possible. I want to set up quickly and completely. I want to even set up clients and team members with the same environments. My development environment requirements have gone from whatever works, to what works well and right. I started off with installing Windows exes of Apache-PHP-MySQL, and then went on to desktop software such as XAMPP and WAMP and MAMP. But I knew that something was missing from these environments as compared to the real ‘production stack’ that the website runs on. No matter how much time was spent on them, they weren’t the real thing. Why not run a mirror of the real stack? I had heard of it being done, and it took a while to figure out but I have it running. Now that I use virtualization as my web development solution, I will never go back.

Use virtualization to mirror your web stack for development and reap the benefits.

With virtualization, I can have a copy of a web server on my computer, that runs the same way a production web server will run, uses the same packages, gives me access to the shell to work the way I would as if I were online, and groups together the entire stack that the site runs on. Virtual machines running virtual LAMP stack offers all these advantages, and more. I have a system that runs and configures the same on my Win 7 machine, my Ubuntu desktop, and my Macbook. I keep many virtual machines stored, and use them for the case required.

  • Common dev setups across different desktops
  • Common dev setups for dev teams
  • Can function independently from the internet and remote web servers
  • Opportunity to run custom stacks
  • Opportunity to deploy VM to cloud
  • Opportunity to use shell tools instead of desktop stand-ins
  • Opportunity to ditch fake setups
  • Can provide offline copy of site to paying customer
  • A real sandbox for practicing new techniques
  • Can deliver code that will run on the production server with a greater degree of reliability

There are many hypervisors out there, and they all have their best use cases

For the purpose of this demonstration, and for my needs I use Oracle VirtualBox. I use this because it is free to use, and easy to work with; I can set up other users with virtual machines regardless of their skill level or use purpose. Other hypervisors may also fit this bill, to some degree, and I encourage exploration. It is good to know also that there is some interoperability of virtual appliances between different brands of hypervisors, or there are methods and workarounds to make it happen.

Hypervisors: http://en.wikipedia.org/wiki/Hypervisor

How to with screenshots

Skill level: Ability to use Desktop and command line environments. Ability to use the software listed below.

Software:

Desktop: Windows, Mac, Ubuntu Desktop.

Oracle VirtualBox https://www.virtualbox.org/wiki/Downloads .

Oracle VM VirtualBox Extension Pack https://www.virtualbox.org/wiki/Downloads .

A text editor, or Komodo Edit http://www.activestate.com/komodo-edit .

Download a Linux Distribution. Consider Ubuntu Server iso http://www.ubuntu.com/download/server . You can also find prebuilt virtual appliances from Bitnami http://bitnami.com/ , Turnkey Linux http://www.turnkeylinux.org/ , if you are ready for something more prebuilt.

Any good web browser (Firefox, Opera, Chrome, Safari, etc).

FileZilla for ftp transfers. https://filezilla-project.org/

PuTTY http://www.chiark.greenend.org.uk/~sgtatham/putty/

Mac, or Ubuntu: Terminal (built in).

Access to your hosts file

Windows: C:\Windows\System32\drivers\etc\hosts The hosts file is a part of computer networking systems. All computers that use networks have a hosts file.

Mac: /etc/hosts

Ubuntu Desktop: /etc/hosts

How to set up a Virtual Machine as a development web server.

  1. Install VirtualBox in your desktop environment.
  2. Install VirtualBox Extension Pack
  3. Open VirtualBox, create a new machine, and give it a few gigs of space.
  4. Start up the ISO you have obtained, just like you were installing Linux on a hard drive.
  5. Log in, run ifconfig to get your inet addr value for eth0.
  6. Find your hosts file on your local machine. Change the file to writeable permissions if needed (Win).
  7. Although you have access to the terminal shell environment from a window in VirtualBox, you can now use that IP address in PuTTY or FileZilla to access the virtual machine.
  8. Enter your IP address in your hosts file, and assign the aliases you want to use for websites.
  9. For setting up Apache2 websites in your virtual machine, refer to tutorial information widely available on the web.
    1. Tutorial 1: http://www.thegeekstuff.com/2011/07/apache-virtual-host/ ,
    2. Tutorial 2: http://www.debian-administration.org/articles/412 ,
    3. Tutorial 3: http://www.linode.com/wiki/index.php/Configure_apache_to_use_virtual_hosts_on_ubuntu_server .
  10. Copy default to your new site name, and edit it as sudo user.
  11. Use sudo a2ensite (sitename) to copy virtual host file in your sites-available folder over to your sites-enabled folder .
  12. You will probably need apache mod_rewrite. Enter sudo a2enmod rewrite at the command line.
  13. Reload server: sudo service apache2 reload .
  14. Once your apache2 virtual hosts have been created, with directories created inside your machine, you can browse to your virtual machine via your web browser. You would be able to go to  http://test if you created a virtual host entry called test, and you had it configured properly.
  15. Get to phpMyAdmin by going to http://(your ip Address)/phpmyadmin .
  16. There are sometimes a few issues to sort out between your hypervisor, your guest machine, and your host. See troubleshooting page.

Now that I use virtualization as my web development solution, I will never go back.

    Share a virtual appliance via a private torrent

    I am going to defer here to other people on how to do this, but I want a note on how to Share a virtual appliance via a private torrent because it is a way to easily share large files ie linux distros, with your fellow developers. My use is to get a team of developers using the same virtual machine for a development environment. I found with one test it takes about 10 minutes for my friend to start receiving my file.

    http://lifehacker.com/5534190/how-to-share-your-own-files-using-bittorrent

    http://www.howtogeek.com/howto/33597/bittorrent-for-beginners-share-large-files-using-your-own-private-tracker/

    Databases on virtual machines

    Of course you have the command line open to you and you can do as you wish there, and you do need to know how to do things there.
    In your linux virtual machine, if you built it yourself, you likely installed phpmyadmin, a host entry was created when the Os was built. You can check for it in the shell at /etc/phpmyadmin/ . You would go to it in your browser below the IP address for your virtual machine. Today, its at http://192.168.1.76/phpmyadmin.
    A root account was created for mysql with a password. An old security bug was that the password for root was left blank. The root user can have any name, its just common use to use ‘root’ for the master user on machines. To create new dbs, you generally create a new user for each db. Log in to phpmyadmin, go to the Privleges tab, create user, select local from the host options. Do not type in local or localhost in the menu, select it from the menu.

    FreeGeek Vancouver is Computer Heaven

    Freegeek Vancouver is technology heaven and I can prove it. I took photos. It is thriving. It is a beehive of activity. FreeGeek is a ‘non-profit computer re-use and recycling centre’ that only opened in Vancouver a couple of years ago as a branch of the original operation in Portland, Oregon. They have expanded their facilities at least a couple times that I know of just to keep up with the community need to properly recycle computers. If you want to learn about technology, if you want to work in technology, if you want to learn about Free Open Source Software, FreeGeek Vancouver is the place to be. It is computer heaven, because that is where computers go to die and are reborn again.

    What you can do at FreeGeek:

    • Donate hardware, books.
    • Recycle.
    • Take short courses in hardware and software, or teach them if you have the background.
    • Mentor someone.
    • Volunteer for 24 hours and take away your own computer.
    • Shop the computer thrift shop, for super affordable computers and peripheral devices.
    • Learn to hack computers and technology, everything an engineer learns how to do.
    • Learn about Ubuntu Linux, and attend the Vancouver Ubuntu User Group meetings.
    • Take part in cleaning up the environmental problems generated by e-waste.
    • Receive a grant of computer hardware as a non-profit community organisation.
    • Donate money or materials for the FreeGeek wish list.
    • Apply for a paid position, or join it as a board member.

    Video on FreeGeek:

    YouTube Preview Image

    Find out lots more about FreeGeek at http://freegeekvancouver.org/ .