Deploying PHP and Mysql Apps on Heroku (success ok)
Last updated
Last updated
June 30, 2016
This tutorial will help you deploying a PHP and Mysql app.
a free Heroku account.
PHP installed locally.
Composer installed locally.
In this step you will install the Heroku Toolbelt. This provides you access to the Heroku Command Line Interface (CLI), which can be used for managing and scaling your applications and add-ons.
To install the Toolbelt for ubuntu/Debian
After installing Toolbelt you can use the heroku
command from your command shell.
Authenticating is required to allow both the heroku and git commands to operate.
In this step, you will prepare a fossasia/engelsystem application that can be deployed.
To clone the sample application so that you have a local version of the code that you can then deploy to Heroku, execute the following commands in your local command shell or terminal:
If it is not a git repository you follow these steps
You now have a functioning git repository that contains a simple application now we need to add a composer.json
file. Make sure you’ve installed Composer.
The Heroku PHP Support will be applied to applications only when the application has a file named composer.json
in the root directory. Even if an application has no Composer dependencies, it must include at least an empty ({}
) composer.json
in order to be recognized as a PHP application.
When Heroku recognizes a PHP application, it will respond accordingly during a push:
A Procfile is a text file in the root directory of your application that defines process types and explicitly declares what command should be executed to start your app. Your Procfile
will look something like this for engelsystem:
Since our folder named public
that contains your JavaScript, CSS, images and index.php
file, your Procfile
would define the Apache web server with that directory used as document root.
In this step you will create the app to Heroku.
Create an app on Heroku, which prepares Heroku to receive your source code:
When you create an app, a git remote (called heroku
) is also created and associated with your local git repository.
Heroku generates a random name (in this case sharp-rain-871
) for your app, or you can pass a parameter to specify your own app name.
But Once you open http://sharp-rain-871.herokuapp.com/ we will not be able to view the site if there are database connections. We need to migrate the database using Cleardb
Migrating database
To create your ClearDB database, simply type the following Heroku command:
This will automatically provision your new ClearDB database for you and will return the database URL to access it.
You can retrieve your new ClearDB database URL by issuing the following command:
After getting the cleardb database url we can import the tables by following command:
than you well get a mysql prompt with connection to the database. Than you can import the tables using the following commands
Now the tables are migrated successfully.
Declare app dependencies
Since we have added the mysql database we need to add the dependencies also.
The composer.json
file specifies the dependencies that should be installed with your application. When an app is deployed, Heroku reads this file and installs the appropriate dependencies into the vendor
directory.
Run the following command to install the dependencies, preparing your system for running the app locally:
You should always check composer.json
and composer.lock
into your git repo. The vendor
directory should be included in your .gitignore
file.
Connecting to ClearDB from PHP merely requires the parsing of the CLEARDB_DATABASE_URL
environment variable and passing the extracted connection information to your MySQL library of choice, e.g. MySQLi:
we need to modify it in the config/config.php file
All the steps are completed now we need to deploy it. Push the code to Heroku. For pushing pushing development branch we need to follow these commands.
Now your app is successfully deployed you can view it here http://sharp-rain-871.herokuapp.com/
Development: https://github.com/fossasia/engelsystem
Issues/Bugs: Issues