Hosting Website on DigitalOcean

Manish Chauhan
7 min readMar 14, 2022

When we see a beautiful website whether its a simple blogging site, an e-commerce website or a website that uses complex algorithms, our curiosity kicks in and we say to ourself “ i want to make a similar website like this but if i go to hostinger, Godaddy etc for their servers, i will not be in a full control and somehow i will mitigate my learning at the backend but what if i want to be in full control, like what if i host a website on VPS(virtual private server).I will handle my database and do so many things, I don’t have to be reliable on limited resources of hosting servers. But wait, who will provide me a VPS ??

There are many players in the market who provides you a VPS but in this blog, let’s talk about digital ocean and we will learn all the necessary things that a naive person should know to host a website that uses flask framework of python in the backend.

Step 1: Creation of droplet on digital ocean

i) Create an Account on DigitalOcean.

Login Page

ii) Creation of a Project(Choose any name like I chose my name for the project)

iii)Creation of a droplet.

iii) Choose Machine, Pricing, Region, Password ,set a name for your droplet and submit(As a beginner I will recommend you to choose the highlighted)

iv) After submitting it will take 3–5 mins for setting up and you will see you IP Address as below that you will need to login to the server.

Step2: Login to the Server and Perform Other activities

i) Download Putty for establishing connection with the server

ii) After Installing, just open the tool and enter IPv4 Address in the host field

iii) Enter “root” in Login as field and enter your password which you used to create the droplet

iv) Now as we have logged in as root user, we have all the privileges to perform any action on the server. that is why we will create another user which have limiting privileges and require extra permission for some important tasks.

For creating another user we will use : adduser <username> and then we will choose any password of our choice because next time when we login as <username> we will use that password.(Just Enter your password and leave other fields)

Also we will make our new user as a sudo user so that it will have root privileges when we use word “sudo” with any command(We will see that i our blog later)

Now we will take care of the firewall settings, we will first check what are the app list that we need to enable that can access our system. As we can see first we will allow “OpenSSH” for our system such that we can establish a connection on our system with our newly create user and firewall won’t block it.

Now we will logout and login again with our newly created user ‘manish’

v) Generally with our new user “manish” we can go to any path, transfer files but for removing and editing files we need extra permission, that is why we will use “sudo” such that our user “manish” acts as a root user but when we want to go completely as a root user which we will see later why, we will use “sudo su” to do that

Step3 :Installing LAMP(Linux,Apache, MySQL and PHP)

i)The Apache web server is among the most popular web servers in the world. It’s well documented, has an active community of users, and has been in wide use for much of the history of the web, which makes it a great choice for hosting a website.

Start by updating the package manager cache

Then, install Apache with:

Once the installation is finished, you’ll need to adjust your firewall settings to allow HTTP traffic. UFW has different application profiles that you can leverage for accomplishing that. To list all currently available UFW application profiles, you can run:

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser

ii) Installing MySQL on our VPS

When you’re finished, test if you’re able to log in to the MySQL console by typing:

Now we can clearly see that we logged in without a password by just typing the command, now we will set a password for root as well as “manish” so that every time we login to the db server, It will ask us the password.

We can see there is no authentication_string for our root user.Now we will set password for our “root” by the query:

To exit the MySQL console, type:

Now if we try to login again as a root user we will use our newly created password in the mysql db.

Now we will create our user “manish” as well such that we can login through manish directly as well.

Now we will login to the mysql directly without using sudo as we have created our user in the table

iii) Installing PHP

You have Apache installed to serve your content and MySQL installed to store and manage your data. PHP is the component of our setup that will process code to display dynamic content to the final user. In addition to the php package, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You’ll also need libapache2-mod-php to enable Apache to handle PHP files.

After installation edit dir.conf and bring index.php file before index.html

Type “I” for insert command to appear and edit as per the below image and save by pressing(Esc+wq:!).If you did any mistakes just type →Esc+q:!

After that we can restart our server(Everytime we do change in any file and for the effect to take place).

Now we will go to the path where all our websites lies and create index.php file and add the line shown in the image.

Installing phpmyAdmin that gives user interface for MySQL that helps to manage our DB.

$ sudo apt install phpmyadmin php-mbstring

Press Space to select apache2
Type your password here(Use the same password that you used for “manish”)

Now open phpmyAdmin in your browser

So this is the basic steps that we have performed to do the initial setup but what we wish to host a flask website on our VPS, for that we will meet in the next blog.

--

--

Manish Chauhan

Data Engineer | Machine Learning | Generative AI | Snowflake | AWS | Azure| GCP