-
Install the Heroku Command Line Interface (CLI)
-
Use the
heroku login
command to log in to the Heroku CLI -
Check if you have PHP(
php -v
), Composer(composer -V
), & Git(git --version
) installed -
Clone your Package
git clone https://github.com/heroku/php-getting-started.git cd php-getting-started
-
Commit a text file to your app’s root directory that is named
Procfile
without a file extension. For example, if you have a folder namedpublic
that contains your JavaScript, CSS, images andindex.php
file, yourProcfile
would define the Apache web server with that directory used as document root as follows:web: vendor/bin/heroku-php-apache2 public/
-
(Optional) Add
app.json
file to your app’s root directory. If you want add any Heroku Addon{ "name": "AuthorName : My Portfolio", "description": "My first portfolio deployment in Heroku", "repository": "https://github.com/{GitHub-Username}/{portfolio}", "addons": [] }
-
Heroku uses Composer for dependency management in PHP projects. If your app has any dependencies, the
composer.json
file should specify them. It will look something like this:{ "name": "AuthorName/my-package", "authors": [ { "name": "AuthorName", "email": "your@email.com" } ], "require" : {}, "require-dev": { "heroku/heroku-buildpack-php": "*" } }
-
Your PHP app can then make use of the dependencies that Composer installed. Dependencies are usually installed to the
vendor/
directory after including the autoloader generated by Composer, Add the below line in yourpublic/index.php
, typically like this:require('../vendor/autoload.php');
-
Install / Update the package dependencies. To generate your
composer.lock
file, make sure you have Composer installed and then type:composer update
-
After updating your dependencies and re-generating the lock file, don’t forget to add and commit the changes to your Git repository:
git add composer.json composer.lock git commit
-
Prevent build artifacts from going into revision control by creating a
.gitignore
file. The Composervendor
directory should be included in your.gitignore
file. This keeps repository sizes small, simplifies dependency updates, and allows Composer to reliably install an application’s dependencies based oncomposer.lock
Here's a typical.gitignore
file:vendor/ .env
-
Run below commands
git add . git commit -am "Commit message" heroku create git push heroku master heroku open
Tuts | Ref |
---|---|
Heroku Login | https://id.heroku.com/login |
Heroku-PHP Integration | https://devcenter.heroku.com/articles/getting-started-with-php |
Heroku-PHP Code base Preparation | https://devcenter.heroku.com/articles/preparing-a-codebase-for-heroku-deployment |
Heroku-PHP Sample PHP Code | https://github.com/heroku/php-getting-started |
Setup Custom Domain in Heroku | https://devcenter.heroku.com/articles/custom-domains |
For connecting MySQL with PHP application in Heroku
Reference:
Youtube: How to Deploy a PHP and MySQL Website on Heroku And Configure the Database
Blog: Doable Danny