Google Cloud Compute Engine

LAMP Installation on Google Cloud – Ubuntu 18.04

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

LAMP Installation on Google Cloud – Ubuntu 18.04. A LAMP stack is a set of open-source software installed to host dynamic websites and web applications.

This guide demonstrates how to install and setup LAMP stack on Google Cloud Platform. Here we use Ubuntu 18.04 to install Apache and PHP 7.3.

We will not install MariaDB or MySQL in the same server, instead we will use Cloud SQL with Second Generation instance MySQL v5.7 for high performance.


1. Install Apache

The Apache web server is the widely used web server in the world. It is also well documented and makes a default choice for hosting a website.

Update the packages and install Apache using the following command.

sudo apt update
sudo apt install apache2

2. Configure Firewall

Now you can set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS

sudo ufw app list

You will see all listed applications.

Available applications:
Apache Full
Apache Secure
  • Apache: This profile opens port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
  • OpenSSH: This profile opens port 22 for SSH access.

If you are not going to use SSL you need to enable only the Apache profile.

Now we will enable Apache Full.

sudo ufw allow 'Apache Full'

With this command you can view the status of UFW.

sudo ufw status

You will see the output as follows.

Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

3. Check Apache Installation

Once Apache is installed is is started automatically and already be up and running.

Every process in Apache is managed with the systemctl command. Check the status of Apache with the following command.

sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
Active: active (running) since Tue 2019-01-29 03:59:34 UTC; 5min ago
Main PID: 10617 (apache2)
Tasks: 55 (limit: 667)
CGroup: /system.slice/apache2.service
├─10617 /usr/sbin/apache2 -k start
├─10619 /usr/sbin/apache2 -k start
└─10620 /usr/sbin/apache2 -k start
Jan 29 03:59:34 apache systemd[1]: Starting The Apache HTTP Server…
Jan 29 03:59:34 apache systemd[1]: Started The Apache HTTP Server.

Now visit your domain name in your favourite web browser, you will see the default Apache welcome page.

00de463e apache welcome page

Now Apache is installed and you can know more about Apache commands here.

4. Install PHP

You can install PHP 7.2 with the following command.

sudo apt install php7.2 libapache2-mod-php php7.2-common php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-curl php7.2-gd php7.2-imagick php7.2-cli php7.2-dev php7.2-imap php7.2-mbstring php7.2-opcache php7.2-soap php7.2-zip php7.2-redis php7.2-intl php7.2-bcmath unzip -y

If you want to use PHP 7.3 you can use this command.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php7.3 libapache2-mod-php php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-redis php7.3-intl php7.3-bcmath unzip -y

After the installation has completed, confirm that PHP 7.3 has installed correctly with this command

php -v

5. Configure PHP

Now we configure PHP for WordPress by changing some values in php.ini.

PHP 7.2
sudo nano /etc/php/7.2/apache2/php.ini 

PHP 7.3
sudo nano /etc/php/7.3/apache2/php.ini

Hit F6 for search inside the editor and update the following values

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Hit CTRL+X and Y to save the configuration and check if the configuration is correct and restart Apache

sudo service apache2 restart

6. Setup Cloud SQL

Now you can create a Second generation Cloud SQL Instance and connect with your Compute Engine VM Instance.

Learn to set up Cloud SQL in Google Cloud.

Now you have installed LAMP stack on Google Cloud with Ubuntu 18.04.


  1. You forgot about editing file with hosts and domain at sites-available

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.