TIL: Installing YOURLS on an AWS Lightsail Instance using Nginx
Back in 2015, I bought the domain ‘livi.link’ to use as a shortlink domain. Why? It’s freaking adorable, and it meant that I could leave links around the internet that would be immediately identified as mine. I set up a bit.ly account with Twitter authentication, and used “livi links” for years.
Then, I deleted my Twitter account, and forgot to detach it from my bit.ly account. Oops.
Yesterday, I wanted to make a short link for my ‘Good AI’ anthology download, and finally cared enough to investigate whether it would be easy to move my domain over to a new bit.ly account. It turns out, now that’s a paid account feature, and Zach recommended YOURLS to me, an open source project that I could run on my web server to host my very own short link service.
I use AWS Lightsail for my web server. I find it to be intuitive and easy to work with, and gives me enough capabilities without overly complicating things that I have yet to run into a major blocker. I already have WordPress installed on the server, so I decided to stick with nginx and MySQL for my YOURLS installation. The default docs suggests using Apache, so I found this tutorial: https://linuxstans.com/how-to-install-yourls/, on the YOURLS-awesome repo of tutorials, and adapted it to fit my existing configuration.
Because I already had an nginx server for this website, I skipped the first three steps of the tutorial. I also chose to use MySQL instead of MariaDB, since it was also already installed and it turns out all the queries are basically the same.
Creating the Database and Downloading YOURLS
I probably have bad MySQL hygiene, but instead of signing in with
root using the
mysql -u root -p command, I just used
sudo mysql to create the database for YOURLS and the user. The original strong password that I generated had some characters in it that seemed to break the act of setting the password for the user, but when I tried a somewhat simpler password, it was fine, so that’s something to watch out for if you’re new to MySQL.
I downloaded YOURLS into a subdirectory under
/var/www/html/YOURLS because I have a few other services that I’m running. I conveniently forgot the ending
. on the
git clone command, which meant it got installed into its proper place and I didn’t accidentally try to overwrite my existing websites.
I followed steps 8 and 9 in the tutorial (for step 9, using the sub-directory noted above), moved on to step 10, and then had to make some changes to my DNS servers and Lightsail configuration so that the endpoint could be hit from a separate client.
Updating Lightsail & Namecheap
Lightsail makes DNS setup really straightforward, which I appreciate greatly. The first thing I tried (which didn’t work) was to use the same name servers that I use for this site and put them on my livi.link domain. In hindsight, it’s more evident to me why this didn’t work, even though both sites reference the same static IP address, but I didn’t realize why this wouldn’t work until the browser window helpfully told me that the certificate on the server that I was trying to reach was good for a different URL.
I went into Lightsail and made a new DNS zone under ‘Domains & DNS’. This time, it gave me different name servers to put into my Namecheap config, which I did. The DNS record change propagated fast – by the time I flushed the browser DNS history, it was up and running and I was able to get the SSL certificate added.
Once I was able to reach the endpoint to install YOURLS, I discovered the aforementioned password issue with the MySQL user and changed it to something with legal characters. I was then able to sign in and make my first short link using livi.link, all on my own server!
A few things in retrospect
I’ve been running this blog on various cloud providers for almost ten years, and have a degree in computer science. Yet, this is the first time that I used this particular stack and got my own configurations working. I was talking to Zach about how I feel like use of Windows (and later Azure) throughout my education and early career hampered my ability to deeply understand how all of the pieces of an operating system and server fit together by abstracting out certain pieces. I’ve never been happier with my computing experience since switching to running Linux full-time, and I am sure that the experience of running Linux on my desktop for the past several months is what has given me the patience and understanding of how to more confidently navigate web servers and databases.
A challenge that I faced in school (minor shade here to Virginia Tech, which I’ll say does have a really solid CS program) is that my classes never really glued pieces of the software development stack together. They also required us to have convertible Windows tablet computers. I took classes on algorithms and data structures and learned how to implement
alloc in C, but never was explicitly taught about file systems and how to work with data in a meaningful way, especially in practice. I’m sure that’s changing now, but at the time, I would have found a lot of value in someone teaching me how to do things on a local machine instead of going through hosted web services or filling in empty blocks of space in pre-setup programs.
I’m *finally*, 32 years in, starting to think about my web server and my computer beyond the content that I can produce with them. I finally feel empowered to look at a tutorial and figure out how close it is to my existing setup, rather than just trying to start and follow them completely from scratch. It’s delightful, and something I hope more people start to find true for themselves.
Anyway. Baby Fox is going to be on Arch, and that’s final.
Update: the first thing I did with my shiny new URL shortener was rick roll Zach.