In this tutorial, we are going to see, how to install LAMP Stack on your Compute Engine of Google Cloud Platform. after all, settings done of Compute Engine, we are going to install Ubuntu/Linux whichever you like to install for your Compute Engine.

What is LAMP Stack?

LAMP stack is a group of open source technologies/ software, which will help you to build and run your web server to host dynamic website or web apps. Lamp is an acronym of Linux is Operating System, Apache is your web server, MySql is your data storage, Php is the language using this, you can develop the dynamic site.

In this article, we are going to setup LAMP stack in Compute Engine of Google cloud platform. Of course, this tutorial will help you to install Lamp stack on AWS EC, Digital Ocean droplet, etc …

Step 1: Install Apache Server

Since we are using a sudo command, these operations get executed with root privileges. It will ask you for your regular user’s password to verify your intentions.

Depending on your os install command will change a little bit
Some Linux os use apt-get install, some other use yum install

sudo apt-get update && sudo apt-get upgrade

Install Apache server

sudo apt-get install apache2

Your web server is now installed. you can verify our server running to check whether it’s working or not by typing public IP/ domain name (if you have setup) on your browser. also you can test web server using below command,

sudo apache2ctl configtest

Now we are going to change apache2.conf file,  open that file using either vim or nano editor.

sudo nano /etc/apache2/apache2.conf

Add/Edit below line

ServerName 'server_domain_or_IP'
Setting up firewall

Adjust the firewall to allow web traffic. first check for utf is installed or not, if not then install it by:

sudo apt-get install utf
sudo utf app list

This will list available application for firewall. Since we install apache, we have apache on the list .

Available application:
        Apache
        Apache Full
        Apache Secure
        OpenSSH

you can see info of available application by below command:

sudo utf app info "Apache fill"

Output:

Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web
server.

Ports:
80,443/tcp

We can allow or deny traffic for your web server by allow or deny option

Sudo utf allow in "Apache Full"

You can test web server by typing your public IP/ URL into the browser

An alternative method is to use the curl utility to contact an outside party to tell you how it sees your server. You can do this by asking a specific server what your IP address is:

sudo apt-get install curl

curl https://devnetwork.io

Step 2: Install PHP

PHP is the language which will help you to build a dynamic website. It can connect to the MySql database to get/store information.

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

This will install PHP without any error.

in most cases, we’ll want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell our web server to prefer PHP files, so we’ll make Apache look for an index.php file first. You can specify your file name but generally in the most case developer use index.
To do this, type this command to open the dir.conf file in a text editor with root privileges. To edit the file, you must have install nano otherwise you can do by vim editor which built-in editor

sudo nano /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

In the second line, you can see the list of file which priority set from left to right. So we are going to set index.php high priority.

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

To restart apache server:

sudo systemctl restart apache2

We can also check the status of the apache2 service using systemctl:

sudo systemctl status apache2
Install PHP Module

To enhance the further functionality of PHP, we can optionally install the additional package

apt-cache search php- | less

It’ll list you php module. To get information of packages.

apt-cache show package_name

We’ll install php-cli for use php via terminal.

sudo apt-get install php-cli

directory is located at /var/www/html/, where your php code is store
Test your php install successfully or not we’ll make one file info.php in /var/www/html/info.php

sudo nano /var/www/html/info.php

After saving this file you can test your file by public IP

http://PUBLIC_IP/info.php

After the successful test, you can remove by rm command

sudo rm /var/www/html/info.php

Step 3: Install MySql

Now our web server and PHP is running, we next install MySql for data storage.

sudo apt-get install mysql-server

During the installation, your server will ask you to select and confirm a password for the MySQL “root” user. This is an administrative account in MySQL that has increased privileges. Think of it as being similar to the root account for the server itself (the one you are configuring now is a MySQL-specific account, however). Make sure this is a strong, unique password, and do not leave it blank.
When the installation is complete, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:

mysql_secure_installation

You will be asked to enter the password you set for the MySQL root account. Next, you will be asked if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer y for yes, or anything else to continue without enabling.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

You’ll be asked to select a level of password validation. Keep in mind that if you enter 2, for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters,, and special characters, or which is based on common dictionary words.

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

If you enabled password validation, you’ll be shown a password strength for the existing root password, and asked you if you want to change that password. If you are happy with your current password, enter n for “no” at the prompt:

Using an existing password for root.

Estimated strength of the password: 100
Change the password for root? ((Press y|Y for Yes, any other key for No) : n

For the rest of the questions, you should press Y and hit the Enter key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.
At this point, your database system is now set up and we can move on.

Conclusion

We installed basic requirement for web server run on EC/ compute engine/droplet. Next is we want to secure our web server, install PHPMyAdmin, FTP Access …

Leave a Reply

Please Login to comment
  Subscribe  
Notify of

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.