i like using a VPS for my websites. i like that i get to manage it mostly however i want. i liked having to learn how to do it properly and then being able to customize that to my own needs.
(i use Vultr for my VPS hosting - this IS a referral link, i get credit to my account if you sign up via this link. you can go directly to Vultr instead if you'd like.)
in managing my VPS i have acquired some important pieces of code or configuration that are very helpful to me, and they might be helpful to you!
update.sh
the first is a shell script. this kind of thing was intimidating at first, but it was actually really easy to compose. it's basically just a collection of commands i would run in the terminal anyway, so i can run this one script instead of typing all that shit.
#!/usr/bin/env bash
# exit when a command fails
set -o errexit
# shows each line as it's executed
set -o xtrace
# update, upgrade, dist-upgrade, autoremove: these do a full update of your system
apt-get update
apt-get upgrade
apt-get dist-upgrade
apt autoremove
# print system info
landscape-sysinfo
i keep it saved as update.sh in my root home folder and generally run it as cd ~ && yes | ./update.sh. it is necessary to chmod +x this file before use, otherwise it doesn't run as a script. (chmod +x grants execute permissions to the user, so you can execute the file.)
domain.conf
the next is a configuration file that is commonly used in servers with Apache web server software installed, which is what i use on my VPS to display my websites. (there is also NGINX which i have used in the past, but i prefer Apache because it has some tools available that NGINX doesn't have that make managing my websites easier, like PHPMyAdmin. (i think there are PHPMyAdmin alternatives that do work with NGINX, but i don't know how to set them up and i do not want that project right now.)
this configuration file allows a website request to be served correctly. that is, when a browser accesses http://example.com, if you have successfully set up your DNS so that example.com points to your webserver, this file tells the browser, "display the files in This Folder," and other things.
<VirtualHost *:80>
ServerName your_domain.com
ServerAdmin webmaster@localhost (or your email)
DocumentRoot /var/www/your_domain
ErrorLog /var/www/your_domain/error.log
CustomLog /var/www/your_domain/access.log combined
</VirtualHost>
this is a very basic configuration file. i like to start with this, because when i use Certbot to set up SSL, it'll add that information to the end of this configuration file. keeping it simple makes it easier to read in the end, and in case we need to change it later that can be important.
this file also lets you point the server where to put your access and error logs. this can be really helpful to know if you run into issues with your website! i use PHP and PHP-based programs for my sites, so their error logs can be really helpful to figure out what's wrong when things don't load correctly.
this file is most commonly saved as example.conf where example is your domain. i sometimes save it as example.com.conf but that's just a personal quirk, particularly because i use a lot of aesthetic TLDs.
this file gets saved in your /etc/apache2/sites-available folder, edited to reflect your domain (ServerName) and file location (DocumentRoot and so on). you then must run a2ensite [domain].conf to enable it, and then systemctl reload apache2 (or however your particular system reloads apache).
DigitalOcean
finally i'd like to provide you with a set of links to some DigitalOcean tutorials i've found invaluable when working with my VPSes over the years. most of these give you an option at the top to change what server you're installing them for, in case you choose something other than Ubuntu.
- Initial Server Setup with Ubuntu - this will show you how to do basic stuff with your new server, like make a new user and set up the firewall.
- How To Install LAMP Stack (Apache, MySQL, PHP) on Ubuntu - this guides you to installing some of the most important software for hosting websites on your server. there is also an NGINX version! i do advise trying both NGINX and Apache and seeing which you like best, if you have the time and desire to do so!
- How To Secure Apache with Let's Encrypt on Ubuntu - this is the article from before on Certbot, but i'm repeating it here for ease of reference. very easy way to keep your sites secure! (and, there's also an NGINX version.)
- How to Create a MySQL User and Grant Privileges (Step-by-Step) - more niche because not everyone will be using MySQL but it's a very useful tool and necessary for some web programs like Wordpress or most wiki softwares.
i hope this page was helpful to you in your website journey, and i hope you play with a VPS if you can afford to. it can be a very fun and rewarding experience for webmasters.

