How to build a CRUD App on Heroku with Php & Pdo & Github Deployment & ClearDB & MySQL Workbench
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.
- Firstly, we need to create a Heroku Account.
Heroku | Sign up
Create apps, connect databases and add-on services, and collaborate on your apps, for free. A platform for apps, with…
- Once you create your account in Heroku, select the free plan.
Pricing | Heroku
Heroku offers simple, flexible pricing to meet the needs of every app and every organization. Add data stores, cloud…
- 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.
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.
MySQL :: MySQL Workbench
MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. MySQL Workbench provides data…
- 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
) ENGINE=InnoDB CHARSET=utf8;
- Insert a User and other required row items if it is needed.
INSERT INTO users (name,email,password) VALUES ('test','firstname.lastname@example.org','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) .
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.