Install Apache Server and PHP on Google Cloud Platform.

This guide shows you how to set up Apache and PHP on a Compute Engine virtual machine instance on GCP. The instructions are for Ubuntu 20.04 Linux distribution (goes with PHP 7.4 in its default repositories).

Creating a virtual machine instance

Go to your Google Cloud Console and click
Compute Engine > VM Instances > Create
Create a name for your instance
Region — us-central1(Iowa)
Zone — us-central1-c

[Update] Google introduced E2-micro Free Tier, which is a part of a second-generation VM family on August 1, 2021
Series - E2
Machine type - e2-micro (2 vCPU, 1 GB memory)

Boot disc - Standard persistent disk, Image Ubuntu, 20.04 LTS (LTS — Long Term Support)

Firewall - checkmark
Allow HTTP traffic
Allow HTTPS traffic

Click Create.
It takes a few seconds to create the instance.

Installing Apache and PHP on the instance

On your instance click SSH to open the SSH window
In the opened window update packages that need upgrading typing

sudo apt-get update
sudo apt upgrade -y && sudo reboot

Now, install Apache

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

and install PHP and the extensions with the apt package manager

sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

Verify PHP Version

php --version

In Google Cloud console on your instance copy external IP and type it in a browser to verify that Apache is running:

Do not use https:// in the URL as the encrypted connection is not configured at this moment and the page won’t open

Alternatively, you can install a LAMP (Linux, Apache, MySQL, PHP) stack by Google Click to Deploy automatically.

Upload files on the server.

If you don’t have a connection to your instance check this guide on how to connect to Google Cloud VM Instance.

Map your domain name to your instance.

Reserving a static external IP address

In the Cloud Console click
VPC Network > External IP addresses
In the column Type of your instance select Static

Pointing your domain at your web server IP

Create an A record in your DNS Management console and copy/paste your external IP address.

Create a CNAME record for WWW subdomain and point it to your naked domain.

It usually takes effect within a few next hours.

Install SSL certificate for your website.

Read this article to install auto-renewing Let’s Encrypt SSL Certificate using automated client Certbot.

--

--

--

Lead Web Developer at Vue Health. Husband of a wonderful wife, Entrepreneur, Dad

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to make a fast application cache with specific conditions for huge Web API calls on .NET

A few notes on delivery at scale in technology companies

MongoDB: A Beginner’s Guide

How to pull request to git dummies

Paper Review:“System R: Relational Approach to Database Management”

Moving AWS Resources Between CloudFormation Stacks

Cloud Formation events showing Import In Progress and then Import Complete

Discord Tweak for Invisible Typing

Removing the Windows XP End of Life Message

12

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Max Shestov

Max Shestov

Lead Web Developer at Vue Health. Husband of a wonderful wife, Entrepreneur, Dad

More from Medium

JWT Keys and RingCentral API Connections

Node With AWS DocumentDB using Mongoose

CONFIGURE NODE + MONGO + AWS + DOMAIN | HOST API SERVER!

Access Personal Gmail from Cloud Functions using OAuth2