Creating a Simple Website on Vultr With OpenBSD and httpd

Updated on October 26, 2018
Creating a Simple Website on Vultr With OpenBSD and httpd header image

Introduction

The purpose of this guide is to show you how easy it is to make a homepage for your website on Vultr with OpenBSD and httpd.

Creating the Instance

Head over to https://my.vultr.com/deploy/. This is the main page for deploying new servers. However, before installing anything on your server, we must first create it. Thankfully, Vultr has made this process very easy:

  1. Choose where you would like the server to be located at.
  2. Select "64bit" and then "OpenBSD".
  3. Select the desired hardware specifications for the new instance.
  4. Select any additional features you need.
  5. If you have any startup scripts place them here.
  6. Create and add your SSH key. (See this guide)
  7. Finally enter the Hostname and Label for the server. For this guide, we will use My-Website-01.

After checking the summary at the bottom of the page and making sure everything is correct, click the Deploy Now button. Allow a minute or two for the server to be created. Afterwards you will be redirected to a new page that shows the status of all your servers.

Once the status tab turns green on the newly created server, everything is up and running. Click the manage link next to it and you will be taken to the server information page. You will see Server Information (My-Website-01) at the top of the page. From here you can manage the server and view the root password by clicking the eye icon.

Update DNS Records

Next you should record the IP address assigned to your server and point your DNS records at it. You can read more about how to do this here.

Logging into the Server over SSH as root

Open up your SSH program and connect to your server as root. Please note that this is heavily frowned upon so we will only be doing this once in order to create a non-root user with elevated privileges. Once you have connected to your server over SSH, make an account for yourself. To do this enter adduser into the terminal. You will now be prompted with several questions about the new account. The only two things you are required fill out are your username and password. The rest of the questions are optional.

After making the account, the final thing that must be done is enabling elevated privileges for it. While you are still logged in as root, enter the following into the terminal:

user mod -G wheel username

This will place your account in the wheel group, allowing you to act as root.

Logging into the Server over SSH with your new username

We are now finished with creating your account. Exit the server and reconnect with your new account. The first thing you should do is enter su into the terminal. You will be asked the password for the root account.

Creating a directory for your Website

Now we need to make a directory for your website:

mkdir -p /var/www/htdocs/yourwebsite.com

Configuring httpd

Let's make the configuration file:

vi /etc/httpd.conf

Type the following into the file:

# Main Configuration
server "yourwebsite.com" {
	listen on * port 80
	root "/htdocs/yourwebsite.com"
}

# This is a redirect to the Main Configuration
server "www.yourwebsite.com" {
	listen on * port 80
	block return 301 "http://yourwebsite.com$REQUEST_URI"
}

Save and exit.

Checking the configuration settings and starting httpd

Go ahead and make sure everything is working:

httpd -n

You will see httpd(ok). This indicates that everything is working.

The final two things we need to do for httpd is enable it, and then start it.

Enable httpd:

rcctl enable httpd

Start httpd:

rcctl start httpd

You will now be able to access your website over the internet, however you will get a 403 status code because there's nothing in the website directory. Let's change that.

Creating a simple Webpage

Create your homepage by typing the following:

vi /var/www/htdocs/yourwebsite.com/index.html

Populate it with the following:

<!DOCTYPE html>
<html>
	<head>
		<title>Hello World</title>
	</head>
	
	<body>
		<p>Welcome to my OpenBSD server on Vultr!</p>
	</body>
</html>

Save and exit, and you have successfully created your first website on OpenBSD.