How I run all my websites on one virtual private server

26 Apr 2024

I run multiple websites from a single VPS that I have procured from Linode (not affliated). I do this because I suffer a bit from shiny object syndrome, as there's always another exciting project waiting to be started and even more projects to neglect.

My setup on the VPS helps me test out new websites easily, and if they don't pan out, I can just as easily delete them again and move on. The setup is based on

CentOS

RockyLinux running Nginx and PostgreSQL. I run Certbot for SSL certificates.

The setup includes following steps: Let's run through the setup of a website.

DNS

In order to get my domain name pointing to my VPS, I need to setup some DNS records. It is a good idea to start with this step, because the DNS records may take some time to update. I have my domain names at Namesilo, but you'll be able to setup DNS with whatever provider that you may have.

I setup the two following DNS records to start with.
Type Hostname Value
A philiosoerensen.com 127.0.0.1
A www.philipsoerensen.com 127.0.0.1
Obviously you would replace philipsoerensen.com with whatever your domain is called and 127.0.0.1 with whatever IP your server is located at.

Since I run Nginx on my webserver, the URL will show a default page, when the DNS has updated (again this may take some time). With the DNS records setup I can now setup the website in Nginx.

Setting up a new website with Nginx

To setup a new website with my Nginx installation, I'll do the following steps: Replace philipsoerensen.com with your domain name, and that is basically it.

Setting up a database for the new website

Your website probably won't be that useful without a database, so let's make one. I run my databases on a PostgreSQL server and I like to keep each website isolated on it's own database, therefore I'll create a new database.

I log into my VPS and write the following:
sudo -u postgres psql
This logs me into the commandline of PostgreSQL, where I can create a user for the website and a matching database. You can replace mydb (name of the database), myuser (name of the database user) and mypass (password for the database user) below with something that matches your naming convention and requirements for the password.
create database mydb;
create user myuser with encrypted password 'mypass';
grant all privileges on database mydb to myuser;
You can then exit the commandline by typing: \q.

If it's a Laravel project, I'll write the credentials into my .env-file and do a test migration. I can then log into the server through PgAdmin to verify the migration.

E-mail hosting

I don't really want to deal with e-mail on my own server (personal choice), therefore I have my e-mail hosted at a service provider instead.

MX Route

I use MX route (not affiliated) to host my e-mail. There I can host as many websites as I want. To use them however I need to setup the following DNS records:

Type Hostname Value Priority
MX philiosoerensen.com blizzard.mxrouting.net 10
MX philipsoerensen.com blizzard-relay.mxrouting.net 20
TXT philipsoerensen.com VPF record
TXT x._domainkey DKIM record
The VPF and DKIM record are personalized, so you need to get that from your e-mail provider.

After the DNS is setup I usually create an e-mail account for the domain, e.g. support@philipsoerensen.com. Then I setup catch-all, so every possible e-mail for the domain will be sent to the newly created e-mail account.

Wrapping up

Following the above guideline I can setup a website that is online with a working e-mail account for the domain within 10 minutes. This gives me a great opportunity to try out new ideas and see if they work, before putting more effort/money into them.

You might also enjoy

Getting title tag and meta tags from a website using PHP

Getting title tag and meta tags from a website using PHP

Published 2024-05-14

PHP

Web development

Learn how to easily webscrape title and meta tags from a website using simple PHP commands.

Read the post →
Using Linode/Akamai for your S3 storage in Laravel

Using Linode/Akamai for your S3 storage in Laravel

Published 2024-05-05

Laravel

Web development

Implementing a S3 bucket from Linode/Akamai in your Laravel application

Read the post →
The Seven Restful Controller Actions in Laravel

The Seven Restful Controller Actions in Laravel

Published 2024-05-05 — Updated 2024-05-16

Laravel

PHP

Web development

The seven RESTful actions and how you could implement them in Laravel

Read the post →