We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Improve your Craft CMS skills

Craft CMS Hosting On Heroku - Is This A Good Idea?

10 min read
Andy Golpys Made By Shape Founder

With its git-based deployments and instant scaling, Heroku seems like an ideal hosting platform for Craft CMS. But before jumping on the hype train, it’s worth evaluating if Heroku's constraints around flexibility, performance and costs outweigh the benefits for your specific use-case. This article provides a comprehensive, unbiased analysis of using Heroku for Craft CMS, so you can make an informed decision.

Heroku's fast deployments and automatic scaling make it a viable option for hosting Craft CMS, but limited flexibility, potential performance lags, and higher long-term costs versus self-managed infrastructure are drawbacks to evaluate.

Benefits of Using Heroku to Host Craft CMS

Fast and Easy Deployment

One of the biggest advantages of using Heroku to host Craft CMS is the fast and straightforward deployment process. With Heroku's git-based workflow, deploying a Craft CMS site is as simple as pushing code changes to the Heroku remote. This enables instant and seamless deployments with just a single command.

There's no need to mess around with configuring servers or managing infrastructure. Developers can focus on building Craft plugins and frontends, while Heroku handles all the server provisioning and deployment tasks behind the scenes. The automated deployment workflow provides huge time savings compared to traditional CMS hosting setups.

The ease and speed of deployments on Heroku is a massive boost in developer productivity. No more waiting around for code changes to go live. Pushing a commit to the Heroku remote triggers an immediate rebuild and redeploy of the Craft site. This rapid iteration allows developers to deploy updates and test new features in real-time.

Flexible Scaling and Management

Another major advantage of Heroku is the flexible scaling it provides for Craft CMS sites. Heroku allows effortless scaling of compute resources to handle fluctuations in traffic and load. This autoscaling ensures the Craft backend always has sufficient dynos and memory to support the site usage at any given time.

If a big traffic spike is expected due to a new product launch or marketing campaign, it's easy to instantly scale up the number of Heroku dynos to comfortably handle the increased load. Then scale back down during quieter periods to reduce resource usage. This flexibility is invaluable for managing variable traffic and load patterns.

Heroku also shines when it comes to addons and seamless management. It offers a huge ecosystem of third-party addons like Postgres databases, performance monitoring, logging and security tools. These can be provisioned instantly with just a click. And integrated directly into the Craft codebase automatically.

The Heroku dashboard and CLI provide user-friendly management and visibility into the Craft app's performance and resource usage. Enabling at-a-glance monitoring without complex setup. Heroku effectively abstracts away server management, allowing developers to solely focus on building the Craft frontend and backend.

Reliability and Availability

Reliability and uptime are crucial for any CMS hosting solution. Heroku offers industry-leading reliability for Craft CMS sites through its resilient cloud infrastructure. The platform provides built-in redundancy to eliminate any single points of failure. If an underlying server fails, Heroku automatically fails over the Craft app to a healthy one with minimal interruption.

Heroku also ensures high availability through automated health checks and self-healing capabilities. Any issues like crashed dynos or failed deploys are automatically detected and recovered from rapidly. This intelligent automation maximises uptime for the Craft site.

In addition, Heroku provides 99.95% uptime SLAs along with an industry-leading rollback system. If any bad code gets deployed, the Craft CMS site can be instantly rolled back to the previous working release with a single click. This provides a safety net against mistakes impacting site availability.

The resilience and self-healing capabilities of Heroku allow Craft developers to rest assured their sites will stay highly available. Eliminating the stress of maintaining reliability through redundant servers, health checks and complex failover setups.

So in summary, Heroku brings some huge benefits for Craft CMS hosting. The instant and automated deployments allow rapid iteration and testing. The flexible scaling handles variable traffic spikes and troughs seamlessly. The wide range of management addons improves monitoring and optimisation. And the resilience of the platform provides rock-solid reliability and availability. For Craft developers wanting a simplified, cloud-based hosting solution, Heroku ticks all the boxes.

Drawbacks of Heroku for Hosting Craft CMS

Limited Flexibility and Control

While Heroku provides speed and simplicity, one potential drawback is the limited flexibility and control compared to traditional hosting platforms. Heroku employs an opinionated architecture that restricts deeper server access and customization.

For example, the ephemeral filesystem makes it harder to install complex dependencies or run customisation scripts. There is no direct access to configure server stacks, networks or infrastructure. You can't spin up a SQL server or craft custom Varnish caching rules.

This can be frustrating for developers who want more control over the hosting environment. The Heroku workflows and restricted access sometimes feel constraining, especially when transitioning from unmanaged servers. While it enables quick setup, you sacrifice configuration possibilities.

The lack of flexibility also makes certain Craft CMS plugins incompatible or harder to install. Modules that require elaborate configuration or depend on access to specific directories may not work. For developers needing full control and customization capability, Heroku can seem restrictive.

Potential Performance Issues

While Heroku offers automatic scaling, there can still be performance and latency constraints compared to finely tuned dedicated servers. The abstracted architecture means less performance optimisation possibilities and resource targeting.

For example, asset editing and live previewing from the Craft control panel can feel sluggish at times. Saving and publishing new entries doesn't feel quite as snappy. For sites running heavy workflows, the performance may degrade over unmanaged infrastructure.

The dyno sleeping and spin up times can also cause delays if the site experiences variable traffic patterns. It takes time for dynos to awake and scale when needed, leading to temporary lag spikes. Complex sites under load may suffer more latency issues.

So for some high performance use cases, Heroku may prove limiting. Sites needing the ultimate speed may want the customisation and control of bare metal or virtual private servers. The constraints of Heroku's architecture can impact latency sensitive Craft implementations.

Higher Long-Term Costs

While Heroku has a generous free tier, pricing can escalate for large Craft sites. The pay-as-you-go model gets expensive with premium dynos, expansive databases, and multiple add-ons. Costs grow exponentially with site traffic and resource usage.

At a major scale, the monthly Heroku invoice will easily eclipse a self-managed infrastructure bill. Running hundreds of dynos 24/7 racks up a hefty tab. Add-ons like performance monitoring and logging also come at a recurring cost.

For larger Craft sites, it's worth comparing the long-term costs against a DIY server cluster. After the initial setup time investment, maintaining your own stacks may prove cheaper. However, the convenience and simplicity of Heroku may still justify the premium pricing.

In summary, Heroku's limitations around flexibility, performance and long-term costs should be evaluated before adopting the platform. For smaller Craft use cases, these may not pose any issues. But at major scale, or for specialised needs, Heroku's constraints could become problematic. The reduced control and customisation possibilities may also frustrate some Craft developers.

Deploying Craft CMS on Heroku

Prerequisites and Dependencies

Before deploying Craft CMS to Heroku, there are a few key prerequisites and dependencies to configure.

Firstly, Git needs to be installed to enable Heroku's git-based deployment workflow. The Craft codebase must be in a Git repository in order to push changes to Heroku remotes.

Composer is also required to manage PHP dependencies and install Craft CMS and plugins. The composer.json and composer.lock files should be committed to Git to ensure identical dependency installs on Heroku.

Certain Craft CMS plugins may need tweaking or disabling to run on Heroku's architecture. For example, plugins that execute shell commands are restricted due to Heroku’s read-only filesystem. Performance-intensive plugins like Sprout SEO may also need adjusting based on available Heroku dyno resources.

Some additional dependencies like ImageMagick for image processing should be declared in composer.json so they compile correctly during Heroku builds. It’s important to validate plugin compatibility and dependencies before deploying to avoid issues.

Environment variables will need configuring for connecting to Heroku services like the database. Heroku Postgres connection details should be stored in config vars. API keys for services like Stripe or Twilio should also be defined as secure environment variables.

Configuring Buildpacks and Deploy Scripts

To deploy Craft CMS to Heroku, the correct buildpacks need configuring. PHP and Node.js buildpacks are required to support Craft’s PHP backend and Node-based front-end tooling.

A Procfile declares the process types to launch on Heroku dynos. A simple web: vendor/bin/heroku-php-apache2 starts PHP-FPM for serving Craft CMS. Optionally, a worker process could run queue or tasks.

Deployment and compile scripts in composer.json automate builds and migrations. The post-install-cmd and post-update-cmd events can trigger tasks like database migrations during deployment.

To enable zero-downtime deploys, the Craft release feed and entry publishing needs disabling before push. A custom deploy script can handle this. Pre-deploy hooks in the Heroku CLI simplify automation.

After committing the code changes, Git pushes to the Heroku remote trigger a build. Heroku installs dependencies, compiles assets, and releases the new dynos. Followed by any post-deploy actions like clearing caches.

Setting Environment Variables

Environment variables are critical for configuring Craft CMS on Heroku. The platform's heroku config vars command allows securely setting app settings, credentials and keys.

At minimum, variables like DATABASE_URL, CRAFT_LICENSE_KEY and SECURITY_KEY must get defined. Any external services like Stripe or AWS S3 should have API keys and secrets stored as protected config variables.

The environment variables get automatically injected into PHP's $_ENV array at runtime, available in craft()->config->get(). This allows referencing them in config/general.php and .env files for app configuration.

To prevent security mishaps, the config var UI redacts protected variables on display. But all values get exposed at runtime, so values like API keys shouldn't be echoed in templates.

Environment variables enable changing config on the fly without redeploying code. So settings like Stripe keys can be rotated seamlessly. Heroku's CLI also allows bulk import/export of variables between environments.

In summary, Heroku's config vars are integral for deploying Craft securely and connecting to external services. All confidential credentials, API keys and app settings should be defined as protected environment variables.

Managing and Monitoring Craft CMS on Heroku

Logging, Alerting, and Troubleshooting

Heroku provides useful tools for monitoring, debugging, and troubleshooting Craft CMS deployments. Log drains can stream app and platform logs to external log aggregators for analysis. Heroku's logfmt logging makes searching through log data much easier.

Adding Papertrail or Logdna addons creates a centralised dashboard for searching and alerting on application logs in real-time. Debugging error messages and exceptions is straightforward.

For debugging, Craft's devMode can be enabled to display full stack traces. Heroku's one-off dynos allow quickly reproducing issues in a disposable environment using debug tooling like Xdebug. The Heroku CLI also provides SSH access to prod dynos for manual inspection.

Craft CMS can integrate with Sentry or Bugsnag addons to track errors and exceptions. Email and Slack notifications on critical events can be setup. This provides visibility into issues and proactive alerting.

Scaling Resources

To ensure optimal Craft CMS performance on Heroku, resource scaling needs proactive management. The Heroku dashboard provides visibility into dyno usage, enabling planning for traffic fluctuations.

Horizontal dyno scaling handles increased load and concurrent requests. Spiky traffic may require rapidly spinning up extra dynos. Stress testing under load indicates how many web and worker dynos are needed.

Likewise database resources should be monitored. Highly concurrent Craft operations can exhaust Postgres connections. Scaling to a higher Heroku Postgres tier provides more connections and memory.

Additional services like cache and queue addons may require upgrading tiers or provisioning extra nodes as usage grows. Regularly reviewing addon usage ensures resources scale in line with site traffic.

Backups and Availability

To protect against data loss, regular automated Craft CMS backups are essential. The Heroku Postgres Backup addon enables scheduled database dumps to external S3 buckets or other storage providers.

For maximum availability, Heroku Postgres can be configured to replicate data to standby followers. If the primary database fails, the follower is automatically promoted to take over with minimal downtime impact.

The overall application can also be replicated across multiple regions to maintain reliability. Heroku has datacenters worldwide, allowing Craft to run in Europe, USA and Asia for local redundancy.

Backups, replication and geo-distribution provide defence against failures and disasters. For mission critical Craft sites, these high availability measures are advisable to guarantee maximum uptime.

In summary, Heroku furnishes powerful facilities for monitoring, resource management and disaster recovery when running Craft CMS. Leveraging these appropriately ensures happy experiences for both developers and end users.

Heroku Alternatives for Hosting Craft CMS

AWS for Craft CMS Hosting

Amazon Web Services provides a popular alternative to Heroku for hosting Craft CMS workloads. The on-demand IaaS model gives more control for custom infrastructure setups.

AWS EC2 can run Craft CMS across a cluster of Linux servers. RDS provides managed PostgreSQL hosting for the database backend. An Elastic Load Balancer handles traffic distribution for high availability.

The main advantage of AWS is flexibility. Developers can fine-tune server specs, storage, networking to optimise performance. Auto Scaling groups allow programmatic scaling of EC2 capacity up or down based on demand.

AWS offers a wider array of database options beyond Postgres like MySQL and Aurora. Services like ElastiCache, Lambda, and SQS integrate nicely for caching, automation and queues.

The global infrastructure provides low latency by deploying Craft CMS servers to region closest to users. Routing policies can send visitors to the optimal AWS zone.

However, AWS requires more oversight for security, updates, and infrastructure management. Heroku eliminates this Ops work, while AWS gives more control at the cost of complexity.

Google Cloud for Craft CMS

Google Cloud Platform is another fully-managed cloud offering capabilities similar to Heroku. Compute Engine provides the scalable Linux VM hosting for Craft CMS.

Cloud SQL makes setup and management of Postgres databases simple. Cloud Load Balancing distributes incoming requests across multiple regions for smooth failover.

Google Cloud services integrate seamlessly with each other and Craft CMS. Cloud Storage replaces local asset volumes with unlimited, durable object storage. Cloud CDN serves assets globally from edge caches.

Managed services like Cloud Armor provide DDoS protection and Web Application Firewall capabilities out-of-the-box. Monitoring tools give visibility into performance metrics and application health.

The benefits are reduced Ops overhead through managed services, and tight integration between GCP tools. However, costs can be higher than self-managed infrastructure.

Azure for Hosting Craft CMS

Microsoft Azure is another robust IaaS and PaaS platform suitable for hosting Craft CMS. Virtual Machines provide configurable Linux servers to run PHP worker pools.

Cosmos DB is Azure's globally distributed database service supporting MongoDB APIs. It handles global replication and scaling for Craft's backend data storage.

Azure Load Balancer evenly distributes traffic to ensure high availability across regions.

Application Gateway provides layer 7 capabilities like Web Application Firewall protection.

Azure appeals through potential hybrid scenarios, integrating on-premises infrastructure with Azure's cloud resources. Services like Traffic Manager route visitors optimally between cloud and on-prem.

The main drawbacks are somewhat higher basic costs than competitors, and the learning curve of navigating Azure's multitude of services.

In summary, leading cloud providers all offer compelling Craft CMS hosting options. The choice comes down to needs around flexibility, integrated services, hybrid potential, and costs.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat