Categories
PHP

Deploying a Containerized PHP Application to AWS Using Docker and ECS

Since I’ve been playing around with Laravel Envoy, I kept wondering how I could improve the deployment process. For sure it works and I’ve been using it for 6 months or so on a project in production, but having to deal with a physical server has drawbacks I wanted to overcome. For example, the PHP team just released 7.4 packed with cool features I am eager to try. But on a physical server, one has to manually upgrade the PHP version, for each environment and this is a process prone to errors and can lead to different results in different servers. Logistically, the next step was to containerize the application. Because our application is running on an EC2 instance in AWS, I wanted to take advantage of the AWS ecosystem more.

On a high level point of view, this is what I ended up doing: the application is deployed in an ECS cluster running a task that contains a Docker image of the application. This image is stored in ECR. There is an ALB in front of the EC2 instances. The database is stored in RDS. The PHP sessions are stored in a Elasticache memcached server.

Categories
PHP

Modern PHP Development for WordPress

Let’s face it, WordPress’ reputation among PHP developers is atrocious. It is, for the most part, justified by the questionable code quality of most plugins (because the barrier entry is very low), the will of the core developers to keep backwards compatibility at all cost, and, as a result, its architecture.

However, as you may have noticed, this blog is running WordPress. Why would you ask me? Well, despite all its flaws, WordPress is stupidly easy to use and complete. I considered using Jekyll on GitHub pages but realized that I would miss many features that I like. I can have comments without relying on external services like Disqus, after all I start to appreciate Gutenberg, I do not have to rely on third-party providers for something as simple as a contact form… and I’m OK with running a server for my blog as it would run anyway.

That being said, there are a couple of things you can do to make your developer experience pleasant, or at least way less painful than you would think maintaining a WordPress website.

Categories
PHP

Using highlight.js on WordPress

I was looking for a replacement for the syntax highlighter I was using on my blog, since SyntaxHighlighter Evolved never really gave me satisfaction (unwanted advertisements next to the code blocks, poor styling).

Categories
PHP

Migrate Routines to Laravel

I had to work on a project that made heavy use of MySQL routines: stored procedures, views, functions and triggers. In the process of adding Laravel to the application, I found good packages to seed the database from existing data, create models from the existing schema and create migrations from existing tables.

Categories
PHP

Zero Downtime Laravel Deployments with Laravel Envoy

Recently, I was looking for a way to deploy a Laravel application with ease and no headache. After some time, I wrote a very basic Bash script to automate the common deployment tasks: pulling changes from Git, installing Composer dependencies, building NPM scripts, running migrations and so on. But it was still feeling primitive. There had to be a better way.