Click here to Skip to main content
15,881,588 members
Articles / Mobile Apps / iOS

How To Deploy Your Mobile App Backend In Google Compute Engine (GCE)

Rate me:
Please Sign up or sign in to vote.
4.89/5 (6 votes)
7 May 2016CPOL7 min read 13.8K   5   1
Integrating Google Compute Engine for your mobile app backend data is the best thing for success of your mobile app.
With the economic progress in a metropolitan city, there is a stark rise in its population. The fundamental idea is to success and acceptance – things become easy to accept once it is successful. It is the reason why technology is now a widely accepted part of human lives.
 
Again, with a number of people using this technology as a service for the betterment of their personal and working lives, the data is getting bigger and bigger. The servers get jammed with the data overflowing out of it pretty frequently. Especially the traffic to servers have increased significantly with the advent of mobile data.
 
Moreover, gauging the demand-supply relation between data and server space many of the technocrats analysed in past bout dearth of server space as well. And that is why, we as a human race, as always came up with a solution. The cloud solution – a virtual space in the cloud to store the data without the help of any physical server. When the data itself is in the cloud, the computing also takes place in cloud.
 
It is called Cloud computing. Here, the remote network servers are one which acts as a host server on the Internet used to store, process and manage the data without the utilization of any server of computers. One of the best infrastructures to perform cloud computing is Google Compute Engine.
 
Google Compute Engine provides a virtual machine running in the Google’s innovative data centres and its worldwide fibre network.
 
Follow the steps mentioned below to deploy the mobile app backend in Google Compute Engine.
 
You must need a google id to move ahead. SO, if not, kindly create a google mail id.
 
Now,
 

1# Go to the Compute Engine and log in using your gmail id.

 
 
 

2# Then, Go to My console (top right corner) this shall land you to the ‘Getting Started’ page. It shall display different information regarding 'starting with Google cloud'.

 
The information over here is mainly related to
  1. Try compute engine
  2. Create Google Cloud Storage Bucket
  3. Try app engine
  4. Use Google APIs
  5. Create Cloud SQL instance
  6. Documentation for more info

You shall be dealing with this page in step no. 2

Here, we are focusing on IaaS (Infrastructure as Service), and therefore, we shall go on the Google compute engine. Because it gives a full server access to the user so that you can modify it as per the requirements.
 

3# Create Project in Google Compute Engine

  1. Select “create a project” option from the drop-down menu and Select a project from the given header.
  1. Now, add the project name. There are two responsive checkboxes which let you agree to the terms and conditions, and second to subscribe to the mailers
 
Now that you have accepted the terms and conditions and created the project you are routed to the dashboard screen.
 

4# In this step, we need to create the instance of the virtual machine where we want to deploy the application.

However, before this, you must need to sign up for the google compute engine by filling up the required information.
 
However, you must enable the billing for your project. For more info click here.
  1. For the payment part – Google provides the credit of $300 with the 60 days trial period to explore the Google cloud platform.
  1. Google Compute Engine adopts ‘Pay as you go’ model. Therefore, you shall be charged only for the services you render in the form of the instance requests.

5# Creating Virtual Machine Instance

  1. In the Cloud Platform Console -- go to the VM Instances page.
  2. Go to the VM Instances page
  3. Click the Create Instance button.
  4. In the Boot disk section, click Change to start configuring your boot disk. You have the option to select the machine type based on the expected server requests.
  5. In the Preconfigured image tab, choose the Debian 8 image or any other which matches your requirement on which you want to deploy backend e.g. Ubuntu 14.04 LTS and so on.
  6. Click Select.
  7. In the Firewall section, select Allow HTTP traffic. If you want to allow secure connection than allow HTTPS traffic too.
  8. Click the Create button to create the instance.

Just wait for some time for the instance to start up. Once ready, it is listed on the VM Instances page with a green status icon.

6# Connect with your Instance

Now the task is to connect the data to the instance you just created

  1. In the cloud platform console goes to VM instance page.
  2. In the list of virtual machine Instances, click on SSH button from the row of Instance to which you want to connect.
  3. It gives you a terminal window for interacting with your Linux Instance.

All the required setup can be done over here in the Terminal window

Here are some of the ways to connect the Google Compute Engine

  1. Connect from a browser (Same step as above explained)
  2. Connect to an Instance using Gcloud
  3. Connect using the SSH on Linux or Osx workstation
  4. Connect using Putty on Windows workstation.

Check how to connect to the instance over here.

7# Now, you need to run the required setup to upload the backend on GCE. Below are the steps which you require following for uploading the PHP backend.

Step 1: Install Apache and PHP on your instance

Sudo apt-get update
Sudo apt-get install apache2 php5

Step 2 : Test Apache & PHP

i. You must have an external IP address of the Instance. You can get this from the VM instance page in Cloud Platform Console.

ii. In the browser, verify if the apache is running. You can see the Apache test page.
http://[YOUR_EXTERNAL_IP_ADDRESS]
iii. Create a test file in the default web server root. 
sudo sh -c 'echo "<?php phpinfo();?>" > /var/www/html/phpinfo.php'
 
iv. Browse the test file to verify the Apache and PHP is working 
http://[YOUR_EXTERNAL_IP_ADDRESS]/phpinfo.php 
You can get the standard PHP info page that provides you with the information about your Apache environment.
 
Note: If your page failed to load (HTTP: 404) Verify

1.    In the Cloud Platform Console, HTTP traffic is allowed for your instance.
2.    The URL uses the correct IP address and file name.

Step 3 : Install MySQL on your instance

v. Install MySQL and related PHP Components

sudo apt-get install mysql-server php5-mysql php-pear

vi. Configure MySQL. You should run the mysql_secure_installtion command to improve the security of the installation.

sudo mysql_secure_installation

Step 4: Install PhpMyAdmin to handle the database of MySQL and follow the basic steps asked during the setup e.g. password for the database access and so on.

sudo apt-get install phpmyadmin
sudo apt-get update

Step 5 : Test & Verify PhpMyAdmin. Before going to test PHPmyadmin follow the steps to change the config file.

vii. Open apache.conf using your favourite editor, mine is vi :)

sudo vi /etc/apache2/apache2.conf

viii. Then, add the following line:

Include /etc/phpmyadmin/apache.conf

ix. Test the PHPmyadmin. You must log in to access the database using the initial username and password.

The default username would be root, and password is the one which you have set during the installation of PHPmyadmin.

http://[YOUR_EXTERNAL_IP_ADDRESS]/phpmyadmin

Step 6: By default the Mod rewrite is disabled in apache and before we start generating the actual URL rewrites, we need to activate the Apache mod_rewrite module to control them.

sudo a2enmod rewrite
sudo service apache2 restart

Step 7: Once the module is enabled, we can set up our URL rewrites by creating a .htaccess file in the backend directory.

x. A .htaccess file is a way to configure the details of your backend or website without needed to alter the server config files.
xi. We can create the .htaccess site in a text editor without giving any name to file and extension .htaccess.

Step 8: Permit the changes in .htaccess file

xii. Allow the .htaccess file to override standard configurations by starting by opening the configuration file.  

sudo vi /etc/apache2/sites-available/default

xiii. Inside that file - find the below-mentioned section, and change the line that says AllowOverride from None to All. The section should now look like this:

<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

xiv. You are required to restart apache once you save and exit that file.

.htacess files shall be available for all of your sites.

sudo service apache2 restart

Though done with the mandatory server setup, we are yet to upload the files on Instance.

However, before uploading it, we need to update the change required for the database connection. 

8#. Transferring file to instance

There are multiple ways to transfer the file we can use any based on our workstation.

i.    Transferring the file using Gcloud 
ii.    Transferring the file using the browser on Linux or OSX workstation
iii.    Transferring the file using SCP on Linux, or OSX workstation
iv.    Transferring the file using WinSCP on Windows workstation

Moreover, this is it; you have successfully transferred the file over the Instance built in the server. Now it has become easy to set up your cloud computing space with Google Computing.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Writer Tatvic
India India
Karan Dave is a Sr. content writer Google Analytics firm, Tatvic. He has blended his interests in analytics with the writing capabilities to provide resourceful information for varied audiences. During his occasional escapes to the Himalayas, he likes to keep himself away from being a technocrat to a tech-free nomad.

Comments and Discussions

 
Newsvery helpfull Pin
Member 1254768826-May-16 0:56
Member 1254768826-May-16 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.