LAMP installation on Google Cloud Platform

Updated 11 October 2018

Introduction:

 

In our previous blog, we discussed about how to create a compute engine VM on GCP. In this blog, we will discuss about LAMP installation with multi-tier architecture on GCP. We will be using the Compute Engine service of GCP for Linux server, Apache Web server and php. For the Mysql database, we will use the SQL service of GCP as a separate micro service. We will connect both the services to design  a multi-tier architecture for LAMP installation. For Installing LAMP on GCP, you need to have a registered GCP account. For this blog, we assume that you already have a registered GCP account.

 

Creating a Compute Engine VM:

 

For creating a Compute engine VM, you may refer to my previous blog on running a compute engine VM on GCP. In this blog, we will use the following:

 

  • Linux OS: Ubuntu 16.04
  • Apache Version: v2.4
  • Mysql Version : v5.7
  • Php Version: v7.0

 

First create a Compute Engine VM on your GCP account and once you have created a VM instance, ssh login to the VM server to install apache and php. You can login to ssh either via GCP provided web console or third-party ssh tools like terminal or putty. Here we will use the GCP web console for ssh login. For details on using third-party ssh tools, please refer to my previous blog.

 

To SSH login to the VM instance via “ssh web interface”, click on the SSH button of the instance from the console by going to Navigation menu > Compute Engine > VM Instances. On clicking on the ssh button of the VM instance, an ssh web interface will be prompt where  you will be logged in to that particular instance. Here you can perform any operations on the server via ssh.

 

 

Installing Apache and PHP:

 

After login into the VM instance, you can install apache web server and PHP. You can define your preferred php version for installation.

To install apache web server, Use the following commands.


 

To install php and its extensions, use the bellow commands. We will use php7.0 for the demo.


 

To check apache and php installations and its version, use the below command.


 

Enable apache rewrite and headers module.


 

Now Apache webserver and php has been installed on your server.

Further you may also need to install mysql-client to login to the remote database instance i.e. on SQL service of GCP.

To install mysql-client, use the below command.


 

To check the mysql installation and its version, use the below command.


 

Creating a MySQL database using SQL service of GCP:

 

To create a mysql database using SQL service of GCP, go to Navigation menu  > SQL. Now click on “create instance”, choose database engine as MySQL and click on next. Next you need to choose the use case i.e. for development, staging or production. Here we will choose development. Next in the configure step,  choose Instance Id, Root Password, Region and zone. You can also change other configuration parameters as per your requirement but we will keep it default for this demo. Now click on create button to create the mysql instance. Once the Mysql Instance is created, you can click on its instance id to see its details. You can also find the Public IP of the MySQL instance in the Overview section.

 

 

Connecting MySQL Database with VM instance:

 

Once you have created a Mysql Database on SQL service of GCP, its time to connect the Database to the Compute Engine VM instance. For this, you need to allow the public IP of the Compute VM, in the firewall rules of the MySQL service. Click on the MySQL database Instance Id that you created and select the Connections Tab, and under the connectivity section, click on “Add network”. Now give a name to the network and add the IP of the Compute VM instance in the CIDR format i.e. <ipv4_address>/32 and finally click on done and save. This will allow the Compute VM instance to connect with the MySQL database instance.

 

 

To verify that the database is properly authenticated to the MySQL database, ssh login to the Compute VM instance and check if you are connected and able to login to the database instance. For this you need the Public IP of the database instance which you can easily get in the overview section of the MySQL Instance.



 

If you are able to login to the MySQL instance through the public IP, then your Compute instance VM is properly authenticated the MySQL database instance.

 

Congrats, you have now successfully set up LAMP on GCP with multi-tier architecture with separate Instance for Compute and Database.

Stay Connected!

 

In case of any help or query, please contact us or raise a ticket at [email protected].

 

Tag(s) GCP
Category(s) cloud linux php
author
. . .

Leave a Comment

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


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home