# How to Deploy a PHP App on Heroku in 2026 (Apache, Nginx, MySQL)

> Deploy a PHP app on Heroku in 2026. Covers Composer, Apache vs Nginx, PHP versions, MySQL, Postgres, common errors, and better alternatives.
- **Author**: team-kuberns
- **Published**: 2026-05-11
- **Modified**: 2026-05-11
- **Category**: Deployment Guides
- **URL**: https://kuberns.com/blogs/deploy-php-on-heroku/

---

Heroku has supported PHP since its early days, and in 2026 it still does. PHP 8.2 through 8.5 are all supported, frameworks like Laravel and Symfony work out of the box, and the deployment process follows the same Git-based workflow as every other language on the platform.

That said, deploying PHP on Heroku involves more manual steps than most tutorials show. You need to configure Composer correctly, write a Procfile, choose a web server, wire up a database through an addon, and handle environment variables yourself.

This guide walks through every step clearly, covers the common errors that trip people up, and shows you a faster path at the end if you want to skip the config entirely.

## Prerequisites

Before you start, make sure you have the following in place:

- PHP 8.2 or higher installed locally
- Composer installed and available in your terminal
- Git installed and your project in a Git repository
- Heroku CLI installed and logged in (`heroku login`)
- A Heroku account on the Hobby plan minimum. The Eco plan will put your app to sleep after inactivity

> Not on Heroku yet? [Here is what Heroku is, how it works, and whether it is still worth using in 2026.](https://kuberns.com/blogs/what-is-heroku/)

## How to Deploy a PHP App on Heroku

![Step by step guide to deploy PHP on Heroku](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/guide-to-deploy-php-on-heroku.png)

### Step 1: Prepare Your PHP App

Heroku detects PHP applications by looking for a `composer.json` file in the root directory of your project. This file is required even if your app has no dependencies.

At minimum, your `composer.json` can be an empty object:

```json
{}
```

If your app does have dependencies, they should be declared in `composer.json`. You also need to specify the PHP version you want Heroku to use:

```json
{
  "require": {
    "php": "^8.4",
    "monolog/monolog": "^3.0"
  }
}
```

After updating your dependencies, generate the lock file and commit both files:

```bash
composer update
git add composer.json composer.lock
git commit -m "Add Composer config"
```

Heroku requires the `composer.lock` file to be committed. If it is missing, your push will be rejected.

Add `vendor/` to your `.gitignore` to keep build artifacts out of version control:

```
vendor/
.env
```

### Step 2: Configure the Procfile

A `Procfile` in your project root tells Heroku which web server to run. You have two options:

**Apache (default, simpler setup):**
```
web: heroku-php-apache2
```

**Nginx (better performance for high traffic):**
```
web: heroku-php-nginx
```

For Laravel, Symfony, or any framework where the entry point is a `public/` directory, point the web server at that directory:

```
web: heroku-php-apache2 public/
```

If you skip the Procfile entirely, Heroku will try to use Apache with the root directory as the document root, which causes 404 errors on most framework-based apps.

### Step 3: Create the App and Deploy

Create a new Heroku app and push your code:

```bash
heroku create your-app-name
git push heroku main
```

When you push, you should see Heroku detect your PHP app:

```
-----> PHP app detected
-----> Installing dependencies from composer.lock
```

Set any environment variables your app needs:

```bash
heroku config:set APP_ENV=production
heroku config:set APP_KEY=your-app-key
```

Your app will be live at `https://your-app-name.herokuapp.com` once the build completes.

### Step 4: Connect a Database

**MySQL via JawsDB**

Heroku has no native MySQL offering. To use MySQL, install the JawsDB addon:

```bash
heroku addons:create jawsdb:kitefin
```

This sets a `JAWSDB_URL` environment variable with the full connection string. Parse it in your PHP app:

```php
$url = parse_url(getenv('JAWSDB_URL'));
$host = $url['host'];
$db   = ltrim($url['path'], '/');
$user = $url['user'];
$pass = $url['pass'];

$pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
```

Note: the JawsDB free tier is limited to 5MB of storage. For any real application you will need a paid tier.

**PostgreSQL (Native Heroku)**

For PostgreSQL, Heroku's native addon is the simpler choice:

```bash
heroku addons:create heroku-postgresql:essential-0
```

This sets a `DATABASE_URL` environment variable. Connect via PDO:

```php
$url = parse_url(getenv('DATABASE_URL'));
$pdo = new PDO(
  "pgsql:host={$url['host']};dbname=" . ltrim($url['path'], '/'),
  $url['user'],
  $url['pass']
);
```

> Need the full breakdown of Heroku Postgres plans before you commit? [Here is what each plan actually costs and where the limits are.](https://kuberns.com/blogs/heroku-postgres/)

## Common Errors and Fixes

| Error | Cause | Fix |
|---|---|---|
| App not detected as PHP | Missing `composer.json` | Add empty `{}` to project root |
| Build fails on push | Missing `composer.lock` | Run `composer update` and commit the lock file |
| 503 error on deploy | Wrong Procfile command | Verify `web: heroku-php-apache2` syntax |
| Document root 404 | Framework entry in `public/` | Use `web: heroku-php-apache2 public/` |
| Database connection error | Wrong env var parsing | Use `parse_url(getenv('DATABASE_URL'))` |
| PHP version mismatch | No version specified | Add `"php": "^8.4"` to `composer.json` require |

> Seeing unexpected charges after your PHP app went live? [Here is how Heroku billing actually works and what to watch out for.](https://kuberns.com/blogs/heroku-pricing-explained/)

[![Deploy your PHP app on Kuberns](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/CTA_banner.png)](https://dashboard.kuberns.com)

## Heroku PHP Limitations Worth Knowing

![Heroku PHP limitations in 2026](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/heroku-php-limitations.png)

Heroku works for PHP, but there are real constraints to understand before you commit:

- **PHP 8.1 is fully EOL** since the end of 2025. Heroku will still build it but it receives no security updates from the PHP maintainers or Heroku.
- **No persistent file storage.** Heroku's filesystem is ephemeral. Any files your app writes (uploads, cache, logs) are lost on every dyno restart. You need S3, Cloudinary, or a similar service for file persistence.
- **Dynos sleep on the Eco plan.** Every request after a period of inactivity triggers a cold start that can take 10 to 30 seconds. Users will notice.
- **JawsDB free tier is 5MB.** That is not enough for any real application. You will need a paid MySQL plan almost immediately.
- **Everything is manual.** Procfile, buildpack detection, web server config, addon setup, env var wiring  none of it is automated. Every deploy requires you to know what you are doing.

> Thinking about switching from Heroku entirely? [Here are the best Heroku alternatives developers are actually moving to in 2026.](https://kuberns.com/blogs/the-ultimate-guide-to-heroku-alternatives-in-2025/)

## Deploy Your PHP App in One Click with Kuberns

![Kuberns AI-powered deployment platform](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-home-page-new.png)

Everything above works. But if you just counted the number of steps it takes to get a PHP app with a database running on Heroku, you will understand why developers are looking for a better way.

Kuberns is an AI-powered deployment platform built around one idea: you should not have to configure infrastructure to ship an app. Connect your GitHub repository, and an AI agent takes over from there.

Here is what happens when you deploy a PHP app on Kuberns:

- The AI agent reads your repository and detects PHP automatically
- Composer dependencies are installed without any manual commands
- The web server is configured automatically. No Procfile required.
- A database is provisioned by the AI agent. No addon marketplace, no URL parsing.
- Environment variables are set up through a clean interface
- Your app is live with a real URL in under 5 minutes

No YAML files. No buildpack documentation to read. No JawsDB free tier limits to work around. The AI agent handles the infrastructure so you can focus on the code.

| | Heroku | Kuberns |
|---|---|---|
| PHP detection | Requires `composer.json` in root | Automatic |
| Web server setup | Manual Procfile required | AI-configured |
| MySQL support | JawsDB addon (5MB free limit) | Built-in, AI-provisioned |
| PHP version pinning | Must declare in `composer.json` | Auto-detected |
| Free credits | $5 trial | Around $14 |
| Deploy time | 10 to 20 minutes with manual steps | Under 5 minutes |

The $14 in Kuberns free credits is enough to deploy a real PHP app with a database and test it end to end. Not a toy demo. A real working deployment.

**Stop writing Procfiles. [Deploy your PHP app with one click on Kuberns.](https://dashboard.kuberns.com)**

> See how Kuberns stacks up against Heroku for real deployments. [Full comparison here.](https://kuberns.com/blogs/heroku-vs-render-vs-kuberns/)

## Conclusion

Heroku works for PHP in 2026, but it requires more manual setup than most developers expect. Getting a simple PHP app running takes a few steps. Adding a database, handling file storage, and keeping things running reliably takes quite a few more.

For a tutorial project or a quick proof of concept, the Heroku workflow is manageable. For anything you want running in production with minimal overhead, the config adds up fast.

If you are ready to skip the Procfile, skip the addon marketplace, and just ship your PHP app, the smarter move is a platform where an AI agent handles all of it for you.

[Deploy with Agentic AI now](https://dashboard.kuberns.com) and get your PHP app live in under 5 minutes.

[![Deploy your full-stack app on Kuberns with AI](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deploy-on-kuberns-bannner6.png)](https://dashboard.kuberns.com)

## FAQs

### Does Heroku support PHP in 2026?

Yes. Heroku supports PHP in 2026, including PHP 8.2, 8.3, 8.4, and 8.5. PHP 8.1 reached end-of-life at the end of 2025 and no longer receives updates. Heroku detects PHP apps automatically when a `composer.json` file is present in the root directory.

### What PHP versions does Heroku support in 2026?

Heroku supports PHP 8.2, 8.3, 8.4, and 8.5. PHP 8.4 and 8.5 are the recommended versions. PHP 8.1 is fully end-of-life and no longer receives security updates from Heroku or the PHP maintainers.

### Do I need a Procfile to deploy PHP on Heroku?

Yes. A Procfile is required to tell Heroku which web server to run. For Apache use `web: heroku-php-apache2`. For Nginx use `web: heroku-php-nginx`. For Laravel or Symfony with a public directory, use `web: heroku-php-apache2 public/`.

### Does Heroku support MySQL for PHP apps?

Heroku does not offer native MySQL. To use MySQL, you need the JawsDB addon. The free tier is limited to 5MB of storage, which is not viable for real applications. Heroku's native database is PostgreSQL.

### What is the document root for a Laravel app on Heroku?

Laravel's entry point is the `public/` directory. Your Procfile should read `web: heroku-php-apache2 public/` to point the web server at the correct document root. Without this you will get a 404 or see a raw directory listing.

### Why is my PHP app not being detected by Heroku?

Heroku detects PHP apps by looking for a `composer.json` file in the root directory. If this file is missing, Heroku will not apply the PHP buildpack. Even if your app has no Composer dependencies, you must include at least an empty `{}` as `composer.json`.

### What is the best alternative to deploying PHP on Heroku in 2026?

Kuberns is an AI-powered deployment platform that deploys PHP apps in one click. Connect your GitHub repo and the AI agent detects PHP automatically, installs Composer dependencies, configures the web server, and provisions a database without any manual setup. No Procfile needed.

---
- [More Deployment Guides articles](https://kuberns.com/blogs/category/deployment-guides/1/)
- [All articles](https://kuberns.com/blogs/)