A starter kit for building a restful API in PHP, with server-side and client-side sample code

Image for post
Image for post

These days, if you want a scalable web application, at some point you’re going to have to consider building cloud-based API services, micro or otherwise, that allow your distributed applications the ability to share common functions.

This article is going to show you how to build a simple restful API in PHP. We’re going to build a server-side API that receives an API key from the client, connects to a MySQL database for the API Secret Key, and then returns a JSON Web Token (JWT) that’s secured with the Secret Key.

The client-side application is a simple PHP page that makes a call to the API to retrieve a token and then stores it in a cookie before writing out the page. The page itself includes some simple jQuery that allows you to delete the cookie and then retrieve a new token using the same API interface through JavaScript. The goal is to provide you a single page where you can see PHP and JavaScript code calling the same API. …


Breeze past this very common developer interview question

Image for post
Image for post

I’ve been writing PHP code since 2008. Over that time I’ve built all sorts of applications for all sorts of purposes. When you write code for that long, you find yourself creating a library of tools, utilities, and snippets of code that you use over and over. After a while, you discover you’re reusing code you wrote years ago and now don’t remember how it works or why, or even if there might be a new and better way. Your old reliable code just does what it has always done and works, so you use it and don’t ask questions.

Recently, when someone asked me to explain the difference between an interface and an abstract class, I realized I couldn’t answer the question (at least not intelligently). …


Over the last decade my first software startup failed. Then I co-founded one that had a successful exit. Here’s what I learned from that.

Image for post
Image for post
Photo by Andrew Neel on Unsplash

Now that we’re into 2020, I find myself thinking back over the past 10 years and reflecting on all the things I’ve learned about software startups. Good and bad. There have been some soul crushing low points and wild-ride high points. But when considered with the whole, even the failures had some good in them too.

At the end of 2010 my first software startup, which I founded in 2008, came to a dismal end. I had an idea for a ride sharing app that used the Google Maps API to pair people who had cars with people who needed rides. I had investors, built a proof of concept, had people use the web app and got local news coverage. But ultimately, I couldn’t figure out how to monetize it. …


Here’s a list of easy setup tips I always apply to make my life better on my macOS machines.

Image for post
Image for post
Photo by Tianyi Ma on Unsplash

Here I am on Christmas Eve setting up the new Macbook Pro 16" that I bought with a trade-in of the 2018 Macbook Pro 15" I got last year. The bigger screen (in more or less the same sized frame), the r̵e̵s̵u̵r̵r̵e̵c̵t̵e̵d̵ … er … revitalized keyboard and the snappier multi-core processor were all too compelling to ignore.

Of course, I’m going to “eat what I cook” and use my own instructions from my article “PHP: How to Run Your Entire Development Environment in Docker Containers on macOS” to get my dev environment up and going. …


A step-by-step guide to creating a PHP 7.2 localhost, MySQL 8 server, and Redis server development environments using Docker containers

Image for post
Image for post

I’ve written several articles about setting up a PHP localhost development environment on various macOS machine versions using Homebrew, including a couple of articles for running MySQL 8.0 in a Docker container.

Now that I’ve upgraded to macOS 10.15 Catalina, with its read-only file system volume, I decided to lift my development environment entirely off of macOS and run it inside Docker containers. This opens up all kinds of possibilities. First, not only should I be able to run the exact same development environment across all version of macOS, but I should also be able to run these exact same containers on Ubuntu desktop if I chose to—or any other OS capable of hosting Docker. …


Part two of an updated two-part series to set up an Apache/PHP development environment on macOS Catalina

Image for post
Image for post
Image source: Casey McMullen

This piece is for web developers who want Apache and PHP installed as part of their development environment setup on their Mac.

Make sure to check out Part One, How To Install Apache on macOS 10.15 Catalina Using Homebrew, which is a pre-requisite for this piece.

In the past, I used to rely on the version of Apache and PHP that came pre-loaded with the OS on my MacBook Pro. I would then install the PHP extensions I needed (Xdebug, Redis, etc.) from Homebrew.

As of April 1, 2018, Homebrew deprecated the Homebrew/php tap in favor of a new Homebrew/core approach. In addition, although some critical extensions are still supported (e.g., MySQLi), most PHP extensions are no longer distributed through Homebrew at all (php72-xdebug, php72-redis, etc.) …


Part one of an updated two-part series on how to set up an Apache/PHP development environment on macOS Catalina

Image for post
Image for post
Image source: Casey McMullen

This article is targeted towards web developers who want an Apache web server install as part of their development environment setup on their Mac.

This piece is a pre-requisite to the next one in the series, which will walk you through installing PHP using Homebrew and PECL.

This approach to installing Apache disables the version that comes preinstalled with macOS, allows more flexibility for versioning, and will continue to work across all macOS versions.

These instructions will work the same for all current versions of macOS. Also, you don’t have to start with a fresh OS install to use the information here, but I’ve been seeing some weird things happen when upgrading vs. doing a fresh install (e.g., completely missing the mod_deflate.so module extension file entirely after the upgrade). …


Part one of a two part series to set up an Apache/PHP development environment on macOS

Image for post
Image for post

This article is targeted towards web developers who want an Apache web server install as part of their development environment setup on their Mac.

If you’re a PHP developer, then this article is a pre-requisite to the next article which will walk you through installing PHP using Homebrew and PECL. A link to that article can be found at the bottom of this page.

As a developer, I used to rely on the version of Apache that came pre-loaded with the OS on my MacBook Pro. With the ever changing security rules in macOS, I’ve decided to change my whole approach and instead disable the distributed version of Apache and use a setup entirely from Homebrew. …


This article will show you a simple query example in MySQL 5.7 (along with an example using the rank() function in MySQL 8.0) that will return the top 3 orders per month out of an orders table.

Image for post
Image for post

If you’ve ever wanted to write a query that returns the top n number of records out of a group or category, you’ve come to the right place. Over time I’ve needed this type of query every once in a while, and I always wind up with either an overly complex multi-query union effort, or just iterate through a result set in code. …


This article will show you the steps to run MySQL 8.0 in your macOS development environment with mysql_native_password rather than caching_sha2_password

**NOTE** This article focuses primarily on running MySQL 8.0 in a Docker container. You can learn how to do this by first visiting my other article, “How to Run MySQL in a Docker Container on macOS with Persistent Local Data”. However, the tips you learn here will help you if you’re running MySQL locally on your Mac.

**SECOND NOTE** Update Dec 14, 2019: I updated the linked article above to make permissions handling much easier. …

About

Casey McMullen

Startup Entrepreneur. Internet Software Developer. Classic Rock Guitar Player. Harley-Davidson owner.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store