During this past Black Friday sales event, I was able to pick up a $1/year vps from Gullo’s Hosting with a promo code. (You can no longer get them for that cheap. Now they are available for $3.5/year) The specs for this VPS are very limiting:
- NAT IPV4 (20 ports)
- 128MB RAM
- 1 vCore
- 3GB HDD
- 125GB BW
The most limiting factor for this server is going to be RAM, which I quickly found out after I had Centos 7 pre-installed. The package manager, yum, could not install any server packages such as PHP, or Nginx. It would run out of ram. I didn’t want to revert to a much older distro because I wanted to also use the latest packages and continue to get updates. There is one distro I found which is up to date and works flawlessly on 128MB of ram: Alpine Linux.
Now I needed to get Alpine onto my VPS. You can’t get it pre-installed in most cases so you’ll have to side-load it by erasing everything in / and replacing it with an Alpine base system. Luckily this is very easy if you use an existing script which is available here. You only need to copy that script to your disk and then execute it. It will automatically erase everything and replace your distro with Alpine Linux. This worked flawlessly on Centos 7. Also, before you erase everything you may want to check on your IPv6 settings since you will need to set those again manually after reboot.
Once you’re in your new Alpine Linux VPS, there are a few things you may need to do to get it fully working.If you notice there are a lot of error messages in /var/log/messages about /etc/inittab then you should try:
apk add e2fsprogs-extra chattr +i /etc/inittab
I don’t know what that does, but it makes the errors go away. Next you’ll need to configure your IPv6, which you will need to use when you configure a reverse proxy for web hosting. Open up /etc/network/interfaces and add the following lines:
iface venet0 inet6 static address abcd:123:456:7890:ef::abcd netmask 80 gateway abcd:123:456:7890:ef::1 pre-up echo 0 > /proc/sys/net/ipv6/conf/venet0/accept_ra
Remember to change the bold areas to what’s relevant to you. Your hosting provider should give you what IPV6s you have, you need only pick one for yourself. Reboot or restart networking. Make sure you are able to ping your IPv6 address. If all is working then you may setup your hosting. I prefer Nginx because it’s fast, scales relatively well, and doesn’t use too much ram. With only 128MB of ram that limit is going to be hit if enough people are using your server, the goal here is to keep the server working under normal load. And to use an aggressive caching policy so the server can even handle usage spikes.
You can follow the guide to installing nginx and php on Alpine Linux. I went with PHP7. You’ll definitely want to lower your PHP_MEMORY_LIMIT, I used 64MB. I am not going to install mysql because that takes far too much memory. Instead, for any database needs I use another offsite mysql server. Because this will increase the time it takes to deliver pages dramatically, I need to enable aggressive caching. Those changes (and some other unrelated preferences I have) are to the nginx.conf file. this is commented nginx.conf I use.
Now that you have your hosting setup, you will need to make it accessible to the outside world. Since this server is behind a NAT and only has an IPv6, you will need to use a reverse proxy. CloudFlare provides this service free of charge. All you have to do is:
- Make a free account with CloudFlare.
- Tell CloudFlare what domain you want them to manage.
- On your domain registrar, change the DNS to CloudFlare servers.
- Configure two AAAA records on CloudFlare. one with “@” and another with “www” as the names. Both should point to your IPv6 address.
- Remove any other A or AAA DNS records which point to a parking page or somewhere other than your server.
- Make sure CloudFlare is on and it is configured to cache and act as a reverse proxy for your server.
You should now be able to access your web host through your domain! Another advantage of CloudFlare is they are a full CDN which will provide additional caching for your website which will increase the speed and reduce the bandwidth requirements from your host.
This is how I was able to turn a dirt cheap $1 VPS into a fairly fast and reliable website hosting machine. In fact, with hosting this cheap, by far the largest cost is the domain registration. Also I cheated a bit and didn’t use a local MYSQL server since you’re definitely going to have trouble with that on 128 megs of ram. But still, I was able to turn an extremely limited server that cost the same as a Jr. Bacon Cheeseburger in the early 2000s into something that can actually be used for my businesses.