Setting up Lamp on Digital Ocean in 5 Minutes

Hiren Kavad
Coding Monk
Published in
5 min readDec 3, 2018

Lamp stack and phpmyadmin on digital ocean

What is LAMP ?

The Word “LAMP” is just a bunch of words. When you want to create server environment for dynamic website we need to install some software when you are choosing PHP as programming language.

L in “LAMP” stands for operating system which is Linux Operating System, A for Apache webserver, it’s a most commonly used host server to serve PHP files.

M for Mysql. It is also most commonly used and most popular database among PHPdevelopers used to store data.

P for PHP. A Programming language to dynamically process data and business logic.

What we need ?

We are going to install LAMP stack on latest ubuntu (we will be using 18.04) on digital ocean server, you can choose any VPS provider.

1. Install Apache

Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation, Apache is an open source software available for free. It runs on 67% of all webservers in the world. It is fast, reliable, and secure.

If you are on local machine then gain root user rights by doing sudo, and then perform following commands.

sudo apt-get update
sudo apt-get install apache2

Now type your IP in your browser and you will see apache default page.

Apache server default page

Hurreeeeyyyy Apache is installed.

2. MySql

We have apache server ready, it’s time to install one of the most used database management service “ MySql”. We can easily organize our data into mysql server. so let’s get started

Perform following command on your Digital Ocean VPS

sudo apt install mysql-server

Above command will install MySql on your machine, this instance of MySql comes with default credentials. So we need to make it more secure. type below command to make it secure.

sudo mysql_secure_installation

It will prompt you for VALIDATE PASSWORD PLUGIN choose whatever you like

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:

Choose Password Strength Rules.

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

After these you will prompt to enter password. Enter your MySql root password.

Again it will prompt you few times; about deleting test database and password strength. Make your choice.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment. Press y|Y for Yes, any other key for No:

And you are ready to go.

Type mysql and login to mysql CLI and change root password with following commands

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword@123'; mysql > FLUSH PRIVILEGES; mysql > exit;

Mysql is ready to serve you.

3. PHP

We have setup apache server and mysql database. No we need programming language in which you are going to code. PHP is one of the best, easy, simple and most used language world wide.

We will be installing PHP’s Latest version PHP 7.2 on ubuntu 18.04.

First of all update ubuntu with following commands

apt-get update && apt-get upgrade

Install PHP with following command

apt-get install php

Check version with

php -v PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Now Let’s install some PHP 7.2 Modules with following commands

apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

And it’s done. you can check php configuration by creating index.php (or any holy name you want haha) file on /var/www/ folder and writing following function in php file.

go to below address and check your php configuration

http://YourIP/index.php

You have installed PHP successfully on your VPS. Now thing left is just Phpmyadmin.

How to Install phpmyadmin on Digital ocean VPS

We learned how to install LAMP Stack. We will learn one more important tool which is database management tool or UI. There are many software available to manage mysql database. phpmyadmin is most commonly used and most popular system to manage mysql database with php. so let’s install it.

It’s super easy, type following command.

sudo apt install phpmyadmin

It will ask you to choose webserver : Select apache2

Configure database for phpmyadmin

Again it will ask for mysql root password. Enter it and pufff. You have installed phpmyadmin.

Restart Apache through following command

sudo systemctl restart apache2

To access phpmyadmin on your IP Address we need to make some changes. perform following commands

sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl restart apache2

Go to

https://YourIP/phpmyadmin

You are ready to develop awesome application with php 7.2 , mysql, apache and phpmyadmin.

All the best.

Comment below if you have any query or questions.

Originally published at https://medium.com on December 3, 2018.

--

--