How to build a CRUD App on Heroku with Php & Pdo & Github Deployment & ClearDB & MySQL Workbench

Mert Kadir Gursoy
5 min readMar 6, 2022

Let’s begin with Heroku.

“Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.”

Developers can easily deploy their application from Github and configure MySQL Database with its free plan.

So, we will deploy our CRUD Application from “Github” to “Heroku” and then connect to the MySQL database via ClearDB Add-on and MySQL Workbench with the following steps below.

HEROKU ACCOUNT

  • Firstly, we need to create a Heroku Account.
  • Once you create your account in Heroku, select the free plan.
  • Now we are able to create our app from the following “/new-app” link below.

A NEW APP ON HEROKU

  • Create a new app with the button on top right.

https://dashboard.heroku.com/apps

CLEARDB & HEROKU

In order to make our app dynamic, we need to connect our CRUD App to MySQL Database via ClearDB Add-on before configure MySQL Workbench Tool.

  • In Heroku Dashboard, select “Resources” tab.
  • Click “Find more add-ons” button.
  • Now, search this text “ClearDB” and click on it.
  • “Install ClearDB MySQL”
  • Select Add-on plan & Connect it with your Heroku App (that we created above).
  • You should be able see this now in your “Resources” tab in Heroku Dashboard.
  • Click “Settings” Tab now.
  • Now scroll down and click “Reveal Config Vars”
  • Copy the link that indicated below.
  • Split the url like this below.

We will use these “UserName”, “Password”, “HostName” values in MySQL Bench now below.

MySQL WORKBENCH TOOL

In order to use ClearDB Add-on in Heroku, we need to install MySQL Workbench.

  • Install MySQL Workbench Tool from following link below.
  • Once it’s installed open MySQL Workbench and click the “Add” button.
  • Add the values that we kept in “UserName”, “Password”, “Hostname”.
  • Test the connection now.

If “Successful Message” box show up, it means Database connected to App.

  • Open Database by clicking it.
  • Once it is opened, select “File > New Query Tab”.
  • Run your SQL Commands in this like this “Create “Users Table” and other Tables.
CREATE TABLE users (
user_id INTEGER NOT NULL
AUTO_INCREMENT KEY,
name VARCHAR(128),
email VARCHAR(128),
password VARCHAR(128),
INDEX(email)
) ENGINE=InnoDB CHARSET=utf8;
  • Insert a User and other required row items if it is needed.
INSERT INTO users (name,email,password) VALUES ('test','test@theemail.com','123');
  • Copy UserName, Password, HostName(in Resources Tab > Reveal Config Vars)
  • Also copy database name in MySQL Benchwork > Schemas
  • Update your “PDO Credentails” (pdo.php) with the following ones above that we already have (UserName, Password, HostName, DatabaseName) .

Pdo.php

DEPLOYMENT (Github To Heroku)

  • Select “Deploy Tab”
  • Select “Connect Github”
  • Search CRUD App Name (in Github Name) then connect it.
  • Finally, you scroll down and click “Deploy Branch”.
  • You should have the following success message like this below.
  • Now you can view your app in browser by clicking “View” button.

Congratulations. You have just built your own CRUD App successfully.

--

--

Mert Kadir Gursoy

Product Team Lead | Product Management ~ Product Design ~ UX Research ~ Technical Project Management