This tutorial is not for the faint of heart. There’s a lot of work in Terminal involved and if you don’t know what you’re doing, things can get very ugly, haha! Also, for your convenience, all links that look like this open in a new tab/window.
And to make it absolutely clear, I wiped my own VPS server in order to create this How To, which I then followed to the T to re-create it again! So it’s proven to work ;)
VPS setup and Jekyll installation
- get a VPS. I used Linode and used their VPS installation script to get started. Select Ubuntu 16.04 LTS as your Linux distribution.
- follow this tutorial to setup your Ubuntu OS with a non-root user with
sudoprivileges - you only need to complete steps one through three (unless you feel adventurous, in which case feel free to go the list all the way down :)). After you’re done, log out of your root session and log back in using the newly created user account.
- follow this How To to install Jekyll on your new VPS. See notes below that should help you overcome some shortcomings of that tutorial:
- Step 1: The
sudo apt-get install ruby ruby-dev make gccshould really be
sudo apt-get install ruby ruby-dev make gcc g++. Without the
g++installed, the gem command that comes next will not execute properly.
- Step 1: The
gem install jekyll bundlershould read
sudo gem install jekyll bundler- if you don’t include
sudoyou’ll get an error.
- Step 2: Your firewall may return
Status: inactive. At this point it’s best to leave it that way so it doesn’t interfere with installation but when you’re done, enable your firewall by entering
sudo ufw enableand then run
sudo ufw statusto see what rules (if any) are configured on your machine.
- Step 1: The
Now comes the fun part…
We’ll be doing four things here:
- Installing and configuring Dropbox on an Ubuntu server
- Setting up Dropbox folder monitoring, syncing files from the Dropbox monitored folder to Jekyll’s
- Installing Apache web server
- Setting Jekyll to automatically regenerate static
HTMLfiles and store them in the web root folder
Let’s get started…
Installing Dropbox on a Linux server
To install Dropbox, follow the instructions on Dropbox.
REMEMBER: Because you’re not logged in as
root, you will need to add
sudobefore the installation command so it’ll look like so:
`sudo wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -`
There’s no need to include the
cd ~ &&part as at this point you should be in your home folder, anyway.
After you finish authenticating, you’ll get a
This computer is now linked to Dropbox. Welcome User message. If you don’t see the usual
[email protected]:~$ prompt, just hit
ctrl + c to end the script.
In order to manage Dropbox on the server, you need to download their command line interface (CLI). Follow those instructions and don’t forget to start the Dropbox service so your folders and files can sync to your server.
To make sure the Dropbox service starts automatically each time you reboot your server, execute
~/bin/dropbox.py autostart y command.
Now, usually, people have more than one folder on their Dropbox account. Syncing it all to your server may pose a security risk (and takes up space on your server, too) so you either want to use a dedicated Dropbox account just for your Jekyll server or you can exclude the unneeded folders from syncing like so:
~/bin/dropbox.py exclude add Dropbox/FolderName
If your folder names contain spaces, add a
\ before each space, for example:
~/bin/dropbox.py exclude add Dropbox/Folder\ Name.
Make sure you create a folder for your Jekyll markdown files and that it’s being synced with your Dropbox folder on the server.
Setting up Dropbox folder monitoring
This part consists of two steps: 1. installation of
incron, 2. adding an
incron job that will trigger an external script each time a file is added/removed to/from the monitored Dropbox folder, or is updated.
sudo apt-get install incron command. Then you’ll need to edit a list of users allowed to run
your user name, each on a separate line. Save by pressing
ctrl + o, confirm, then press
ctrl + x to quit the editor.
incron job by executing
incrontab -e and entering the following:
/home/username/Dropbox/jekyllfilesfolder IN_MODIFY,IN_DELETE,IN_CLOSE_WRITE,IN_MOVE /home/username/copyfiles.sh
The above should be all on a single line. Make sure to replace
username with your actual user name and the
jekyllfilesfolder with the real name of your Jekyll folder you have created on your Dropbox account.
You can check the result by running
incrontab -l. It should display the line you entered into the
incrontab file earlier on.
Now we need to create that copyfiles.sh script. Create a new file:
Add this line to it:
`#!/bin/sh rsync -a /home/username/Dropbox/jekyllposts/ /home/username/www/_posts –delete`
Save and close file.
We’ll need to make it executable:
chmod u+rwx copyfiles.sh
Installing Apache web server
Jekyll on its own doesn’t do anything but generate static
HTML files from the markdown documents it grabs in its
_posts folder. In order for your visitors to actually see your blog (created from those static
HTML files), you need to have a working web server. You then copy the generated files into the web root folder. The good news is that this can all be done automatically…
To install Apache web server, follow another excellent tutorial on DigitalOcean
Setting Jekyll to automatically regenerate static
HTML files and store them in the web root
This is the last thing on the list to do. And it’s fairly easy, too. All you need is to edit
/etc/rc.local to have Jekyll’s build service start when the server reboots.
Before heading on to editing that file, let’s test if Jekyll and web server really work by going to your blog’s folder first (replace the
blogfolder with an actual name of where you installed Jekyll):
cd ~/blogfolder and then executing:
sudo jekyll build --destination=/var/www/html
Go to a web browser of your choice and enter your VPS’s IP address into the address bar. You should see a working test blog.
Now, go back to the Terminal window and let’s have that Jekyll command executed automatically after each server restart.
First, we need to create a shell script in our home folder. Run
cd ~ to go back to your home folder and then execute
#!/bin/sh on the first line, and enter the following on the second one (replace
username with your own user name):
sudo jekyll build --source=/home/username/www --destination=/var/www/html --watch
Save, close, and make executable:
chmod u+rwx startjekyll.sh
You can test the script by running
./startjekyll.sh. It should list a few lines about it starting with autogeneration, etc. When ready, hit
ctrl + c to stop the script.
We’ll reference this new script in the
/etc/rc.local file (anything placed into this file gets executed during start up sequence of your server).
Open the file with
sudo nano /etc/rc.local and just above the
exit 0 line paste
sh '/home/username/startjekyll.sh' (again, replace
username with your own user name). Test the result by executing
sudo /etc/init.d/rc.local start, you should get a
[ ok ] Starting rc.local (via systemctl): rc.local.service. response.
All done. Reboot your server to check everything starts up automatically.
You can't buy me time but you can if you'd like :) Thanks!