Just roll up your sleeves and do the work

Just roll up your sleeves and do the work

Yesterday, I got inspired to write this post while I was setting up a new droplet on DigitalOcean.

Two years ago, I had installed and created a droplet (server) running Ubuntu 14.04. The purpose of that server was to run a Laravel 4 application and serve the "admin" part of the website using a SSL certificate.

A few days ago, I received a feature request for that application and things quickly started to cascade for the worse.

Things that did not work

1. Application had packages which worked only on PHP 5

Because my local environment is running PHP 7.* on both my host PC and virtual machine, I could not execute a simple composer install to install the dependencies.

2. Some of the packages used do not exist anymore

I had a few private packages, which at the time of coding the application were being actively used, but today they are nonexistent.

3. Some packages were completely unnecessary

Packages like guzzlehttp/guzzle, way/generators, itsgoingd/clockwork , barryvdh/laravel-ide-helper and laracasts/testdummy.

Some of those package were not even used in the application. They were leftovers from the original application.

4. There were obsolete tests, and unused test frameworks

Codeception was installed and had a few tests which were obsolete. PHPUnit was installed by default, but the app/tests directory contained no tests.

5. Junk, junk everywhere

By junk, I mean unused files. A lot of development and research related files were included in the application. Since there were unused packages, there were also unused files.

6. Code was poorly formatted

This was probably my fault. My coding style changed a lot during the past two years, and nowadays I fix everything with php-cs-fixer to adhere to the PSR-2 coding standard.

Getting everything to work locally was a pain in the ass

After fixing all the packages, removing junk files and formatting the code, I had to clone the production database to test if everything works correctly. Everything worked except two tables which had two unused columns.

I had two fields on two tables which were not set as nullable. During the insert statement they would not receive any parameters; they would not even be mentioned in the insert statement.

This worked on the previous Mysql server version, but since I am running a newer version than I did two years ago, this throws an exception now. I did not even know that those two columns existed in those two tables. Somehow, during one of the migrations, I've completely forgotten to drop them. A quick new migration solved this issues and the application was working 100%.

How about the production server

As you may have guessed so far, the production server was running the same things as it did two years ago. Now, that I have upgraded the application to work on PHP 7 (The latest version of Laravel now supports PHP 7) there was an issue of upgrading the production server to use PHP 7 and other newer software.

The easiest way that I could think of was upgrading the server from 14.04 to 16.06 and then fixing the quirks.

STOP!

Good thing, that I have stopped and thought this thru. Upgrading a production server was a no-no. Alternative way was to create a snapshot of the droplet (server) and create a new droplet from that snapshot and then try to upgrade it.

But, how wise is it to upgrade a two years old server. I do not even remember what I have done to it two years ago. Hell, I can't remember what I had for lunch yesterday. Even if I managed to upgrade it, wouldn't it be best if I start over with a fresh installation of Ubuntu 16.04?

Doing the work

I was losing time just by thinking of how to upgrade the server. And then if upgraded, I would have to setup Let's encrypt on it to obtain SSL certificates.

"Sometimes it is easier to just do, that to think of different ways of doing things". Overthinking gets you nowhere.

Since I know my way around a server I decided to start from scratch:

  • Create a new droplet
  • Setup sudo non-root account with SSH keys
  • Install Mysql server and nginx
  • Install and configure PHP 7 and extensions
  • Install the repository
  • Setup Nginx sites
  • Obtain Let's encrypt certificates
  • Update Nginx conf for the site

And done!

A few quick tests that everything works and now to switch the old production server with the new, was just a matter of changing a few DNS records.

For me, it was much easier to setup a new server than to upgrade an old one and then try to fix all the kinks once they pop up. Maybe it is different for you.. let me know of your experiences.

Best regards and have a nice day!

Mario Bašić

About Mario Bašić

Sometimes backward to move forward. Always.