How To Start Up With Ubuntu VPS to Run Website for Beginner


Setting up ubuntu VPS to run websites for the first time for beginner can be tricky since most of us started from shared hosting. first of all, lets start with the definition of VPS.

What is VPS

VPS or virtual private server or sometimes can also be called virtual dedicated server is a virtualization blocks on one physical dedicated computer. A single dedicated server can have multiple virtualization block, that is VPS. Each VPS resemble a dedicated server which has its own Operating system and fully functional like a real physical dedicated server. so basically, VPS is a dedicated server in shared environment. the technology of VPS is similar to VMware. a program that allow you to run several virtual machines inside host operating system.

What is the different between VPS and standard shared hosting

The two main different is Control and Resources. with VPS you can control not only some part of your hosting but you can control the whole operation system of your VPS. much more control  so you can set your server specifically to the need of your website. in term of control, usually there will be no restriction to do what you can do with your VPS. you can install any program you want just like what you can do with your personal computer.

Number two is resource, usually VPS providers will give you certain dedicated amount of resources like IPv4, RAM and Storage Space. some providers will give you dedicated CPU usage in which you can use 100% of your CPU capability.

Things to consider before buying VPS

First you will need to check the provider reputation, many of VPS providers have bad network, bad machine and bad uptime, and most of the time you won’t get what you paid for. So buy only VPS from provider with good reputation.

After you find a good provider, you will need to look at the VPS specifications that they offer. Below is the vps specification you will need to look before buying one.

VPS Resource:
  • CPU – how many CPU core, fair share or dedicated
  • Ram – Ram is memory used to run programs in VPS. for small website typically 128MB to 512MB ram is enough, but if you want to run some medium to hardcore application you will need 1GB Ram or more depending of what application you want to run.
  • Swap  – Swap is part of your harddisk that is being used like ram. When Ram is full, Swap will be used. But remember, swap I/O will be much slower compared to ram.
  • Port Speed – port speed is the transport speed of your VPS. there are 100MB/s, 1GB/s or 10GB/s connection speed. Off course, the bigger is better. remember, this is mostly shared in a VPS environment. so if the host machines of your VPS has multiple VPS on it, the port will be shared to all VPS it hosts.
  • Storage space – a dedicated space you can use to put your file on. there will be SSD and HDD. SSD is solid state disk wich has faster I/O speed than HDD. the faster the disk,  the faster your program and website loads. HDD is spinning hard disk which is slower than SSD but offers more space.
  • Bandwidth – the amount of data can be transferred to and from your VPS. this will be reset monthly so if you have 100GB bandwidth you will be allocated with 100GB transfer each month. if your website spend 100GB before one month you won’t be able to access your VPS or website and you have to wait until the next month when the bandwidth will reset. for small to medium website with not so high traffic 100GB should be enough.
  • Virtualization type – there are OpenVZ, Xen, KVM. OpenVz is OS container virtualization, it is the cheapest and linux only virtualization. Your VPS provider usually already have linux template in which you can install or reinstall your OS. Xen and KVM is full virtualization which mean you can install windows or any other operating system you want to install on your machine. I would recommend using linux as operating system since it is widely used for server and on top of that Linux is free.
  • Data Center locations it is the location where you VPS physically located.

Server Operating Sytem

In this tutorial we will be using ubuntu as the operating system. if you are following this tutorial and the VPS you brought doesn’t come up with ubuntu by default you need to reinstall the OS to Ubuntu on your VPS control panel provided by you provider. Any release of Ubuntu is fine, but the latest release is recommended. they should be all have the same command.

64bit vs 32bit Operating System

If your VPS has enough resources I recommended using 64 bit version of linux OS since it will give you better performance.

Pointing your domain to your VPS (optional)

After you get your first VPS the next thing to do is pointing your domain to your VPS IP. this can be done by creating  A record for your domain. on your domain management, select your domain and find something like manage DNS, then create record.

There will be record type field, name/domain filed and TTL

  • Choose record type to A record.
  • On the name or domain filed leave it blank if you want to point your naked domain to your VPS. you can also fill it with www for or fill it with wildcard character * for pointing all your domain and sub domain to your VPS.
  • TTL is time to live the time where when the domain propagation should take effect. fill it with low value at first like 800 so you will see the your domain pointing to your VPS much faster. remember to set it high again later when you are done.
  • click save.

This step is optional. You don’t have to own a domain in order for your server to be able to run website. You can simply use your server ip address to replace the domain name. But if you want to run website with domain name on your ubuntu server, you may want to know how to point your domain to your vps server.

Connect to VPS via command line using putty

When you buy a VPS you should be given SSH login detail and how you can access your VPS via command line by your provider.

To connect to your VPS via SSH download putty here. Enter your vps’s IP address and ssh port. Port 22 is the default port for ssh, Click open.

putty login

Now you can login using the detail given by your provider

Setting Up Ubuntu VPS

After pointing you domain to your VPS, your server will not recognize the domain right away. we need to set up your server so it can recognize your domain and serve website specifically for it.

We will start configuring your server by installing necessary files and applications. there are three main application you need to install for your server to run websites, web server application, php processor and database server. In this tutorial wee will be using nginx as web server, php7.0-fpm as php processor and mariaDB as the database server.

Installing nginx

We will need root access to install nginx. If you are not logged in as root you need to add sudo before every command.

Update nginx repository

sudo apt-get update

Update your OS software to the latest version

sudo apt-get upgrade

After that, make sure apache is not installed so there will be no conflict with nginx

sudo service apache2 stop
sudo apt-get remove --purge apache*

Now we can start installing nginx

sudo apt-get install nginx

You will be asked to continue the installation process. press Y and hit enter.

After the installation process completed, you can test your web server by accessing your VPS’s ip in your web browser.


Installing php7.0- fpm

Before we can install php7, we need to add Ondřej’s PPA to the system’s Apt sources.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-key adv --keyserver --recv-key 4F4EA0AAE5267A6C

Update ubuntu repository

sudo apt-get update

Now, install php7.0-fpm , php7.0-mysql and php7.0-xml

sudo apt-get install php7.0-fpm php7.0-mysql php7.0-xml
Configure nginx to use php7.0-fpm

By default nginx can only serve static content, we need to tell nginx to pass the php request to php7.0-fpm. We can do that by configuring nginx’s server blocks.

sudo nano /etc/nginx/sites-available/default

If nano is not installed, you can install it by typing

sudo apt-get install nano

When you open /etc/nginx/sites-available/default with nano, there will be many lines commented. here is how it will look like without commented lines.

server {
 listen 80 default_server;
 listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
 index index.html index.htm;

server_name localhost;

location / {
 try_files $uri $uri/ =404;


  • listen 80 default_server; -> tell nginx to listen at port 80 (http request)
  • root /usr/share/nginx/html; -> is the location of your web files, put your website to the directory specified on this line
  • server_name localhost; -> change localhost to your domain name so if your domain already pointed to your VPS’s ip, nginx will serve any request coming from this domain with web files located on root /usr/share/nginx/html;
  • index index.html index.htm; -> index directive. In order for nginx to allow php index files to be served as php when a directory is requested, we need to add index.php here.

We also need to comment out and add some lines for nginx to be able to actually serve php.

The configuration will look like this:

server {
 listen 80 default_server;
 listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
 index index.php index.html index.htm;


location / {
 try_files $uri $uri/ =404;

error_page 404 /404.html;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root /usr/share/nginx/html;

location ~ .php$ {
 try_files $uri =404;
 fastcgi_split_path_info ^(.+.php)(/.+)$;
 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;

Reload nginx to apply changes

sudo service nginx restart
Install MariaDB for database server

We already have web server and php processor, now we need to install database server for your vps. Inthis tutorial we are going to use mariaDB. In case you don’t know, mariaDB is an upgrade of mySQL, designed to be a drop-in replacement for mysql database.

To install mariaDB server type the following command on your SSH command line:

sudo apt-get install mariadb-server

You will be asked mariaDB password twice, enter your password and complete the installation.

Securing mariaDB installation

After installation completed, secure mariaDB installation by typing the following command:

sudo mysql_secure_installation

You will be asked these questions:

Enter current password for root (enter for none): <-- press enter
 Set root password? [Y/n] <-- y //press N if you already set mariadb's password
 New password: <-- Enter the new MariaDB root password here
 Re-enter new password: <-- Repeat the password
 Remove anonymous users? [Y/n] <-- y
 Disallow root login remotely? [Y/n] <-- y
 Reload privilege tables now? [Y/n] <-- y

Congratulation! Your VPS is now complete and able to serve dynamic website with database

We will learn how to make database on ubuntu command line in the next section

If you have any question do not hesitate to ask me on the comment bellow ^^