Building an Ubuntu LAMP Web Server

Recently I was setting up my Mac OS X with a kick ass development environment and jotted down all the cool steps I took to build an Ubuntu LAMP web server in a virtual machine environment. Here is this in-depth guide translated from paper to this digital copy. Hope you find this guide valuable and it saves you time when you need to do the same.

LAMP (Linux, Apache, MySQL and PHP)

Ubuntu Server

The flavor of Linux I like to use as a Web Server is Ubuntu.

What is Ubuntu

Ubuntu , is a secure, intuitive operating system that powers desktops, servers, netbooks and laptops. It is based on the Debian GNU/Linux distribution. Ubuntu is also named after the Southern African ethical ideology Ubuntu (“humanity towards others”) and is distributed as free and open source software with additional proprietary software available.

Why Ubuntu

  1. Reduce costs – free to use with no licensing fees.
  2. Visualization – it runs beautifully & fast in any VM environment (esp. Mac OS X)
  3. Build-in security – tight security, inbuilt firewall and encryption.
  4. It based on a Debian Distribution. A computer operating system composed of software packages released as free and open source software especially under the GNU General Public License and other free software licenses. Debian distributions are slower to release but this means they are extremely thorough.
  5. A lot of the big boys use Ubuntu. See case studies here: http://www.ubuntu.com/business/case-studies

Step by Step – your 1st web server

This guide assumes you have already installed Ubuntu Server. If not, go here and do it first. I recommend you install Ubuntu Server in a VM. I use VMware Fusion to run my instances when developing and Amazon EC2 for production. This guarantees that whatever I do locally in a VM will be compatible when pushed into production.

Ubuntu Server in a VMware Fusion

Goal:

  • Install LAMP – Linux (already done), Apache (web server), MySQL (mysql) and PHP (code compiler).
  • Install Webmin – a web-based interface for system administration for Unix.
  • Allow WWW for sFTP so you can remotely manage your website using a GUI.
  • Setup access to MySQL using MySQL Workbench.

1. Install LAMP

  • SSH into your box as root on Port 22 (default post install).
  • Update your OS software (just in case you are missing some dependencies):
    sudo apt-get update
  • From the terminal window, install LAMP using this 1 line of code (the caret (^) must be included):
    sudo apt-get install lamp-server^
  • The apt package manager will display what it is installing and ask you a bunch of standard questions. Just say yes to all. You will also be asked for a password for your new MySQL database. Type that in and note this down for future.
  • When this finishes you are done. Easy hey! Port 80 (default web server port) is now enabled and pointing to ‘/var/www’. ‘/var/www’ is where your site(s) should be placed.
  • Hit the Public DNS URL of your server (typically your IP) to verify that it’s up. It should show up a page with “It works!” If you are not sure what your box’s IP is, type this in and hit enter (similar to ipconfig on a Windows box).
    ip route
  • Before moving to the next step, you may want to know information about PHP’s configuration inc. installed extensions. You can grab this by creating a PHP file from your terminal window like this:
     sudo nano /var/www/phpinfo.php

    then adding this into it, save it, and quit nano (the editor your in):

    <?php phpinfo(); ?>

    restart Apache:

    sudo /etc/init.d/apache2 restart

    Hit the IP in your browser again with this new file name appended to the end eg. http://170.10.105.110/phpinfo.php – it should show you what is running.

2. Install Webmin

  • Edit “/etc/apt/sources.list” to add 2 new source:
    sudo nano /etc/apt/sources.list
  • … add these 2 new lines to the end, save and exit:
    deb http://download.webmin.com/download/repository sarge contrib
    deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
  • Now you can run this in your terminal window to install Webmin.
    sudo apt-get update
    sudo apt-get install webmin
  • Webmin should now be accessible from your browser using the server’s ip address followed by port 10,000 eg. https://170.10.105.110:10000
    Note that you do not have HTTPS cert so your browser will throw a warning since https is (and has to be) the protocol. Ignore it and move forward.
  • If you cannot login with your sudo account you may need to enable root. Follow the steps outlined here: https://help.ubuntu.com/community/WebminWithoutARootAccount
  • Or you can change the password of the root user in your terminal window. Then restart webmin.
    sudo /usr/share/webmin/changepass.pl /etc/webmin/ root foo
    sudo /etc/init.d/webmin restart
    
  • If you need to restart webmin run this:
    sudo /etc/init.d/webmin restart

3. Allow WWW for sFTP

  • You need to make sure the group www-data is added to “/var/www”. Run this in your terminal window:
    sudo chgrp www-data /var/www
  • Make “/var/www” writable for the group.
    sudo chmod 775 /var/www
  • Set the GID for www-data for all sub-folders.
    sudo chmod g+s /var/www
  • Your directory should look like this on an ‘ls -l’ output.
    drwxrwsr-x    root www-data
  • Last, add your user name to the www-data group (secondary group) where USERNAME is the “new” username you will use to sFTP. Note that we follow it by “passwd” to give new account a password.
    sudo useradd -G www-data NEW_USERNAME
    sudo passwd NEW_USER

    OR if the username is “existing” one use the command below. Also don’t forget to add “ubuntu” user if you have set this up on an EC2:

    sudo usermod -a -G www-data EXISTING_USERNAME
  • You should now be able to SFTP to your server using this USERNAME and upload data to “/var/www” with no problems.

4. Access to MySQL using MySQL Workbench

  • MySQL Workbench is a nice free GUI tool by the folks at mysql.com to manage your MySQL database. It can be downloaded from here: http://wb.mysql.com/
  • By default MySQL listens on localhost (127.0.0.1) so if you are going to manage your Ubuntu VM instance from say OS X, MySQL wont allow you entry. Here’s what to do to grant remote management of MySQL.
    1. Go to Webmin and login.
    2. In Webmin, navigate here: Servers > MySQL Database Server > MySQL Server Configuration
    3. Change “MySQL server listening address” to “Any”. By default it is 127.0.0.1. Save this.
    4. Now navigate here: Servers > MySQL Database Server > User Permissions
    5. Click on User “root” on the line where it says 127.0.0.1. And under Hosts change it to “Any”. This set the permissions on your db access.
    6. Save & Restart MySQL and you are done.
  • Remember that this is for “development” purposes only. You would not be allowing “Any” to your DB rather a specific static address and username.

5. Bonus – running multiple web applications on the LAMP instance

To save on time, money and managing multiple boxes, you may want to run multiple websites from this same box. I like to do this using ports as the separator. The following can be done in Webmin:

  1. Upload code to /var/www/mynewsite/
  2. Create a Virtual host for your new web application by navigating to:
    Servers > Apache Webserver > Create virtual host
  3. Fill out the form pointing ‘Document Root’ to the location of your code and assign a ‘Port’ number eg. 81, to this new host. Remember port 80 is your default.
  4. Save and click on ‘Apply Settings’ (link top right of the Webmin interface).
  5. Finally you need to tell Apache to listen to this new port. Navigate here:
    Servers > Apache Webserver > Global configuration > Networking and Addresses
  6. Add port 81 (where your new host is configured on) to ‘Listen on addresses and ports’.
  7. Save, apply changes and restart Apache.
  8. Done. You can now access your website via http://IP_DNS:81

Now go and build kick ass products!

There you have it folks. How simple is that. That’s why I love Ubuntu so much. It’s simple and powerful all under the 1 umbrella. That’s how software should be. All the complexities removed so us engineers can get to work and build kick ass products!

If you found this post useful let me know in comments section below. Super!!

~ Ernest

Difficult Conversations: How to discuss what matters most

I just finished reading a New York Times business best seller which geeked me out big time. It’s called Difficult Conversations: How to Discuss what Matters Most. The book is based on 15 years of research at the Harvard Negotiation Project. The content walks the reader through a step-by-step approach with examples demonstrating how to have approach and handle these conversations with less stress and more success. Let’s face it, no matter how competent we are, we all have conversations that cause anxiety and frustrations. This book is the golden goose that helps us tackle these issues at home, on the job, or out in the world.

The core of difficult conversations

Difficult conversations are almost never about getting the facts right. They are about conflicting perceptions, interpretations, and values. They are not about what a contract states, they are about what a contract means. They are not about being hurt by an action or word they are about how that action or word was interpreted and the impact on our values, what it meant to me. These are not question of right or wrong, but questions of interpretation and judgement.

If your time poor then you can now stop reading because I just told you the holy grail of difficult conversations. If you want to learn more, keep on reading. If you want to chill while learning, you can visit sites such as 텐텐벳.

Don’t assume their intentions

It’s important to never assume the intentions of the person you are dealing with because your thinking how you feel about them will be affected by it and ultimately, how the conversation goes. So never assume we know the intentions of others when we don’t. The truth is, intentions are invisible. We assume them from other people’s behavior. In other words, we make them up, we invent them.

Because our view of others’ intentions (and their views of ours) are so important in difficult conversations, leaping to unfounded assumptions can be a disaster.

This shadows what I learnt back in May 2010 at Jeff Slayter’s seminar on the best kept secrets of modern day heroes and leaders. Jeff shared with us this same concept to never judge a person without first separating their “Behavior” from their “Intentions”. Separating these two allows you to delve open-minded and find that their intentions are not as bad as their behavior may be making us think. This is also the trait of a successful leader to be able to see past the behavior of their followers and understand their true intentions – only then is a leader capable of truly understanding their followers.

Best approach to take when communicating

If you need to deal with faults in your difficult conversation, instead of talking about those faults which automatically put people into defense & denial mode, figure out:

  1. 1. What kept them from seeing it coming and
  2. 2. How to prevent the problem from happening again.

What we are trying to do here is explore why things went wrong and how we might correct them going forward since talking about blame distracts us from a resolution.

So, instead of trying to persuade and get your way, you want to understand what has happened from the other person’s point of view, explain your viewpoint of view, share and understand feelings, and work together to figure out a way to manage the problem going forward.

“Life is just one damn thing after another.” ~ Stone, Patton, and Heen

A difficult conversations checklist

Here is a checklist to follow when having a difficult discussion:

Source: Difficult Conversations, by Stone, Patton, and Heen; p 232-233

Step 1: Prepare by Walking Through the Three Conversations
1. Sort out What happened
  • Where does your story come from (information, past experiences, rules)? Theirs?
  • What impact has this situation had on you?
  • What might their intentions have been

2. Understand Emotions

  • Explore your emotional footprint, and the bundle of emotions you experience

3. Ground Your Identity

  • What’s at stake for you about you? What do you need to accept to be better grounded?
Step 2: Check your purposes and Decide Whether to Raise the Issue
Purposes: What do you hope to accomplish by having this conversation? Shift your stance to support learning, sharing, and problem-solving.

Deciding:

  • Is this the best way to address the issue and achieve your purposes?
  • Is the issue really embedded in your Identity Conversation?
  • Can you affect the problem by changing your contributions?
  • If you don’t raise it, what can you do to help yourself let go?
Step 3: Start from the Third Story
  1. 1. Describe the problem as the difference between your stories.
    Include both viewpoints as a legitimate part of the discussion.
  2. 2. Share your purposes.
  3. 3. Invite them to join you as a partner in sorting out the situation together.
Step 4: Explore Their Story and Yours
  • Listen to understand their perspective on what happened.
    Ask questions.
    Acknowledge the feelings behind the arguments and accusations.
    Paraphrase to see if you’ve got it.
    Try to unravel how the two of you got to this place.
  • Share your own viewpoint, your past experiences, intentions, feelings.
  • Reframe, reframe, reframe to keep on track. [cf. page 204]
    From truth to perceptions
    From accusations to Intentions and impact
    From blame to contribution
    From Judgments, Characterizations to feelings
    From “What’s wrong with you” to “What’s going on for them”
Step 5: Problem-Solving
  • Invent options that meet each side’s most important concerns and interests.
  • Look to standards for what should happen.
    Keep in mind the standard of mutual care-taking; relationships that always go one way rarely last.
  • Talk about how to keep communication open as you go forward

Three Conversations


Use the following with the checklist above in Step 1: Prepare by Walking Through the Three Conversations.

Source: Difficult Conversations, by Stone, Patton, and Heen; p 18-19

Conversation A Battle of Messages A Learning Conversation
The “What Happened?” conversation.Challenge: The situation is more complex than either person can see Assumption: I know all I need to know to understand what happened

Goal: persuade them I’m right

Assumption: Each of us is bringing different information and perceptions to the table; there are likely to be important things that each of us doesn’t know

Goal: Explore each other’s stories: how we understand the situation and why.

Assumption: I know what they intended

Goal: Let them know what they did was wrong

Assumption: I know what I intended, and the impact their actions had on me. I don’t and can’t know what’s in their head.

Goal: Share the impact on me, and find out what they were thinking. Also find out what impact I’m having on them.

Assumption: It’s all their fault. (Or it’s all my fault.)

Goal: Get them to admit blame and take responsibility for making amends.

Assumption: We have probably both contributed to this mess.

Goal: Understand the contribution system; how our actions interact to produce this result.

The Feeling Conversation.Challenge: The situation is emotionally charged. Assumption: Feelings are irrelevant and wouldn’t be helpful to share. (Or, my feelings are their fault and they need to hear about them.)

Goal: Avoid talking about feelings. (Or let ’em have it!)

Assumption: Feelings are the heart of the situation. Feelings are usually complex. I may have to dig a bit to understand my feelings.

Goal: Address feelings (mine and theirs) without judgments or attributions. Acknowledge feelings before problem solving.

The Identity ConversationChallenge: The situation threatens our identity. Assumption: I’m competent or incompetent, good or bad, lovable or unlovable. There is no in-between.

Goal: Protect my all-or-nothing self-image.

Assumption: There may be a lot at stake psychologically for both of us. Each of us is complex, neither of us is perfect.

Goal: Understand the identity issues on the line for each of us. Build a more complex self-image to maintain my balance better.

It’s always best to assume that you will encounter difficult discussions, even when you have mastered the ins and our of discussing what matters most. The difference now is that having this knowledge on how to handle difficult discussions allows you to know that it’s okay to talk about them, so the misunderstandings may not be as emotionally draining and are less likely to threaten the relationship.

Here’s to discussing what matters most!
~ Ernest

Credit history: Expats guide on building credit history in America

I have an awesome credit history in Australia. With property & stock investments behind my name over a number of good years and credit cards with limits I’d never hit you’d think I have it easy on the credit history front in America. I mean America and Australia already have a tax treaty which stops me from getting taxed twice and includes nice tax breaks for all Aussie ex-pats.

Well that’s where things change. American financial institutions, and uncle Bob, don’t care about your good credit history in Australia. They say you have to start from scratch here and prove to them you are capable of managing your money on the American soil. If you intend to stay in America for only a few years to earn some cash and go back home then getting credit history in America will not be your priority. However if you think there is a slight chance you may stay I recommend you get familiar with how credit works in America. If you’re a parent, then you should also learn how to secure your child’s financial future with The Children’s ISA.

How does credit work in America

So let’s look at this:

  • You start with 0 credit score in the USA.
  • Your prior credit history in Australia means nothing, even if you are a good investor.
  • 0 credit score means you can’t buy Ford shares UK, or get a car loan (sort of, I will explain this later), a credit card (there is a way though which I will explain later), buy anything which requires bank’s leverage (money) like a house, car, shares etc…

In the U.S. credit scores are broken down into 5 categories each contributing to a percentage of your credit score:

35% – Payment History: This is whether you have paid on time or not
30% – Debt To Credit Limit Ratio: This is your total debt compared to your total credit limit
15% – Length Of Credit History: This is how long you have had credit
10% – Types Of Credit Accounts: This is the different types of credit you have
10% – Inquiries (hard): This is when a creditor checks your merge credit report

Most important factors in your credit score:

  • Whether you pay your bills on time and
  • How much of your available credit you actually use.

Credit score

As I mentioned above you start with 0 credit score. Once you start building credit history your score will increase.

The range:

  • Credit scores range from 300-850, with 723 being the medium FICO score of Americans.
  • Scores below 600 are considered high risk borrowers,
  • 620 being the dividing line between good and bad,
  • 640 or above being “pretty good”,
  • 650 as average general credit-use behavior, and
  • above 690 or 720 being excellent

More on credit score can be located here.

Building a super-duper credit score

  • Since best method is to get a car loan. Even if you don’t need a loan get one at least for 50% of the vehicle’s value. Make sure it’s not lower than $5K. This is what I did with my wife. It was tricky because no financial institute will give you a “car loan” since you have no credit history but you need credit history to get a car loan. A chicken or egg scenario. However there is a way! I found this small hole the hard way and will explain it in my next post on purchasing a car using a loan. Check out Houston in house financing for easy car loan.
  • Get a secured credit card. Note, a “secured” credit card not an unsecured one. No one will give you an unsecured credit card. With a secured credit card you pay the institute (bank) a sum of money ($2K in my case) and they use that as security for your $2K limit credit card. You do get this money back once they approve you for an unsecured credit card but for now budget around $2K out-of-pocket. An unsecured one is your typical bank credit card where you use the banks money. This means you will need to recharge (pay credit card dept) on your money every month. Remember you are “proving” to your bank you can pay off the “dept” in a reasonable amount of time and know how to handle it. You will be able to convert to a regular, unsecured credit card after 12 to 18 months of on-time payments.
  • Do not max out any of your credit cards, or even get close. Keeping your credit use to less than 30% of your credit limits (10% is better) will help you get the best possible credit score – and should help keep you from getting over your head in debt, as well.
  • Pay utilities (power, gas & electricity) and property rental in your name and set up automatic payments or reminder systems so that you’re never, ever late. All it takes is a single missed payment to trash your credit scores – and it can take seven years for the effects to completely disappear.
  • Get a store card like Macy’s Credit Card. Macy’s is one of America’s largest chain of mid-to-high range department stores. Department stores like Macy use finance companies, rather than major banks, to handle the transactions. These cards don’t do as much for your credit scores as a bank card (Visa, MasterCard, Discover, etc.), but they’re usually easier to get. Again, don’t go overboard. One or two of these cards is enough.

Your credit score

Finally, you’re also entitled to a free annual look at your reports from AnnualCreditReport.com or CreditSesame.com. This is known as a “soft inquiry” (thanks Brian P. Hamachek). It is ok to use these systems to frequently check your credit score since they are not recorded on your credit report. Hard inquiries (when buying a house or car) remain on your credit report for 24 months and an impact for only first 12 months. A good rule of thumb is to only apply for credit when you really need it, this will give you the opportunity to be elgible for the best 5 year fixed rate mortgage.

CreditSesame is a nice free online tool which also advises you how to improve your credit score and show you what causes it to fluctuate. I use this one regularly.

I believe I covered most of what’s needed (stuff I did and am doing) but if you know of more stuff I can do or have missed here feel free to share it in the comments section below.

Update Sep 10, 2011 – Thanks to Brian P. Hamachek and Philip Tellis for contributing to this post in the comments sections below. Some updates were made to the body of this post. You guys rock!

Here’s to building a fantastic credit history in America.

Ernest

Google Voice – how to protect your privacy

Teach your phone new tricks – Google Voice enhances the existing capabilities of your phone, regardless of which phone or carrier you have – for free. In my view, Google Voice is the 2nd most useful product offered from a set of Google apps. Here’s why.

What is Google Voice

Google Voice gives you one number for all your phones, voicemail as easy as email, free US long distance, low rates on international calls, and many calling features like transcripts, call blocking, call screening, conference calling, SMS, and more. Google Voice allows me to select any of my phones (fixed line and/or mobile) to connect me with the caller.

Google Voice interface

What features work for me

  • One Number – I have set up a nice network of phones closest to me for Google Voice to call. So I am no longer limited by a handset or carrier and I can always give just the 1 number to people.
  • Online voicemail – Should I miss a call or choose to not accept a call Google Voice will divert the user to my online voicemail (which can be customized to each caller) and record it. No big deal here right. But here is where it gets better. I also receive via email and SMS a transcribed version of the voice mail and if I log in to Google Voice there it is again, the transcribed version.
  • Call screening – Everytime someone calls me on my Google Voice you go through my virtual secretary who asks you your name and then tries to connect with me. I can choose to decline the call if I’m busy or am getting spammed and it goes directly to my voicemail.
  • Do not call block – In Google Voice online interface I can “Block” callers from ever calling me again. This is great since in Australia we have the “Do Not Call Register”. A government ran website protects individuals privacy by stopping certain telemarketing calls to fixed line and mobile telephone numbers. In the USA (as far as I’m aware) there is nothing like this. This is where Google Voice helps. Additionally, individuals concerned about privacy and unwanted solicitations may explore internet privacy services to further enhance their protection against unsolicited communications and safeguard their personal information.
Blocking a caller

Protecting my privacy

This means that I can still keep my fixed land line and mobile (cell) numbers but now I give out my Google Voice number to people I meet at meetups, real estate agents, car dealers etc… if one of them abuses my number or passes it to a telemarketing agency I just block them in Google Voice and Google Voice will no longer connect me with those callers. Simple.

Also, since there is a screening feature which allows Google Voice to 1st call me and ask me whether I want to speak with the individual trying to connect with me I always know who is calling me before I say g’day. Should I wish not to speak to them, Google Voice will tell the caller I am not available and they can leave a message for me. Talk about a personal assistant!

Business cards

When Google Voice launched into Beta I was one of the lucky few American’s to get access to it. Google also gave out a bunch of free 25 business cards with the Google Voice number. Since then I have paid to have a lot more printed since I love the simplicity of these cards and the fact that I can hand these to people I meet.

Here’s my Google Voice business card:

Call me!

URL’s mentioned in this post:

Do Not Call Register – https://www.donotcall.gov.au/
Google Voice – http://google.com/voice

Ernest