How to deploy a website code into a compute engine virtual machine and serve the website from GCP

In this tutorial I will clone the codebase of a pre-built website from GitHub into a virtual machine and serve the website files over the internet.

This tutorial builds on a previous tutorial: How to setup a compute engine VM on GCP and install LAMP stack on the server.

Prerequisite

Complete tutorial: How to setup a compute engine VM on GCP and install LAMP stack on the server.

Find the link to the YouTube tutorial here.

Steps

i) SSH into the VM – Log into your GCP console and SSH into the server virtual machine instance. 

ii) Change to the apache2 web server root directory:

ls
cd /var/www/html

List files

ls

iii) Clone prebuilt code from https://github.com/ugogineering/computershop2 into the VM with the command:

sudo git clone https://github.com/ugogineering/computershop2.git 

List files:

ls

Change to the cloned directory

cd computershop2

iv) Move cloned files to web server root directory

sudo mv * ..

v) Change directory

cd ..

vi) List files

ls
Screenshot of a website home page
Screenshot of a website home page

vi) Visit website file in the virtual machine from a browser over the internet by opening a browser and going to 

http://[EXTERNAL_IP]/index.php

You should see the website home page. Make sure that you don’t use the https protocol specifier because HTTPS is not configured.

END.

What we accomplished in this tutorial

i) We cloned a website code from GitHub into a compute engine virtual machine on Google Cloud Platform (GCP);

ii) We viewed a web page from the virtual machine from a browser over the internet.

NB: With the skills you learned in this blog and accompanying video you have skills to clone code from a repository into a compute engine virtual machine.

If you have comments or corrections about this blog post please write them in the comments section below and I will respond. Thank you.

References

  1. How to setup a GCP compute engine virtual machine instance and install Linux, Apache, MariaDB, PHP (LAMP) Stack on Ubuntu 22.04 – YouTube Video.
  2. How to setup a GCP compute engine virtual machine instance and install Linux, Apache, MariaDB, PHP (LAMP) Stack on Ubuntu 22.04 – blog post.
  3. My (Ugochukwu Ukwuegbu’s) YouTube channel.

How to setup a GCP compute engine virtual machine instance and install Linux, Apache, MariaDB, PHP (LAMP) Stack on Ubuntu 22.04

YouTube video demonstration of how to install a LAMP stack on a virtual machine server

Introduction

A “LAMP” stack is a group of open source software that is typically installed together in order to enable a server to host dynamic websites and web applications written in PHP. The term is an acronym which represents the Linux operating system, Apache web server, MySQL database and PHP.

This guide will show you how to set up a virtual machine and install a LAMP stack on an Ubuntu 22.04 server. It will also show you how to store data in a MariaDB relational database, retrieve the data and serve it on a web page.

Prerequisites

In order to complete this tutorial, you will need to have a Google Cloud Platform (GCP) account.

Step 1 – Set up a Google Compute Engine virtual machine

i) Log in to your GCP console and go to the VM instances page

ii) Click Create instance.

iii. In the Name field, enter lamp-guide.

iv) In the Machine configuration section, select e2-micro for Machine type.

v) In the Boot disk section, click Change.

vi) In the Boot disk window, perform the following steps in the Public images tab:

  1. In the Operating system menu, select Ubuntu.
  2. In the Version menu, select Ubuntu 22.04 LTS.
  3. Click Select.

vii) In the Firewall section, select Allow HTTP traffic and Allow HTTPS traffic.

viii) Click Create.

Give the instance a few seconds to start up.

Step 2 – Deploying the LAMP stack on Compute Engine

In this section, you configure the LAMP stack.

Connect to your instance

i) In the Cloud Console, go to the VM instances page.

ii) In the list of virtual machine instances, click the SSH button in the row of the instance (lamp-guide) to which you want to connect. 

iii) Note down the IP address of your VM instance. You can see this address in the External IP column.

Install Apache and PHP on your instance

By creating an instance, you already have the Linux part of LAMP. In this section, you install Apache and PHP.

sudo apt-get update
sudo apt-get install apache2 php libapache2-mod-php
php -v

Test Apache and PHP

  1. Get the external IP address of your instance from the VM instances page in the Cloud Console.
  2. In a browser, enter your external IP address to verify that Apache is running:
http://[YOUR_EXTERNAL_IP_ADDRESS]

You should see the Apache test page. Make sure that you don’t use the https protocol specifier because HTTPS is not configured.

  1. Now you create a test file in the default web server root at /var/www/html/ .
cd /var/www/html/

ls
sudo nano phpinfo.php

Enter the following line in the text editor:

<?php phpinfo(); ?>

Then save and exit the nano text editor. (Ctrl + X and then press Y)

  1. Browse to the test file to verify that Apache and PHP are working together:

http://[YOUR_EXTERNAL_IP_ADDRESS]/phpinfo.php

You should see the standard PHP page that provides information about your current Apache environment.

If the page failed to load (HTTP 404), verify the following:

  • In the Cloud Console, HTTP traffic is allowed for your instance.
  • The URL uses http with the correct IP address and filename.

Install MariaDB (a relational database server)  on your instance

Install MariaDB and related PHP components:

sudo apt-get update

sudo apt-get install mariadb-server php php-mysql

Check the MariaDB server statuses

Run the following command to check whether the MariaDB database server is running: 

sudo systemctl status mariadb

If mariadb service is not running, then start the service with the following command:

sudo systemctl status mariadb

If the mariadb service is not running, then start the service with the following command:

sudo systemctl start mariadb

Let’s use the mysql client to connect to the database server:

sudo mysql

Configure MariaDB

Run the mysql_secure_installation command to improve the security of your installation. This performs steps such as setting the root user password if it is not yet set, removing the anonymous user, restricting root user access to the local machine, and removing the test database.

sudo mysql_secure_installation

STEP 3 – Testing Database Connection from PHP

sudo mysql -u root -p
CREATE DATABASE sample_database;
CREATE USER 'sample_user'@'%' IDENTIFIED BY 'ChooseYourPass@789!';
GRANT ALL ON sample_database.* TO 'sample_user'@'%';
CREATE TABLE sample_database.todo_list ( item_id INT AUTO_INCREMENT, content VARCHAR(255), PRIMARY KEY(item_id));
INSERT INTO sample_database.todo_list (content) VALUES ("My first important item");
sudo nano my-sample-data.php

Paste the following code in the my-sample-data.php script, save, and close it.

<?php

$user = "sample_user";

$password = "ChooseYourPass@789!";

$database = "sample_database";

$table = "todo_list";

try {

  $db = new PDO("mysql:host=localhost;dbname=$database", $user, $password);

  echo "<h2>TODO</h2><ol>";

  foreach($db->query("SELECT content FROM $table") as $row) {

    echo "<li>" . $row['content'] . "</li>";

  }

  echo "</ol>";

} catch (PDOException $e) {

    print "Error!: " . $e->getMessage() . "<br/>";

    die();

}

Open your browser and go to http://[YOUR_VM_EXTERNAL_IP]/my-sample-data.php to view the sample page with data from database.

If you encounter an error like “… driver not found”, restart your Apache server with the following command.

sudo systemctl restart apache2

What we accomplished in this tutorial

i) We set up a compute engine virtual machine (VM) on Google Cloud Platform (GCP);

ii) We installed a LAMP stack on the VM

iii) We populated the database with data and wrote a web page script to retrieve the data and display it on a web page which we accessed over the internet.

With the skills you learned in this blog and accompanying video you have skills to build on to build dynamic websites, develop backends for web and mobile applications, and pretty much anything you can build using the LAMP stack.

If you have comments or corrections about this blog post please write them in the comments section below and I will respond. Thank you.

References

  1. Setting Up LAMP on Compute Engine.
  2. How to Install LAMP Stack on Ubuntu 22.04
  3. How to sign up for your own GCP account.
  4. Caseray Cloud
  5. My (Ugochukwu Ukwuegbu’s) YouTube channel.

Benefits of building applications that are optimised for cost and value on GKE

The cloud offers modern technologies for compute, storage, databases, machine learning and artificial intelligence with which applications can be built that give businesses an edge in their operations. Like any state of the art technology there are associated costs that weigh on the minds of business executives making them wonder if the technological edge that the cloud promises can be justified by the benefits.

The labs in the quest, Optimize Costs for GKE, show tools and techniques to help optimise resource usage and eliminate unnecessary costs. The skills learned in this quest when combined with the skills learned in the quest, Secure Workloads in GKE, can be applied to build a WordPress application which is designed to be reliable, secure, highly scalable and highly available. What does this mean?

Well, if you plan to build a blog or website where you expect a few hundred visitors per day then the type of application I am describing here might sound a bit like over-engineering to you.

However, if you plan to use WooCommerce to build an eCommerce website or if you are a Linda Ikeji whose blog, lindaikejisblog.com, can expect to receive 10,000 users per minute one minute and then 100,000 users per minute ten minutes later then the technology described here is recommended to avoid poor user experience or even the web server crashing altogether when many people are visiting it at the same time. 

GKE can be used to build web applications that scale and are cost optimised. For example, a website can use two servers to handle 10,000 users per minute and if web traffic grows suddenly, GKE can be configured to automatically spin up additional servers to handle the increased traffic without impacting user experience. If on the other hand web traffic drops from 100,000 users per minute to 100 users per minute, GKE can automatically scale servers down from 10 to 2. 

This way the application only uses the resources it needs to serve users and the business only pays for the resource it needs to satisfy customers and meet business expectations.

Website Design Fundamentals with HTML, CSS, and JavaScript

Course: Website Design Fundamentals with HTML, CSS, and JavaScript

What you will learn:

  • You will learn how to set up a website development environment on your laptop or personal computer.
  • You will learn the basics of website design using HTML5, CSS and JavaScript.
  • You will learn how to build a functional website like (cubeconcepts.org) and host it.

Course Outline:

  • How to set up the website development environment on your laptop.
  • Overview of HTML5 and other Web technologies.
  • Fundamentals of HTML.
  • Organizing text in HTML.
  • Working with links and URLs.
  • Working with Images, Colours, and Canvas.
  • Overview of JavaScript.
  • JavaScript functions, events, image maps and animations.
  • JavaScript objects.
  • Overview of CSS.
  • Styling with CSS.

Lab: How cubeconcepts.org was built.

Duration: Six (6) weeks

Cost: N70,000

See more at: https://ugogineering.com/web-design-training

Give yourself the fundamental skills you need to kick-start a digital career

Do you know that with the right digital skill you can apply for jobs in Europe, America and Canada with an annual salary of $50,000 or more?

Do you want to be a blogger, a full-stack developer, a programmer or a digital marketer? You are in the right place. We have carefully thought out courses designed to give you the fundamental skills you need to kick-start your career in tech.

The training courses we have on offer are:
i) Website Design with HTML5, CSS and JavaScript;

ii) PHP Fundamentals;

iii) WordPress Fundamentals (How to blog with WordPress);

iv) Digital Marketing Fundamentals;

v) JavaScript Fundamentals; and

vi) Kotlin Fundamentals.


Our digital skills courses have both theoretical and practical components so that at the end of it you will be able to build tangible web projects as well as ace job interviews that require you to demonstrate your technical skills.

The best part of our programmes is that you can learn at your own pace and from your home as long as you have the facilities which are a laptop or personal computer, a mobile phone, and internet access. See details of the courses at https://ugogineering.com/training.

Feel free to send us a message and we will reply.
Cheers.

Sums of two integers in an array less than K

Problem

Given an array A of integers and integer K, return the maximum S such that there exist i < j with A[i] + A[j] = S and S < K.
If no i, j exist satisfying this equation, return -1

Test array A = [34, 23, 1, 24, 75, 33, 54, 8], K = 60.

Solution

The solution to the problem is shown in Figures 1, 2 and 3 on this page. The code is written in PHP. Figures 1 – 2 show the code. Figure 3 shows the output.

Figure 1. Problem code page 1
Figure 2. Problem code page 2
Figure 3. Problem code output

Feel free to leave your comments below. I will respond. Thank you.

NB: The full code to the problem can be seen on Github at: https://github.com/ugogineering/PHP-codes/blob/main/two-sums-less-than-k.php

Sum of even Fibonacci numbers less than x

This is a Coding problem from ProjectEuler.net

Problem 2. Even Fibonacci numbers.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Solution

The solution to the problem is shown in Figures 1, 2 and 3 on this page. The code is written in PHP. Figures 1 – 3 show the code. Figure 4 shows the output.

Figure 1: Sum of even Fibonacci numbers. Page 1 of code
Figure 2: Sum of even Fibonacci numbers. Page 2 of code
Figure 3: Sum of even Fibonacci numbers. Page 3 of code
Figure 3: Output to Sum of even Fibonacci numbers

Feel free to leave your comments below. I will respond. Thank you.

NB: The full code to the problem can be seen on Github at: https://github.com/ugogineering/sum-of-even-fibonacci-nos-less-than-x/blob/main/sum_of_fibonacci_nos_less_than_x.php

How we plan to grow our business ten times in 2021 through digital business transformation

The first half of 2020 forced business leaders to rethink their approach to delivering services and products to their customers. The impact of Covid-19 and the shelter in place measures to contain the spread of the disease made clear the need to build capabilities for remote work and prepare businesses for the future. Leading companies in the world are adopting cloud technologies to modernize their businesses and the signs can be seen from the 25% – 100% growth in the revenues of cloud technology providers like Google Cloud Platform (GCP), Amazon Web Services (AWS) and Microsoft. 

I will not go into technical details of cloud technologies in this article. Instead, I will cite simple examples of how companies or organisations around the world and in Nigeria are adopting the cloud to transform their businesses. I will also give reasons why there is opportunity for the companies that adopt cloud technologies efficiently to grow ten times in 2021.

Education

In the years leading to 2020 technology (tech) companies in America had been advocating to leading American schools the need to digitize classes and the learning experience. In that time the schools always found reasons to show that classroom teaching would always be superior to any remote learning experience and that adopting online classes would be painful and could take 2 – 3 years to adopt fully. However, when the lockdowns of Covid-19 were imposed and the schools faced the prospect of losing academic sessions to the pandemic, the leading American schools quickly transitioned to online classes in 2 – 3 months!

In Nigeria, in December 2020, public universities have been closed since March first because of Covid-19 restrictions and then because of strike action by its leading academic staff union. On the other hand, private universities and education service providers are open and some have adopted novel ways to continue delivering their services. Prior to 2020, LagTutor.com offered home tutoring services to prepare candidates  for university entrance examinations. In early 2020, they put a stop to physical home tutoring and now offer their tutoring services exclusively online using tools like Zoom, WhatsApp, mobile apps and their website. The dysfunctions in public educational institutions in Nigeria have made people look elsewhere for learning opportunities. If you look online you will find that forward thinking institutions in Nigeria and abroad are cashing in on this by offering online courses that can be delivered on the laptops and mobile phones of their customers at their pace of learning.

Small Business

Whenever there is talk about digital business transformation the first examples that come to mind of companies that can be transformed are the big enterprise scale companies, the financial institutions and the telecommunications giants. The good thing about cloud technologies is that any size business can use them. In practice, cloud technologies provide small tech savvy companies the opportunity to punch above their weight because bigger, better financed companies are typically slow to change methods that are working for them.

In 2020, I have seen among the businesses I offer digital services to, an increase in online enquiries about their services and orders for goods. For example, Rolabik.com, a company that offers security fencing products and services saw a dramatic increase in online orders for their products. This happened during the lockdown when in reaction to the insecurity fears that accompanied it people went online to look for ways to beef up the protection of their properties.

Divine Fish Farm and Gardens is another business that benefited in 2020 from the changing attitude of Nigerians to search online first for food and garden products. During the lockdown they received orders online and delivered farm products to customers at their doorsteps.

Many of the businesses we offer digital solutions to don’t really care about the technical details of cloud technologies. They are just fine that we are using the tools to enhance their businesses. It is enough for them that we interface with the leading cloud technology providers like GCP and AWS and provide them the services they need to accelerate their growth.

In November 2020, we conducted search engine marketing for one of our customers. In a ten-day campaign for one product category we ran advertisements (ads) for $150. The ad campaign increased traffic to the business’ website by twenty times. Using tools like Google Analytics we were able to generate a report on the ad campaign that gave insight into what their potential customers were searching for, where they were searching from, what devices they were searching with and what they were willing to pay for the product. With the kind of information that artificial intelligence (AI) tools like Google Analytics can give a business, managers can make informed decisions that can accelerate growth.

Nigerian traditional financial institutions have often cited regulatory restrictions as reasons why they cannot fully adopt cloud technologies quickly enough for computing, storage, networking and AI needs. However, the events of 2020, including the October #EndSARS protests and related developments, have caused panic among banking executives as they scramble to adopt the superior benefits of the cloud. But they have to be careful to develop well thought-out cloud adoption strategies for their short term and long term needs. The Nigerian financial industry is a place where you will find some players who are doing relatively well because of a track record of willingness to adopt technology quickly enough to solve customer needs and other players who are struggling because complacency and the burdens of tradition make them slow to meet the needs of the times.

History is replete with examples of how the latest technologies influence the outcome of important events. The companies doing well in 2020 despite the challenges that came during the year did not begin preparations in January 2020. In fact, they were ready for the impact of the lockdown before it came. If forward looking companies keep doing the right things they will continue to grow in 2021 and win customers from other companies that are slow to change.

The cloud is not just an exploratory journey – it is the future of business. This is the reason I am confident that we can grow our business at Caseray Solutions ten times in 2021. Join us on the transformation journey. Send me a message at info@ugogineering.com and we can discuss how cloud technologies can help you grow your business.

Lessons Nigeria must learn from the Covid-19 Lockdown experience to improve economically, medically and scientifically

I think that the lockdown during the Covid-19 pandemic was an essential measure in spite of the hardship it brought economically. However, the implementation and the duration of the lock down exposed many shortcomings in the way Nigeria runs as a society. There are lessons that can be learned from the experience that will not only help to improve Nigeria economically but also medically and scientifically.

First, the lock down was almost inevitable because the World Health Organisation recommended it as an effective measure to slow the spread of the coronavirus and many advanced countries like Britain, Germany, France and the United States of America had implemented it. Even China where the novel coronavirus was discovered implemented lockdown measures. The Federal Government shut down the Nigerian land borders, airports, schools and public places in March 2020 as a measure to fight the Covid-19 pandemic. However, the correct approach to tackle the pandemic should have been science based. If the Nigerian science and research community had been up and doing it would have observed one or two months after the lockdown that the coronavirus was not as lethal in African countries as it was in Europe and America. If I were in a position of authority I would have asked competent professionals in Nigeria’s science and medical community to advise the best way to tackle the pandemic from the outset. The Swedish government chose to go this way and did not lock down despite strong criticism from other European countries. Sweden’s Covid-19 response was led by Anders Tegnell, an epidemiologist, and today they appear to have the pandemic under control while other European countries are still struggling to contain Covid-19 spikes after eased lockdown.

Second, the Nigerian government’s efforts to ease the suffering of Nigerians during the lockdown by distributing palliatives were hijacked by politicians. Politicians took charge of distributing food items and cash to the poor. In practice these distributions were characterised by corruption as most of the palliatives did not get to the people who needed them the most. Furthermore, the security operatives who were charged with enforcing the lockdown ended up killing more people with their guns for disobeying the lockdown order than the coronavirus itself. During the lockdown many food items perished in the farms because the means of distributing them to people willing to buy them were restricted. As a result farmers suffered losses, market women lost economic opportunities and people suffered from hunger in their homes. If I were in authority I would have ensured that essential services like food and medical supplies delivery continued smoothly through the lockdown.

Third, the implementation of the fight against Covid-19 disease in hospitals and isolation centres was accompanied by dubious activities. There were accounts of healthcare workers falsely diagnosing ailments like malaria and cough as Covid-19 disease so as to reach set targets and claim money set aside to fight the disease. Worse still, many private healthcare centres rejected sick people they suspected of having Covid-19 disease. As a result, people lost confidence in the healthcare system and stayed at home when they were sick. People started seeing the Covid-19 related figures regularly released by the Nigeria Centre for Disease Control as fabricated numbers to justify huge budget claims from the government. 

Nigeria by the end of September 2020 had experienced six months of some degree of lockdown and I think it was sufficient time to learn enough about the Covid-19 disease. If I had the authority I would have lifted the lockdown in Nigeria completely by September.

I think the experience from the lock down offers Nigeria another opportunity to see how badly things turn out when we do not do things properly. We should not have blindly copied measures to fight the pandemic from foreign countries. The lockdown should not have gone on for too long and we should not have lost lives and economic opportunities needlessly. If we did things properly we would not misappropriate and mismanage scarce resources in the fight against the pandemic. If I had the authority I would insist that things be done properly everywhere in Nigeria because when people see that things are done right it will be less difficult to get the people to work together for a better country.

Caseray Solutions offers digital business transformation and marketing and advertising services from Lagos Nigeria

Digital transformation for businesses has been seen as essential in the past few years if businesses are to remain relevant in a fast evolving digital world. The experience in 2020 of the COVID-19 pandemic and the associated lockdowns has made it imperative for businesses to have the capacity to deliver services remotely and with minimal physical contact.

Many businesses are in different stages of their digital transformation journey. It has been said that it took Microsoft 4 – 5 years to complete their digital business transformation journey. Data and research predict that adoption of cloud technologies is essential to remain in business in the next five years.

However, beyond the elite global technology companies, cloud-first companies, multinationals and forward thinking companies there is little knowledge among many businesses and organisations on how to transform digitally to remain relevant. The goal of being digitally transformed is to have the capacity to work and deliver services remotely and securely, using the latest and most innovative computing technologies, while remaining cost effective. But how do companies get to this destination?

What is the first step to take in the journey to digital transformation?

In my opinion, the first step to successful digital business transformation is to have an effective presence on the internet. A Lagos based company helping businesses in Nigeria on their journey to digital transformation is Caseray Solutions Limited.

Caseray Solutions is a Lagos-based company that helps business grow through digital marketing and innovation. They provide businesses with the digital tools they need to be more productive.

You can see their websites at www.caseraysolutions.com and at: www.caseray.com.ng. They have active social media presence on:

The website of Caseray Solutions and their social media presence allow them to interact with different internet audiences around Nigeria. The feedback the company receives enables them to improve the quality of their services. Caseray Solutions Limited is a digital-first company.

In the coming few weeks I will give examples of cloud technologies and how businesses and organisations are adopting them in their journey to digital business transformation. If you have any questions feel free to leave them in the comments section below. You can also send me an email to info@ugogineering.com.

Cheers!