Giter Club home page Giter Club logo

craft-heroku's Introduction

Craft 4 on Heroku

Craft 4 is a PHP application based on Yii2, and is installed via Composer.

This means that it’s well-suited for deployment to cloud-based platforms like Heroku. In this case, we’ve put together a barebones starter-kit for running a Craft application on Heroku.

12-Factor Apps

There are a couple of limitations, here, that are important to note if it’s your first time using Heroku:

  1. The filesystem is ephemeral. This means that anything you store on your running dynos is considered disposable—so, if you want to persist data (like user uploads), you’ll have to use a cloud-based storage service like Amazon S3 or Google Cloud Storage. This also applies to Craft-specific features like Project Config, which relies on YAML files written to disk.
  2. Assume the app will scale. Design your formation and configuration assuming that you’ll (eventually) be running more than a single process. Your database, sessions, and shared caches should all be kept in a common location—but Heroku will help with this through “Addons,” configured with this app.json.
  3. Logs are streams. Any logging that ends up in a file is as good as gone. There might be some clever workarounds here, but since the purpose of this repo is to demonstrate compatibility with first-party Heroku tools, Craft is configured to log to php://stdout and php://stderr, so the logs can be “Drained” anywhere you like.

Read more about 12-factor app architecture, the underlying principles of the Heroku platform.

Queue

It’s also worth mentioning: The traditional “queue” is handled here by a worker dyno. In order to run the app locally, you’ll need to spin up a queue daemon to ensure your jobs are taken care of:

php craft queue/listen --verbose

☝️ This is the same worker command you see in the Procfile in the project's root! It’ll get booted alongside your web dyno.

Setup

Just click this button to set up your first app!

Deploy to Heroku

This script does a few things:

  1. Creates a new “app” in your Heroku account;
  2. Provisions addons (Redis and Postgres);
  3. Helps set up required Config Vars;
  4. Performs an initial build, including the installation of Composer dependencies;
  5. Configures “dyno” formation (with two web processes and one worker);
  6. Redirects you to the Craft 4 installation screen. 🎊

You might encounter some visual issues with the installation process—this is because the cpresources are published into the public web root on a dyno-by-dyno basis, and the initial request for the installation page is not apt to have been hit on both servers. Subsequent requests for those assets could still be served by another dyno. Refresh the page a few times, and both dynos will begin to warm their cpresources.

Local Development

But what about the road to production? This repo is designed to work seamlessly with Craft’s recommended development environment, DDEV.

Install DDEV, clone the project, and run $ ddev start. For more information, please refer to the official Craft installation instructions.

🌳

craft-heroku's People

Contributors

augustmiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.