Blog Post

Create a new VM instance(UNIX based UBUNTU) on Google cloud with LAMP

Let’s start with creating a VM(Virtual Machine) instance on google cloud with (LAMP) stack.

1. Create Virtual host on Google cloud(Referred v.lemonn blog and video)

  • Go to google cloud console.Check in which project your are.
  • Go to left menu and search for Compute Engine.
  • Click on Compute engine.
  • Select ‘VM instances’.
  • Click on ‘CREATE INSTANCE’ button placed in header section.
  • Enter name of instance as per your choice.
  • Select zone as per your client base.
  • Select Machine type as per your requirement. You can add more CPU’s or increase space.
  • Select Boot disk. We selected UBUNTU 16.04 LTS.
  • Select firewall which tells you what type of request you would like to handle on server.
  • Click on create and an instance will be created.
  • Come to dashboard again and you can see your newly created instances.
  • Dashboard shows various columns. We will be using external IP. Please note this is called an external IP because if you share this link ‘http://(your external IP)’ with your friend, he/she can view data displayed on this IP as well.
  • Now when you open ‘http://(your external IP)’ you see a page which says “This site can’t be reached”.
YOU HAVE SUCCESSFULLY CREATED VIRTUAL MACHINE ON SERVER

Now, let’s check the reason  why “This site can’t be reached” this message is displayed.

So first let’s recall what all we have,

1. We have server, that is one CPU which is located in zone you select while creating instance (HARDWARE).
2. It has Linux based operating system named UBUNTU(SOFTWARE).

That’s it !!!

When we hit “http://(your external IP)” on browser i.e. client where we actually wish to display some data, server needs someone to handle such http requests. Here is when apache comes into picture. Let’s see this virtual representation.

CLIENT (with request)———>APACHE(http/https)———>SERVER(where files locate)

HURRAY!!! So now you know why we need APACHE.

Ok so now let’s check how to setup Apache and PHP.

2. APACHE and PHP setup on server.

To setup apache on server we need command line interface.

  • We have to now go to dashboard and click on instance which we created. Check section named as “Remote access” and click on ssh keys.
  • Once you do that you see we are gifted with a console. Yay !!! we are actually inside the server… Unbelievable isn’t it?
  • Ok so now type ‘ll’ in command prompt. If you need more information about ‘ll’ check on “https://unix.stackexchange.com/questions/137703/difference-between-ls-l-and-ll” and there are many other descriptive websites as well.
  • So now we get list of users there permissions for each file in the system and so on.
    Now type ‘ls’ in command line.You find nothing. Thats because we haven’t added anything 😐
  • I will be listing down few commands with there meaning , You just have to execute this command (Copy and Paste) it in command line and see what happens.
  • Install Apache:
    • Command 1 : First lets be up-to-date before starting installation so we are sure we have latest editions
      sudo apt-get update
      This command will update all packages on server.
    • Command 2 : Now lets install Apache2(The broker guy between client and server)
      sudo apt-get install apache2 php libapache2-mod-php 
      After running above command few questions are asked like :
      After this operation certain space might be used is it okay? You have to type y for this.
      Installation is almost done. To check if its done or no type command 3.
    • Command 3 : This command will be used to check status of apache2 whether it is installed properly and running or no?
      sudo service apache2 status
      You can see that apache2(http server) is up and running.
      – Now again go to the link “http://(your external IP)” and see what is displayed.
      – You can see a page which says “Apache2 Ubuntu default page”.

Interested to know where this page comes from?

So guy’s lets deal with some theory now. In UBUNTU systems /var is the root folder. When you go inside this folder you can’t see www folder if you do this before apache2 is installed. As www folder comes with apache installtion packed with various functions and command for serving http commands.

After installation type of apache2 you can see www folder in var. This means that apache2 has been installed.

cd /var/www/html and you find a file named index.html. This is what is rendered when you hit (http://(your external IP) after apache2 installation. So know you know why you need Apache2 server.

You can check if php is installed on your machine using php -v.

YOU HAVE SUCCESSFULLY INSTALLED  APACHE AND PHP

3. MYSQL server setup on server

Now let’s see how MYSQL is installed.

  • First take all package updates, use the following command :
    sudo apt-get update 
  • Now let’s install MYSQL server using following command :
    sudo apt-get install mysql-server
  • Check if mysql server is running, use the following command :
    systemctl status mysql-service

YOU HAVE SUCCESSFULLY INSTALLED  MYSQL

Congratulations!!!. You have setup a server on google cloud with LAMP stak successfully.

This Virtual Machine instance includes Apache(http) server, MYSQL (database) server and PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *