Host PHP website on heroku - CLI using Ubuntu machine

UpdatedUpdatedOctober 07 - 2017October 07 - 2017

How to setup the environment on a local Ubuntu server to develop and test a PHP website and later publish the website on heroku platform.

Install git on an Ubuntu machine
Install composer
Install Ubuntu - PHP7.0 - Apache2 - ssh
Install heroku cli
Write composer file to create environment on heroku
Create a heroku app from cli
Create PHP environment with necessary extensions and push all files from local Ubuntu machine to heroku app

Install Git:

$ sudo apt update
$ sudo apt install git

Install Composer:

$ sudo apt install composer

Install Ubuntu - PHP7.0 - Apache2 - ssh:

You can manually install the packages. Or, you can use my script to automate the process.

$ wget
$ chmod +x
$ sudo ./

Install heroku cli:

For Ubuntu 64-bit machine:
$ wget -O heroku.tar.gz

For Ubuntu 32-bit machine:
$ wget -O heroku.tar.gz

$ tar -xvzf heroku.tar.gz

Make directories:
$ sudo mkdir -p /usr/local/lib /usr/local/bin

Move heroku-cli-xxx:
$ sudo mv heroku-cli-v6.x.x-x-linux-x64 /usr/local/bin/heroku

$ sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku

Verify the installation:
$ heroku --version

Organize the php pages:

Create any directory directoryName. Inside directoryName, create public directory and place your php website in public directory.
Inside directoryName but outside of public directory, create the following files-


		"php": "~7.0.22",
		"ext-mbstring": "*"


web: vendor/bin/heroku-php-apache2 public/

Create composer.lock file:

Execute the following inside directoryName directory.

$ composer update

Directory structure will now look like this:

|--- directoryName
|--------- Procfile
|--------- composer.json
|--------- composer.lock
|--------- vendor
|--------- public
|--------------- php pages

Delete vendor directory:
$ rm -rf vendor

Create a heroku app:

cd into directoryName

Login to heroku:
$ heroku login

Create heroku app:
$ heroku create appName

Confirm that a remote named heroku has been created:
$ git remote -v

Push all files to heroku:

cd into directoryName

Initialize git:
$ git init

Add all files and directories into git:
$ git add .

Commit with meaningful message into git:
$ git commit -m "initial commit"

Add the remote app to the local git:
$ heroku git:remote -a appName

Deploy code from Ubuntu local machine to heroku app:
$ git push heroku master