Skip to content

Instantly share code, notes, and snippets.

@felegy
Last active November 4, 2019 17:17
Show Gist options
  • Save felegy/42740a2ade6f2c296d8498b0682070ad to your computer and use it in GitHub Desktop.
Save felegy/42740a2ade6f2c296d8498b0682070ad to your computer and use it in GitHub Desktop.
Lando Heroku PHP scaffold

Lando Heroku PHP

Lando Heroku PHP scaffold

  • Heroku identical devenv (as far as possible)
    • heroku-18 official docker image
    • heroku official PHP buildpack
  • Integrated tooling
    • Composer on appserver
    • Git on appserver
    • Heroku-cli on appserver

[TOC]

Installation Prerequisites

Lando and Docker

The main dependency is Lando https://lando.dev and also Docker of course, but Lando is contains Docker builtin in on Windows and Mac.

Local domain and cert for development

The Lando out of the box contains configuration with traefic https://traefik.io and local dev domain *.lndo.site see in Lando Proxy and Lando SSL/TLS . In above docs is contains a main settings for local development. When you are using httpie https://httpie.org you can define alias for TLS verification in your .bashrc or .zshrc like this:

alias http="http --verify=\"/Users/$USER/.lando/certs/lndo.site.pem\""

First steps

Clone my gists repo to local dev:

$ git clone git://gist.github.com/42740a2ade6f2c296d8498b0682070ad.git php-devenv-scaffold

And change dir to repo and run:

$ cd php-devenv-scaffold && lando start

asciicast

.git/
**/.env
vendor/
.profile.d/
.heroku/
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
[*.php]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
.env
/vendor/
/.profile.d/
/.heroku/
name: lando-heroku-php
proxy:
appserver:
- lando-heroku-php.lndo.site:3000
services:
appserver:
type: compose
build:
- mkdir -p /tmp/buildpack/php /tmp/build_cache /tmp/env
- curl https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/php.tgz | tar --warning=none -xz -C /tmp/buildpack/php
- rm -rf /app/.heroku && rm -rf /app/.profile.d && rm -rf /app/vendor && /tmp/buildpack/php/bin/compile /app /tmp/build_cache /tmp/env
services:
image: heroku/heroku:18-build
command: /app/start-web.sh
environment:
STACK: heroku-18
PATH: /app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PORT: 3000
ports:
- '3000:3000'
extras:
- "wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh"
tooling:
composer:
service: appserver
git:
service: appserver
heroku:
service: appserver
cmd: /usr/bin/heroku

.1_lando-heroku-php.md

{
"name": "felegy/lando-heroku-php",
"description": "Lando Heroku PHP scaffold",
"type": "project",
"require-dev": {
"heroku/heroku-buildpack-php": "*"
},
"license": "MIT",
"authors": [
{
"name": "felegy",
"email": "felegy@gmail.com"
}
],
"require": {}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b3fe3dbeb933ff516994d0cfe43072be",
"packages": [],
"packages-dev": [
{
"name": "heroku/heroku-buildpack-php",
"version": "v164",
"source": {
"type": "git",
"url": "https://github.com/heroku/heroku-buildpack-php.git",
"reference": "65bbee93ecc41f8a7d7f909e120c614763079167"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/heroku/heroku-buildpack-php/zipball/65bbee93ecc41f8a7d7f909e120c614763079167",
"reference": "65bbee93ecc41f8a7d7f909e120c614763079167",
"shasum": ""
},
"bin": [
"bin/heroku-hhvm-apache2",
"bin/heroku-hhvm-nginx",
"bin/heroku-php-apache2",
"bin/heroku-php-nginx"
],
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David Zuelke",
"email": "dz@heroku.com"
}
],
"description": "Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP/HHVM and Apache2/Nginx as on Heroku",
"homepage": "https://github.com/heroku/heroku-buildpack-php",
"keywords": [
"apache",
"apache2",
"foreman",
"heroku",
"hhvm",
"nginx",
"php"
],
"time": "2019-10-24T16:05:31+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
FROM heroku/heroku:18-build as build
COPY . /app
WORKDIR /app
RUN mkdir -p /tmp/buildpack/php /tmp/build_cache /tmp/env
RUN curl https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/php.tgz | tar --warning=none -xz -C /tmp/buildpack/php
RUN STACK=heroku-18 /tmp/buildpack/php/bin/compile /app /tmp/build_cache /tmp/env
FROM heroku/heroku:18
COPY --from=build /app /app
ENV HOME /app
WORKDIR /app
RUN useradd -m heroku
RUN chown -R heroku:heroku /app && chmod -R 700 /app
USER heroku
ENV PATH /app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/app/.heroku/php/sbin:/app/.heroku/php/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/bin
ENTRYPOINT ["/bin/bash", "-l", "-c"]
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Referrer-Policy "same-origin";
add_header Feature-Policy "geolocation none;";
add_header Content-Security-Policy upgrade-insecure-requests;
index index.php index.html;
charset UTF-8;
default_type text/html;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_min_length 10;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;
client_max_body_size 64M;
# Force HTTPS on Heroku
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /ads.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny access to any other dot file
location ~ \/\. {
deny all;
}
location ~* ^.+\.(css|js|ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
try_files $uri =404;
expires max;
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
}
# If front page is requested, skip all other regex and rewrite rules and
# pass request directly to WordPress (= URLS that are exactly /)
# Tip from https://www.scalescale.com/tips/nginx/nginx-location-directive/
location = / {
try_files $uri $uri/ /index.php?$args;
}
web: start-web.sh
#!/bin/sh
cd /app
vendor/bin/heroku-php-nginx -C nginx.conf .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment