Chris Wiegman

Opening Common WordPress Tools with Makefile

Automating WordPress Development with Make

This summer I’ve talked about automating WordPress development with Make and gave a few ideas for Make targets to get you started. Today I want to add a few more Make targets to that list.

Two of the most common tasks I need to do when working with a few sites locally is to open them in my browser (URLs can get confusing when you have a few sites going) and opening the database directly in my database app of choice, TablePlus. Here are two Make targets you can use to do so yourself.

Opening a site in your browser with Make

The first target we want to add is open which simply serves to open the current site in your browser. The example below will open the specified URL (it should be set to your site’s URL for the current project) in your default browser when typing make open.

.PHONY: open open: ## Open the development site in your default browser open
Code language: Makefile (makefile)

Opening your database in TablePlus

This next target will instantly open your site’s database in TablePlus so it can be examined or edited directly. This is handy as, otherwise, the configuration required to open a site in a tool can be difficult when using something like Lando or another tool.

.PHONY: open-db open-db: ## Open the database in TablePlus @echo "Opening the database for direct access" open mysql://wordpress:wordpress@$$(lando info --service=database --path 0.external_connection.port | tr -d "'")/wordpress?enviroment=local&name=$database&safeModeLevel=0&advancedSafeModeLevel=0
Code language: CSS (css)

When running the command make open-db you will get access to your database. Note this uses a simple database configuration in WordPress itself. The username, password and database name configured for the database are all simply “wordpress.”

Of course, you will need to edit these if your tools differ but, hopefully, this post serves as another example of the power of using Make for development.