Skip to content

Instantly share code, notes, and snippets.

@lionrajkumar
Created August 8, 2022 17:22
Show Gist options
  • Save lionrajkumar/828bf441711956532ed0272c3ca97ea7 to your computer and use it in GitHub Desktop.
Save lionrajkumar/828bf441711956532ed0272c3ca97ea7 to your computer and use it in GitHub Desktop.
Deploy a PHP Website on Heroku

Deploy a PHP Website on Heroku

  • 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 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 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 your public/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 Composer vendor 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 on composer.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

Reference:

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
@lionrajkumar
Copy link
Author

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

@lionrajkumar
Copy link
Author

@lionrajkumar
Copy link
Author

Deploy Laravel + Vue.js project to Heroku
https://www.youtube.com/watch?v=pA33tNoVWGc&ab_channel=Pyronome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment