<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sonia</title>
    <description>The latest articles on Forem by Sonia (@soniagm).</description>
    <link>https://forem.com/soniagm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F357699%2F2f4355bf-15cd-44b4-aa87-7b66f75fad40.png</url>
      <title>Forem: Sonia</title>
      <link>https://forem.com/soniagm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/soniagm"/>
    <language>en</language>
    <item>
      <title>How to Sep Up Your VPS for Web Hosting with the LAMP Stack Step By Step</title>
      <dc:creator>Sonia</dc:creator>
      <pubDate>Sat, 05 Dec 2020 22:24:54 +0000</pubDate>
      <link>https://forem.com/soniagm/how-to-sep-up-your-vps-for-web-hosting-with-the-lamp-stack-step-by-step-3hf3</link>
      <guid>https://forem.com/soniagm/how-to-sep-up-your-vps-for-web-hosting-with-the-lamp-stack-step-by-step-3hf3</guid>
      <description>&lt;p&gt;Server administration is an important skill to have as a web developer, but it is still many times overlooked. Today we'll learn how to install the LAMP (Linux, Apache, MySQL, and PHP) stack on a VPS and let it ready to host our website.&lt;/p&gt;

&lt;p&gt;Working with servers is mainly done using the console, what might look a little intimidating when you are not used to it, but don't worry, I'll help you to get comfortable with it by guiding you step by step through the whole process.&lt;/p&gt;

&lt;p&gt;This is what we are going to learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Steps. Getting a VPS and connecting to it&lt;/li&gt;
&lt;li&gt;Managing Users in Our VPS&lt;/li&gt;
&lt;li&gt;Installing the LAMP stack in our VPS&lt;/li&gt;
&lt;li&gt;Let's Set Up a Firewall in Our VPS&lt;/li&gt;
&lt;li&gt;Setting up your Domain&lt;/li&gt;
&lt;li&gt;Let's add a FTP Server&lt;/li&gt;
&lt;li&gt;Adding a SSL certificate to our VPS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;: Being familiar with Linux can be helpful but it's not a requirement.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  First Steps. Getting a VPS and connecting to it
&lt;/h2&gt;

&lt;p&gt;There are plenty of VPS providers. Most of the hosting companies offer VPS plans in additions to their shared hosting, and there are also cloud providers, such us AWS or Digital Ocean. In this guide, I would go with Digital Ocean, but the installation and setup of the VPS will be the same for all VPS, regardless of the provider.&lt;/p&gt;

&lt;p&gt;With Digital Ocean, a basic VPS cost $5/month at the time of writing this tutorial. If you want to try it, &lt;a href="https://m.do.co/c/d17d65ffd897"&gt; here &lt;/a&gt; is a link with a 100$ credit so you can test it without spending any money. &lt;/p&gt;

&lt;h3&gt;
  
  
  Let's create our VPS
&lt;/h3&gt;

&lt;p&gt;The very first step is going to &lt;a href="https://m.do.co/c/d17d65ffd897"&gt; DigitalOcean &lt;/a&gt;, opening an account, and creating a droplet —this is how they call a VPS— by clicking on any of the buttons shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m2xVqZVT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/01_create_a_doplet_in_digital_ocean.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m2xVqZVT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/01_create_a_doplet_in_digital_ocean.png" class="img-fluid" width="70%" height="auto" alt="install lamp stack in digital ocean"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the OS to install (I'm going with Ubuntu), a plan ('Basic' should be enough), and the virtual machine, this is the physical resources of your server (the most basic one, which cost $5/month, should be enough).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--thJuVTGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/02_setting_a_ubuntu_vps_on_digital_ocean.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--thJuVTGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/02_setting_a_ubuntu_vps_on_digital_ocean.png" class="img-fluid" width="70%" height="auto" alt="ubuntu vps in digital ocean"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm going with a minimal server here, so, I'm not going to choose any additional feature. Select the data center region (one close to where you are).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fjjVZlhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/03_server_region.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fjjVZlhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/03_server_region.png" class="img-fluid" width="70%" height="auto" alt="region"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last thing you want to set is the authentication method (how do you access to your VPS) I prefer to use a SSH key for a more secure authentication, but you can choose to authenticate with a password if you prefer so.&lt;/p&gt;

&lt;p&gt;If you are not familiar with SSH keys, let me explain you what they are.&lt;/p&gt;

&lt;p&gt;Secure Shell (or SSH) is a cryptographic network protocol that allows to connect with a remote server in a more secure way than logging with a password. Basically because a password can eventually be cracked with a brute force attack, but not SSH keys.&lt;/p&gt;

&lt;p&gt;When you click on the SSH key option in Digital Ocean you will be prompted to enter one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5fT93aN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/04_setting_a_ssh_key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5fT93aN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/04_setting_a_ssh_key.png" class="img-fluid" width="70%" height="auto" alt="vps-ssh-key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might already have one in your computer. Let's check it:&lt;/p&gt;

&lt;p&gt;If you are on Windows, open the terminal and go to the &lt;em&gt;/Users/USERNAME/.ssh&lt;/em&gt; dir (This is the default place to store ssh keys). Type &lt;code&gt;dir&lt;/code&gt; to see the contents of the directory. If you have a file called &lt;em&gt;id_rsa.pub&lt;/em&gt;, it is your ssh key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lCYOAX2U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/05_check-if-you-have-an-ssh-key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lCYOAX2U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/05_check-if-you-have-an-ssh-key.png" class="img-fluid" width="70%" height="auto" alt="check-if-you-have-an-ssh-key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are on Mac, the directory where you have to check is &lt;code&gt;cd ~/.ssh&lt;/code&gt;. And type &lt;code&gt;ls&lt;/code&gt; instead of &lt;code&gt;dir&lt;/code&gt; to inspect its content.&lt;/p&gt;

&lt;p&gt;If you have a key, type &lt;code&gt;cat id_rsa.pub&lt;/code&gt; to see it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9jLz19Lw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/06.inspect-ssh-key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9jLz19Lw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/06.inspect-ssh-key.png" class="img-fluid" width="70%" height="auto" alt="inspect-ssh-key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy it and paste it in the Digital Ocean input field. Give it a name of your choice to identify it.&lt;/p&gt;

&lt;p&gt;One note here: If you plan to connect with PuTTY, you need to add the .ppk key instead of the -pub one. If you don't even know what PuTTY is, ignore this paragraph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-oakj5O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/07.add-ssh-key-to-droplet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-oakj5O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/07.add-ssh-key-to-droplet.png" class="img-fluid" width="70%" height="auto" alt="add-ssh-key-to-droplet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you don't have any ssh key, run &lt;code&gt;ssh-keygen&lt;/code&gt; to generate one. Leave the file name blank and just press return. The key will be generated and stored in the &lt;em&gt;.ssh&lt;/em&gt; dir&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8cdusvDf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/08.generate-ssh-key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8cdusvDf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/08.generate-ssh-key.png" class="img-fluid" width="70%" height="auto" alt="generate-ssh-key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, add a name for your droplet, and tags if you want to (I'm just adding a name), and click &lt;em&gt;create&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You can also add the backups functionality, which is something you might want to consider for your production sites. Here, as this is just a test droplet for this article, I'm not adding it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mYAVanOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/09.create-droplet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mYAVanOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/09.create-droplet.png" class="img-fluid" width="70%" height="auto" alt="create-droplet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we are doing here is just creating the VPS with its Operative System (The Ubuntu distribution of Linux in our case). Next we'll learn how to manage it and install everything we need to be able to host our website.&lt;/p&gt;

&lt;p&gt;Now Digital Ocean will set up your server, what can take a couple of minutes or less (you will see a progress bar).&lt;/p&gt;

&lt;p&gt;Once the server has been provisioned, it will show the server IP address and a menu with many options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pjWSsDhn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/10.install-lamp-in-ubuntu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pjWSsDhn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/10.install-lamp-in-ubuntu.png" class="img-fluid" width="70%" height="auto" alt="install lamp in ubuntu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you selected the password authentication method, you need to receive the root password for the droplet you have created. You will get it emailed to your account in a couple of minutes. If you set the ssh authentication method, you don't need a root password.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connecting to our VPS
&lt;/h3&gt;

&lt;p&gt;The root password or the ssh key is what we use to authenticate ourselves when trying to connect to our VPS from our computer, but we need a way to connect to the remote server.&lt;/p&gt;

&lt;p&gt;You can use the Terminal if your are on Mac. However, if you are on Windows, you cannot use the command prompt. Instead you can use an enhanced terminal like &lt;a href="https://gitforwindows.org/"&gt; GitBash &lt;/a&gt; or &lt;a href="https://cmder.net/"&gt; Cmdr &lt;/a&gt;(I'll use this one), or a special tool to connect to remote computers such as &lt;a href="https://www.putty.org/"&gt; PuTTY&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To connect using GitBash or Cmdr using SSH, enter the following command:&lt;code&gt;ssh root@YOUR-DROPLET-IP&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will find the IP next to your droplet name if you go to 'droplets' in your Digital Ocean account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oFdfNzxA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/11.setting-up-vps.png.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oFdfNzxA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/11.setting-up-vps.png.png" class="img-fluid" width="70%" height="auto" alt="setting upa vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will prompt you for the password you created when creating the ssh key (if you did so).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJFiQlfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/12_connect_to_vps_ssh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJFiQlfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/12_connect_to_vps_ssh.png" class="img-fluid" width="70%" height="auto" alt="connect to vps ssh"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you don't use SSH but a password to authenticate, the first time you log in to your VPS, you will be probably asked to change the password.&lt;/p&gt;

&lt;p&gt;Now we are in our remote server. &lt;/p&gt;

&lt;p&gt;When you connect to your server, you are taken to the user's home directory. This is what the tilde (~) means. We are in the home director of the root user. If we want to see what is there, we can use the &lt;code&gt;ls&lt;/code&gt; command. Nor &lt;em&gt;dir&lt;/em&gt; because now we are in the server not in our machine, and the server OS is Linux.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---N_jkm6j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/13_ls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---N_jkm6j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/13_ls.png" class="img-fluid" width="50%" height="auto" alt="ls"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are not going to see anything because the directory is empty. Let's go one directory up using the &lt;code&gt;cd ..&lt;/code&gt; command and see what's in there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p3XBKrS7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/14_linux_file_system_in_vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p3XBKrS7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/14_linux_file_system_in_vps.png" class="img-fluid" width="70%" height="auto" alt="linux file system in vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The / directory is called the &lt;em&gt;root&lt;/em&gt; directory. This root has nothing in common with the root user. It is the most upper directory in your server (or your partition to be more precise) (like *c:* in Windows).&lt;/p&gt;

&lt;p&gt;I'm not going to get into details about Linux file system here, but let me walk you through some of the most important directories.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;bin&lt;/em&gt; directory contains the essential Linux binaries (programs). In &lt;em&gt;etc&lt;/em&gt; you will find configuration files. In &lt;em&gt;home&lt;/em&gt;, the home folder for each user, except for the root user, whose home directory is in &lt;em&gt;root&lt;/em&gt;. Our &lt;em&gt;usr&lt;/em&gt; folder will be empty because we don't have any user yet, but it will contain the applications installed for each user, in contrast with the &lt;em&gt;bin&lt;/em&gt; dir, where there are the programs used by the system.&lt;/p&gt;

&lt;p&gt;You can use the &lt;code&gt;clear command&lt;/code&gt; to delete everything in your terminal.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing Users in Our VPS
&lt;/h2&gt;

&lt;p&gt;So far we have only the root user in our VPS. Let's create an additional user so that we don't have to connect to our server as the root, which is not a good practice.&lt;/p&gt;

&lt;p&gt;On Linux, the root user is equivalent to the administrator user on Windows. It's not advisable to log in to your system as root in order to minimize the risk of breaking something.&lt;br&gt;
So, let's create a user using the &lt;code&gt;adduser USERNAME&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;You will be asked to create a password for the recently created user, make sure you choose a strong one. Keep in mind that as you type the passwords you won't see the cursor moving.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gOyVnt_3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/16_add_user_to_linux_vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gOyVnt_3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/16_add_user_to_linux_vps.png" class="img-fluid" width="80%" height="auto" alt="add users to linux vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To change the password for one user  &lt;code&gt;passwd USERNAME&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To delete a user &lt;code&gt;userdel USERNAME&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To list all users, you can use &lt;code&gt;cat /etc/passwd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;cat&lt;/em&gt; commands list the contents of a file. &lt;br&gt;
The output shows a lot more users than you expected because it lists the system users too. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xZn9RZK7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/17_users_list.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xZn9RZK7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/17_users_list.png" class="img-fluid" width="80%" height="auto" alt="add users_list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each line represents a user and it has 7 fields, separated by a colon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NtvBnWOU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/17_b_cat_command.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NtvBnWOU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/17_b_cat_command.png" class="img-fluid" width="80%" height="auto" alt="cat command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generally, a system user has a UID smaller than 1000. &lt;/p&gt;

&lt;p&gt;Let's now log out using the &lt;code&gt;logout&lt;/code&gt; command and login with the new user we have created.&lt;/p&gt;

&lt;p&gt;Now, if you try to log in using ssh &lt;code&gt;ssh USERNAME@IP&lt;/code&gt;, you get a &lt;em&gt;Permission denied (publickey)&lt;/em&gt; error. This is because you need to change the configuration of your SSH in &lt;em&gt;sshd_config&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's open the file with Vim (a text editor that comes out of the box with Linux). &lt;code&gt;sudo vim /etc/ssh/sshd_config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you are not used to command line text editors, it might look a little tedious to work with Vim, but with a little patience you'll get used to it.&lt;/p&gt;

&lt;p&gt;To edit the file, press I (now you should see &lt;em&gt;--INSERT&lt;/em&gt; at the bottom of the screen). Look for the following piece of text:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# Change to no to disable tunnelled clear text passwords&lt;br&gt;
PasswordAuthentication no&lt;/code&gt;&lt;br&gt;
And change &lt;em&gt;PasswordAuthentication&lt;/em&gt; to &lt;em&gt;yes&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HB7ByYOw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/18_config_ssh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HB7ByYOw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/18_config_ssh.png" class="img-fluid" width="80%" height="auto" alt="change ssh config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To save the changes press &lt;em&gt;scape&lt;/em&gt; and type &lt;code&gt;:wq&lt;/code&gt;, this is to quite saving the changes. To just quit without saving the changes, use &lt;code&gt;:q&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reload the ssh configuration with the command &lt;code&gt;service sshd reload&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now you will be able to login with the non-root user using the password you assigned to it:&lt;/p&gt;

&lt;p&gt;Although this is something you are allowed to do and you should know how to do it, I would not recommend to allow login using a password. For that we'll need to associate a ssh key to the user we have just created so that he/she can log in via SSH.&lt;/p&gt;

&lt;p&gt;You can generate a new SSH key or use one that you already have in your computer. I will use an existing one, but remember that to create one you should use &lt;code&gt;ssh-keygen&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To associate the key with the new user, logout from the server (by typing &lt;code&gt;logout&lt;/code&gt;). Now you are in your computer. Execute:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh-copy-id -i  ~/.ssh/id_rsa.pub USERNAME@SERVER-IP&lt;/code&gt; if you are on Linux or Mac.&lt;/p&gt;

&lt;p&gt;The first parameter is the path to the key and the second the user and IP in the remote server &lt;/p&gt;

&lt;p&gt;&lt;em&gt;ssh-copy-id&lt;/em&gt; append the contents of your local public key file to a remote file called authorized_keys.&lt;/p&gt;

&lt;p&gt;In windows, this command would not work and, as far as I know,  there is no a similar one. So let's try to replicate that behavior with: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;cat C:/Users/USER-DIR/.ssh/id_rsa.pub | ssh USERNAME@SERVER-IP "cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the &lt;em&gt;.ssh&lt;/em&gt; dir does not exits in your vps, you will get an error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oOHlt9tX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/25_error.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oOHlt9tX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/25_error.png" class="img-fluid" width="80%" height="auto" alt="error "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In that case, you need to first create the directory:&lt;br&gt;
&lt;code&gt;cat C:/Users/USER-DIR/.ssh/id_rsa.pub | ssh USERNAME@SERVER-IP "mkdir ~/.ssh; cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now if we try to log into the vps, we won't be asked for the user's password anymore.  What we are asked is the key password we added to our ssh key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ll2TC509--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/26_lamp_on_vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ll2TC509--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/26_lamp_on_vps.png" class="img-fluid" width="80%" height="auto" alt="lamp on vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, now that we are able to log as the non-root user using a ssh, let's disallow password authentication.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vim /etc/ssh/sshd_config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set &lt;em&gt;PasswordAuthentication&lt;/em&gt; to  &lt;em&gt;no&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This new user is a regular user, meaning that there are certain tasks she/he would not have permission to perform.&lt;/p&gt;

&lt;p&gt;If we want to allow a user to execute superuser tasks, we can elevate the user and give him/her superuser privileges. We can upgrade the non-root user by adding it to the &lt;em&gt;sudo&lt;/em&gt; user group.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;usermod -a -G sudo USERNAME&lt;/code&gt; Make sure you are executing this command with the root user.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;usermod&lt;/em&gt; calls the program, &lt;em&gt;-a&lt;/em&gt; adds to a group, &lt;em&gt;-G&lt;/em&gt; specifies the group.&lt;/p&gt;

&lt;p&gt;Now, let's check if the user has sudo privileges by checking the group the user belong to with the command &lt;code&gt;groups USERNAME&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NVsShgXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/20_usermod.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NVsShgXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/20_usermod.png" class="img-fluid" width="80%" height="auto" alt="usermod command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From now on,  the user sonia (in my case) can execute root commands by prefixing the with &lt;em&gt;sudo&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;For example, to create a new user: &lt;code&gt;sudo adduser peter&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you get a sudo command not found, run &lt;code&gt;apt-get install sudo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You might be asked to enter your password. This will happen if this is the first time you're using &lt;em&gt;sudo&lt;/em&gt; within the current session.&lt;/p&gt;

&lt;p&gt;One thing I would recommend you to do is to do not allow log into the server using the root user. This is a security measure you can take to make it harder for hackers to try to get into your server. The goal of many hackers is to get root access to a site. So, let's try to do all we can to avoid this.&lt;/p&gt;

&lt;p&gt;Open the configuration file with the command &lt;code&gt;vim /etc/ssh/sshd_config&lt;/code&gt; and edit the line &lt;em&gt;PermitRootLogin yes&lt;/em&gt; by setting it to &lt;em&gt;no&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You might need to restart your droplet. To do it: &lt;code&gt;sudo shutdown -r now&lt;/code&gt; or &lt;code&gt;sudo reboot&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the LAMP stack in our VPS
&lt;/h2&gt;

&lt;p&gt;At this point we have a VPS with only the OS installed. Actually there is something more than the OS because when we installed our Linux Distribution (Ubuntu) some programs where installed along with the Linux OS.&lt;/p&gt;

&lt;p&gt;In order to host and serve websites and applications from our VPS we need to install some software. There are multiple options here, but we are going to install what is called the LAMP stack. LAMP stands for Linux, Apache, MySQL, PHP, and it is one of the most popular stacks for hosting and serving websites and web apps written in PHP.&lt;/p&gt;

&lt;p&gt;If your website does not use PHP, you should install any other software you need, like Python if your site is build with Python.&lt;/p&gt;

&lt;p&gt;There are other popular stacks, like LEMP, which uses Ngnix instead of Apache or MEAN, which uses MongoDB, Express, Angular and Node. Or you can make your own stack using any combination of them.&lt;/p&gt;

&lt;p&gt;You can of course setup IIS and MSSQL, but they are not free.&lt;/p&gt;

&lt;p&gt;Before we install anything, let's make sure the programs ('packages' is how they are called in Linux) that are already installed in our server are up to date. &lt;br&gt;
Run &lt;code&gt;sudo apt update&lt;/code&gt; to update any package that need to be updated.&lt;/p&gt;

&lt;p&gt;As you can see I'm prefixing the command with &lt;em&gt;sudo&lt;/em&gt; because I'm logged in with a non-root user. Remember that it is a good practice to avoid login in with the root user.&lt;/p&gt;

&lt;p&gt;Once it is done updating, we are ready to start installing the different pieces of software that are part of the LAMP stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apache
&lt;/h3&gt;

&lt;p&gt;Let's start with Apache, the web server.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;sudo apt install apache2&lt;/code&gt; to install it.&lt;/p&gt;

&lt;p&gt;You will be prompted to confirm if you want to proceed with the installation, enter &lt;em&gt;Y&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now, let's run it:&lt;br&gt;
&lt;code&gt;systemctl start apache2.service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And check if Apache has been installed correctly by opening your browser and typing &lt;em&gt;&lt;a href="http://your-vps-ip"&gt;http://your-vps-ip&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You should see a page similar to this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3vkB60wH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/21_install_apache_in_ubuntu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3vkB60wH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/21_install_apache_in_ubuntu.png" class="img-fluid" width="80%" height="auto" alt="apache on lubuntu vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you cannot see the apache page, it might be because the server firewall is blocking the traffic.&lt;/p&gt;

&lt;p&gt;Ubuntu comes with a firewall installed out of the box, the Uncomplicated FireWall (UFW). By default it should be disabled, but let's check if it has been enabled with the command: &lt;code&gt;sudo ufw status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the status is active, let's disable it for now. We'll come back later and enable and configure it. &lt;code&gt;sudo ufw disable&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should be able to navigate to the Apache page now.&lt;/p&gt;

&lt;p&gt;Here are some basic commands to start, stop, and, restart Apache.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
//Start command &lt;br&gt;
systemctl start apache2.service&lt;/p&gt;

&lt;p&gt;//Stop command &lt;br&gt;
systemctl stop apache2.service&lt;/p&gt;

&lt;p&gt;//Restart command&lt;br&gt;
systemctl restart apache2.service&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Notice that those commands work with Ubuntu(Debian) Linux distributions. For other distributions the commands might be different.&lt;/p&gt;

&lt;p&gt;Now we are ready to server webpages, but those web pages might need a database to store data that they will display. So, let's install a database server. As we are installing the LAMP stack, we'll install MySQL.&lt;/p&gt;

&lt;h3&gt;
  
  
  MySQL
&lt;/h3&gt;

&lt;p&gt;To install MySql, simply run &lt;code&gt;sudo apt install mysql-server&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When done, it's advisable to install a script that helps us make our DB secure. &lt;code&gt;sudo mysql_secure_installation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You'll be asked during the installation if you want to install the Validate Password Plugin.  This is a tool to make sure when you create a password it is strong by validating it against certain conditions. I won't install it.&lt;/p&gt;

&lt;p&gt;Then, you will need to enter the password for the root user (this is not the root user of your Linux OS but the root user for MySQL). Don’t leave it blank and make sure to use a strong password. &lt;/p&gt;

&lt;p&gt;For the rest of the questions you can just enter Yes.&lt;/p&gt;

&lt;p&gt;Once the installation is finished, let's verify it by executing &lt;code&gt;sudo mysql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will connect you to the MySQL DB as the root user, and will open the mysql console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gRQjgHBz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/22_instal_mysql_in%2520_a_vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gRQjgHBz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/22_instal_mysql_in%2520_a_vps.png" class="img-fluid" width="80%" height="auto" alt="mysql on vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Type &lt;strong&gt;exit&lt;/strong&gt; to log out of mysql.&lt;/p&gt;

&lt;p&gt;Those are the command to start, stop, and restart MySql:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemctl start mysql&lt;br&gt;
systemctl stop mysql&lt;br&gt;
systemctl restart mysql&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Php
&lt;/h3&gt;

&lt;p&gt;The last piece of the LAMPP stack is PHP. Let's install it along with &lt;strong&gt;php-mysql&lt;/strong&gt; (a tool to connect php with the DB)  and &lt;strong&gt;libapache2-mod-php,&lt;/strong&gt; a required component to allow Apache to handle PHP files. We can install all three at once with the following command:&lt;br&gt;
&lt;code&gt;sudo apt install php libapache2-mod-php php-mysql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's it. Let's test it by creating a php file and run it.&lt;/p&gt;

&lt;p&gt;To do it, create a new file called &lt;em&gt;info.php&lt;/em&gt; in &lt;em&gt;var/www/html&lt;/em&gt; and open it with vim.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;/var/www/html&lt;/em&gt; directory is known as the &lt;strong&gt;web root&lt;/strong&gt;. This is where by default Apache looks for the file requested in a website URL. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo vim /var/www/html/info.php&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Type the following code (remember to press &lt;em&gt;I&lt;/em&gt; to allow inserting text with Vim).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br&gt;
phpinfo();&lt;br&gt;
?&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This piece of code displays information about our current Php installation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2QiHr9Ar--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/23_test_php_in_vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2QiHr9Ar--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/23_test_php_in_vps.png" class="img-fluid" width="80%" height="auto" alt="lamp on vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save it and quit by pressing ESC and typing &lt;em&gt;:wq&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In your browser, navigate to &lt;em&gt;http.//your-vps-ip/info.php&lt;/em&gt; and you should see a page like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f1M_cZVG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24_install_php_in_ubuntu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f1M_cZVG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24_install_php_in_ubuntu.png" class="img-fluid" width="80%" height="auto" alt="php on ubuntu vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leaving this file in our server is not a good idea because it shows information about the server that can help malicious hackers attack it. So, let's remove it by running &lt;code&gt;sudo rm /var/www/html/info.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We have successfully installed all three pieces of the LAMP stack, so technically we are ready to create and manage MySQL databases and serve web pages and applications written in Php that get dynamic data form a MySQl database. However, there are a couple more things you want to do to have a fully functional server to host and manage your website.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Set Up a Firewall in Our VPS
&lt;/h2&gt;

&lt;p&gt;We'll use a firewall to add some network security by filtering incoming and outgoing network traffic based on a set of user-defined rules. &lt;/p&gt;

&lt;p&gt;We have different options to set a firewall in out server:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using  &lt;a href="https://www.digitalocean.com/docs/networking/firewalls/how-to/configure-rules/"&gt; DigitalOcean Firewall&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using iptables. Iptables is a standard firewall included in most Linux distributions. &lt;br&gt;
I'm not going to cover iptables here. If you are interested, you can learn more &lt;a href="https://help.ubuntu.com/community/IptablesHowTo"&gt; here &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using UFW (Uncomplicated Firewall):  UFW is an interface to iptables that simplifies its use. This is what I'm going to use.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to set up UFW on Ubuntu
&lt;/h3&gt;

&lt;p&gt;UFW should be installed with your Linux distribution, but let's make sure by running &lt;code&gt;sudo which ufw&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You'll get back something like &lt;em&gt;/usrs/bin/ufw&lt;/em&gt;, the directory where the ufw is installed.&lt;/p&gt;

&lt;p&gt;If it does not return the path to ufw, then install UFW with the following command: &lt;code&gt;sudo apt-get install ufw&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's now check the status of the firewall: &lt;code&gt;ufw status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It should be disabled at this point.&lt;/p&gt;

&lt;p&gt;By default, UFW denies all incoming connections and allows all outgoing connections. This means that anyone trying to reach your server would not be able to connect, while any application within the server would be able to get out. As we want to host our website, our server should be able to respond to incoming request, so we need to modify this configuration. We do it by creating rules.&lt;/p&gt;

&lt;p&gt;The first thing we want to allow is ssh connections so that we can connect form our local computer. To set the rule, run &lt;code&gt;sudo ufw allow ssh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will allow all connections on port 22, which is the port that the SSH daemon listens on by default. &lt;/p&gt;

&lt;p&gt;However, if your ssh daemon is configured to use another port, you should use the same command but specifying the port instead of the service: &lt;code&gt;sudo ufw allow 2222&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check which port ssh uses, you can run &lt;code&gt;sudo grep Port /etc/ssh/sshd_config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As my VPS ssh connection is configured to use port 22, I can create the rule with any of those two commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ufw allow ssh&lt;br&gt;
sudo ufw allow 22&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LFqPaVVM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24b_ufw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LFqPaVVM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24b_ufw.png" class="img-fluid" width="70%" height="auto" alt="set a firewall on vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can safely enable the firewall because we have made sure that we can connect via ssh. To do it: &lt;code&gt;sudo ufw enable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You will see a warning that says the command may disrupt existing SSH connections. It's ok. We can connect back.&lt;/p&gt;

&lt;p&gt;To disable it we'll use &lt;code&gt;ufw disable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Connect again to the server and check the status of the firewall. This time adding the &lt;em&gt;verbose&lt;/em&gt; flag to the command: &lt;code&gt;sudo ufw status verbose&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the status is active, the verbose flag will return additional information about the rules being applied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6uwSxMQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24c_ufw_status.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6uwSxMQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24c_ufw_status.png" class="img-fluid" width="70%" height="auto" alt="set ufw on vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If after enabling the firewall, the status remains inactive, make sure you restart your VPS with &lt;code&gt;sudo reboot&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There is one more thing we need to do. It is to allow incoming requests from browsers trying to visit our website. To do so, we need to create a rule to allow http and https connections.&lt;/p&gt;

&lt;p&gt;As with ssh, this can be done by specifying the port or the connection type — this last option only if the server uses the default ports: 80 for http and 443 for https&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ufw allow 80&lt;br&gt;
sudo ufw allow 443&lt;br&gt;
sudo ufw allow http&lt;br&gt;
sudo ufw allow https&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cJEuBpUc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24d_ufw_http_status.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cJEuBpUc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24d_ufw_http_status.png" class="img-fluid" width="70%" height="auto" alt="set ufw rules"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yo can also specify the protocol if you want to limit the connections to only TCP or UDP. If you do not specify the protocol, the connection is allowed for both protocols: &lt;code&gt;ufw allow 22/tcp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In case you are wondering what TCP and UDP are, don't worry. They are network protocols that determine how to send data packets over the Internet. When you send an email or a page request through your browser, you are sending data that is transferred in packets. TCP and UDP protocols define how this data is sent. In most cases, allow both and you will be good.&lt;/p&gt;

&lt;p&gt;When you run &lt;code&gt;sudo ufw status verbose&lt;/code&gt;, you can see the column &lt;em&gt;From&lt;/em&gt; with the values set to &lt;em&gt;Anywhere&lt;/em&gt;. This means that we are allowing connections form any computer, which makes sense if we want to publish a public website.&lt;/p&gt;

&lt;p&gt;However, if for any reason you want to limit the traffic to an specific computer or computers, you can set the IP that you want to allow to connect. &lt;br&gt;
&lt;code&gt;sudo ufw allow from xxx.x.xxx.x&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also allow connections to a range of ports. It that case, you must specify the protocol (tcp or udp).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ufw allow 6000:6007/tcp&lt;br&gt;
sudo ufw allow 6000:6007/udp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to deny the connections to an specific port, request type or IP, you can also with &lt;em&gt;deny&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ufw deny 22&lt;br&gt;
ufw deny ssh&lt;br&gt;
ufw deny http&lt;br&gt;
sudo ufw deny from xxx.x.xxx.x //IP&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Another important thing to know is how to delete a specific rule.&lt;/p&gt;

&lt;p&gt;You can do it in two ways: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specifying the actual rule to delete:
&lt;code&gt;sudo ufw delete allow ssh
 sudo ufw delete allow 22&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Specifying the rule id. Each rule has a numeric identifier. We can get the id by running the status command with the numbered flag: &lt;code&gt;sudo ufw status numbered&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yFNSt-zQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24e_ufw_http_status.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yFNSt-zQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/24e_ufw_http_status.png" class="img-fluid" width="70%" height="auto" alt="delete rule ufw"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To delete a specific rule, run the command:&lt;br&gt;
&lt;code&gt;sudo ufw delete 2 //rule id&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And if you want to delete all rules: &lt;code&gt;ufw reset&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One more thing done. Let's go for the next one, which is setting virtual hosts.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up your Domain
&lt;/h2&gt;

&lt;p&gt;If you are hosting your website in you VPS you will probably want to use your domain. To do so we have to set a new A record of the domain pointing to the VPS IP or your domain.&lt;/p&gt;

&lt;p&gt;You do it where your domain registration is managed. &lt;/p&gt;

&lt;p&gt;First make sure that your DNS is set to the registrar nameservers.&lt;/p&gt;

&lt;p&gt;Ex: if your domain is register in GoDaddy, you must have the DNS set to goDaddy. Otherwise, the DNS records will be managed by the hosting provider (and we don't want to use any hosting provider here).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VBMKxZg_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/dns-vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VBMKxZg_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/dns-vps.png" class="img-fluid" width="70%" height="auto" alt="point domain to vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will need to set the name @ (@ means the whole domain) to point to the VPS IP.&lt;br&gt;
Then, you want to set the canonical name (CNAME) www to the same IP than @. And also the ftp.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G4BYRz0w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/dns-records.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G4BYRz0w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/dns-records.png" class="img-fluid" width="70%" height="auto" alt="point domain to vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it. You only need to wait for the changes to propagate, what can take a couple of hours.&lt;br&gt;
Once it is propagated, if you browse to your domain, you will see your VPS.&lt;/p&gt;

&lt;p&gt;But, what if you want to host multiple domains in your VPS? No problem. I'll show you how to set up multiple virtual hosts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Multiple Virtual Hosts to Host Multiple Domains in our VPS
&lt;/h3&gt;

&lt;p&gt;If you want to install multiple domains in the same VPS, you need to create multiple virtual hosts.&lt;/p&gt;

&lt;p&gt;The web server(Apache) will determine which site's files to serve out based on the the hostname portion of the specified URL (the domain name).&lt;/p&gt;

&lt;p&gt;Even if you only need to host a single website for now, I recommend that you set it up as a virtual host, which will make it easier to add more sites later.&lt;/p&gt;

&lt;p&gt;Apache by default is configured to serve documents from &lt;em&gt;var/www/html&lt;/em&gt;. Do you remember that we placed here our info.php file when testing our Php installation?&lt;/p&gt;

&lt;p&gt;To serve files for different domains, we'll create a directory for each site we want to host within the /var/www folder.&lt;/p&gt;

&lt;p&gt;Create a html dir and a log dir, for each domain&lt;br&gt;
&lt;code&gt;mkdir -p /var/www/domain1.com/html&lt;br&gt;
mkdir -p /var/www/domain1.com/log&lt;br&gt;
mkdir -p /var/www/domain2.com/html&lt;br&gt;
mkdir -p /var/www/domain2.com/log&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Actually you can create those folders wherever you want, but is good practice to follow conventions. &lt;/p&gt;

&lt;p&gt;I have created the folders for soniagm.com. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X5pUE_5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/30-vhost.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X5pUE_5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/30-vhost.png" class="img-fluid" width="70%" height="auto" alt="virtual hosts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to make sure that the directories we have just created have the 755 permission (read and execute access for everyone and also write access for the owner of the file).&lt;br&gt;
&lt;code&gt;chmod -R 755 /var/www&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If we check the permissions for the domain directory, we can see that its owner is the root user and the root group. As my user belongs to the root group, it will have permission to write into that dir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kh0yCGC4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/34-vps-permissions.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kh0yCGC4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/34-vps-permissions.png" class="img-fluid" width="70%" height="auto" alt="virtual hosts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's now create a test file (index.html, for example) in the html folder.&lt;/p&gt;

&lt;p&gt;Navigate to the the your-domain/html folder and run &lt;code&gt;sudo vim index.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will open the empty file in vim. Paste the following code: (Remember to press I to start editing the file)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&amp;lt;html lang="en"&amp;gt;&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;&lt;br&gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;&lt;br&gt;
    &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
    &amp;lt;h1&amp;gt; Home of the domain &amp;lt;/h1&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When done, press ESC and type &lt;code&gt;:wq&lt;/code&gt; to save and quit&lt;/p&gt;

&lt;p&gt;Our file structure is ready. Let's create the virtual hosts.&lt;/p&gt;

&lt;p&gt;To create the virtual hosts, we have to create an Apache virtual host configuration file to serve each one of your websites.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo vim /etc/apache2/sites-available/domain1.com.conf&lt;br&gt;
sudo vim /etc/apache2/sites-available/domain2.com.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following code to each file&lt;br&gt;
&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;br&gt;
ServerAdmin admin@soniagm.com&lt;br&gt;
ServerName soniagm.com&lt;br&gt;
DocumentRoot /var/www/soniagm.com/html&lt;br&gt;
DirectoryIndex index.html&lt;br&gt;
ErrorLog ${APACHE_LOG_DIR}/soniagm.com_error.log&lt;br&gt;
CustomLog ${APACHE_LOG_DIR}/soniagm.com_access.log combined&lt;br&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Quit with &lt;code&gt;:wq&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The VPS by default is set to read the default 000-default.conf file.  We will need to disable the default file and enable the configuration files we have created.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo a2dissite 000-default.conf&lt;br&gt;
sudo a2ensite domain1.com.conf&lt;br&gt;
sudo a2ensite domain2.com.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will have to restart Apache for those changes to take effect: &lt;code&gt;sudo systemctl restart apache2.service&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="http://your-domain/"&gt;http://your-domain/&lt;/a&gt; and you should see the index.html page you created&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Add a FTP Server
&lt;/h2&gt;

&lt;p&gt;You will need to be able to upload files from your computer to your VPS. We can use FTP to do it. Probably, you already have a FTP client such as FileZilla installed in your local machine, what we need to do now is to install a FTP server in out VPS.&lt;/p&gt;

&lt;p&gt;I'm going to install &lt;a href="https://security.appspot.com/vsftpd.html"&gt; Vsftpd &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install vsftpd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Start the service manually: &lt;code&gt;sudo systemctl start vsftpd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And enable it to start when the server starts: &lt;code&gt;systemctl enable vsftpd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As with any other service, you can check it status with &lt;code&gt;service vsftpd status&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, in order to allow access to FTP services from our (and others) computer, we have to open port 20 and 21:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ufw allow 21/tcp&lt;br&gt;
 sudo ufw allow 20/tcp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's setup and secure our FTP server.&lt;br&gt;
Before we modify the vsftpd config file, let's make a backup: &lt;code&gt;sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HPsJMuT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/35_ftp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HPsJMuT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/35_ftp.png" class="img-fluid" width="80%" height="auto" alt="install ftp in vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's now open the config file with vim and make sure those config options are set up:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;listen=NO             # prevent vsftpd from running in standalone mode&lt;br&gt;
listen_ipv6=YES             # enable vsftpd to listen on an IPv6 socket i&lt;br&gt;
anonymous_enable=NO             # disable  anonymous login&lt;br&gt;
local_enable=YES        # allows local logins&lt;br&gt;
write_enable=YES        # enable FTP commands which change the filesystem&lt;br&gt;
dirmessage_enable=YES           # enable showing of messages when users first enter a new directory&lt;br&gt;
xferlog_enable=YES      # maintain a log file detailing uploads and downloads&lt;br&gt;
connect_from_port_20=YES        # use port 20 (ftp-data) on the server machine for PORT &lt;br&gt;
local_umask=022             # value of umask for file creation for local users&lt;br&gt;
xferlog_std_format=YES          # keep standard log file format&lt;br&gt;
pam_service_name=vsftpd         # name of the PAM service vsftpd will use&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After modifying the conf file, restart the ftp service: &lt;code&gt;systemctl restart vsftpd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now you should be able to connect to your server via ftp using any of the users.&lt;br&gt;
Open a new terminal window where you won't be connected to your VPS and run &lt;code&gt;ftp VPS_IP&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kY3pZqpu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/36_connect_ftp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kY3pZqpu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/36_connect_ftp.png" class="img-fluid" width="70%" height="auto" alt="ftp in vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To disconnect, enter 'bye'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5KJrwOFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/37_bye_ftp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5KJrwOFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/37_bye_ftp.png" class="img-fluid" width="70%" height="auto" alt="bye ftp in vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might prefer to use FileZilla or another client with a graphical interface to work with FTP. Now that we have made sure that we can connect to our server, you can configure your client as usual.&lt;/p&gt;

&lt;p&gt;Here you can see how I have connected to my Digital Ocean Droplet using FileZilla.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y2BbZyQA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38_filezilla.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y2BbZyQA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38_filezilla.png" class="img-fluid" width="70%" height="auto" alt="filezilla to vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a SSL certificate to our VPS
&lt;/h2&gt;

&lt;p&gt;SSL stands for Secure Socket Layer, and it is a way to encrypt the sensitive information sent over the Internet. Sensitive information like usernames, passwords and credit card info can be sent safely, out of the reach of malicious hackers, making your site more secure. This is why when users visit a site that doesn't have an SSL certificate, their browsers warn them: "This connection is not secure."&lt;/p&gt;

&lt;p&gt;So, its highly advisable to install a SSL certificate even if your site is not sending sensitive information, because you don't want this unfriendly message to be shown when a user try to browse your website, right?&lt;/p&gt;

&lt;p&gt;You have two options: add a free certificate or buy a paid one and upload it to your VPS. In most of the cases, a free one would be enough and it's what I'm going to do here. I'm going to install a free SSL certificate from Let's Script.&lt;/p&gt;

&lt;p&gt;In order to be able to add the free Let's Script certificate to out Digital Ocean droplet, we must have the DNS of our domain pointing to Digital Ocean DNS. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YsNWN_Ly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38-digital-ocean-nameservers.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YsNWN_Ly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38-digital-ocean-nameservers.png" class="img-fluid" width="80%" height="auto" alt="digital ocean nameservers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you don't know how to do it, you can check  &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-point-to-digitalocean-nameservers-from-common-domain-registrars"&gt; this guide &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you remember that in order to associate our domain with our VPS we added some DNS records? Well, since now we have changed the nameservers, we'll need to do it again. This time from Digital Ocean control panel.&lt;/p&gt;

&lt;p&gt;First of all, we need to associate a domain to our droplet. Click 'Create' in the top right, and select Domains/DNS.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mPkK_SwF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38-digital-ocean-add-domain.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mPkK_SwF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/38-digital-ocean-add-domain.png" class="img-fluid" width="80%" height="auto" alt="digital ocean domain name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, enter the domain name in the Enter Domain field and click 'Add Domain'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q2Jk42d3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/40-digital-ocean-vps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q2Jk42d3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/40-digital-ocean-vps.png" class="img-fluid" width="70%" height="auto" alt="digital ocean vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will take us to the screen where we can add DNS records to our domain. Those are the records you have to add:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_oVw2tqW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/41-digital-ocean-set-dns-records.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_oVw2tqW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.soniagarcia.dev/blog-images/vps/41-digital-ocean-set-dns-records.png" class="img-fluid" width="70%" height="auto" alt="digital ocean vps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that you need to wait for the changes to propagate, what can take a couple of hours.&lt;/p&gt;

&lt;p&gt;And that's it. You are ready to start serving your websites from your own VPS.&lt;/p&gt;

&lt;p&gt;Thanks for reading it!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
