Beta Blockers

It’s been a busy week here at CodeReviewVideos.

I want to thank everyone who tried out the site in the “beta” test. This has now ended, and I’m ready to launch the new site version. Hooray.

The only reason to delay now is that I’m away all weekend (more on this below), and as such, don’t want to launch on a Friday. Instead, the launch will likely be Tuesday, all things being equal.

There’s a bunch of tasks for the launch – it’s not quite as straightforward as I’d like. The hardest part is around migrating the database. I’ve changed the structure quite a lot between versions, and keeping both in sync across two different servers is proving… interesting.

There have been so many lessons learned during this process. Just this week I realised none of the pages had HTML head tags. Whoops. But then it turns out populating these tags from an API response isn’t super straightforward either. There’s no server-side rendering to help me 🙁

Another problem that caught me totally off guard was the sitemap.

Being that CodeReviewVideos is an existing, live site I know that whatever SEO ‘stuff’ I have in place already must be mirrored to the new site.

What I hadn’t thought through was the location of the sitemap.xml  file.

In the current iteration, I’m using Symfony with Twig. Everything lives on one server, and as such, making the sitemap is really straightforward. I use a bundle (PrestaSitemapBundle) and it just works.

For the new site there are two areas where pages may come from:

  • Static pages – i.e. the FAQ, contact / support, privacy policy, etc
  • Dynamic pages – i.e. the Course / Episode pages

There are some libraries available that will help generate sitemaps for React-based projects. I looked at each in turn but none seemed to fit my needs. I found this odd, honestly, as surely I’m not the first person to meet this problem.

Instead, I decided to roll my own. Well, I say “roll my own”, but really it’s a combination of some Doctrine query output dumped into Samdark/sitemap.

This worked really well, but.

It’s a big but.

The sitemap is generated on a sub-domain – under api dot codereviewvideos dot com.

Apparently, having done some research, Google ain’t so keen on this. They want the sitemap to live on www dot codereviewvideos dot com.

The problem being that behind the scenes these are two entirely separate concepts. Both are Docker images with all the necessary data “baked in”. How could I dynamically generate a sitemap from one, and it appear on the other?

Well, it turned out Docker Volumes came to my rescue. I could bind mount a file on the underlying host, and make the file appear as though it were on the www site automatically.

There have been an absolute ton of unexpected surprises like this along the way.

Video Update

This week saw three new videos added to the site.

#1 – Docker MySQL Tutorial

There’s a school of thought that says Docker and Databases don’t make good bedfellows.

For my money, this debate is really only worth having if you’re heading into production. If you’re simply wanting to play around with a database, or you have some local development work to get done, then Docker is perfect for the task.

In this video you will learn how to quickly spin up a working MySQL database server, in almost no time at all. Once you’ve got the latest MySQL Docker image stored locally on your computer, getting a new container up and running takes seconds.

As with almost anything Docker related, there are a few potential gotchas. It’s really all about reading the instructions (or the docker logs  output) if things don’t go according to plan. In particular here, you will need to use one of the mandatory environment variables.

We finish up this video by taking the example docker run command provided in the docs, and turning it into a more practical, usable variant along with storing our database on a named volume.

#2 – Docker nginx PHP Tutorial

Getting MySQL up and running was fairly easy going. And earlier in this series we saw how we could quickly spin up a Dockerised nginx server without much effort, either.

However, beyond some simple examples, the truth is you will need to do quite a bit more to get a working development environment that replicates Vagrant or some Ansible-managed VM infrastructure.

The way we will work through this is to separate nginx from the actual application code. In other words, nginx, php, and our Symfony site will all be separate Docker images.

On the surface of it, this seems like we’re going a little overkill. However, stick with me through this, and the next two videos, as this approach has served me well in the real world.

#3 – Docker PHP 7 Tutorial (7, 7.1, and higher)

As covered in the previous Docker nginx tutorial, our stack will be split across multiple Docker images and containers.

We’re going to let nginx accept incoming requests for our PHP-powered site(s), but the nginx container won’t know how to process PHP code. Instead, it will hand off to a dedicated PHP-processing container.

For our purposes we are going to create a PHP 7.1 image. This will be relatively generic, containing all the stuff most every PHP site will need. This will include a bunch of system level dependencies such as curl , and git , through to PHP deps such as intl , pdo_mysql , and optionally xdebug .

However, we won’t directly use the PHP image we create. Instead we will use this as the starting point for all future PHP Docker images. For example, in the next video we will use it as the basis of a Symfony image. But I also use the image as the base for WordPress, and custom PHP projects too.

PHP North West

This weekend I will be at PHP North West. If you are heading to PHP North West then please say hello 🙂 I already know a few of you will be attending, and I’m looking forward to meeting up in person.

The other reason I mention this is that support response times may be a little slower than usual. Apologies in advance if this causes you any inconvenience.

This will be my fourth year attending PHP North West, and whilst I didn’t blog about my first visit (not sure why), I did capture the previous two. Expect similar for PHPNW17 some time next week.