Local PHP development environments

Published

Updated

👩🏻‍💻

It works on my machine!

A local development environment runs the project on your own computer. Code changes, updates and experiments get tested there and reach fortrabbit with the next deployment.

Why develop locally

Develop and test on your own computer, then deploy. Running updates directly on the live server breaks the site for visitors when something goes wrong.

  • See code changes right away
  • Debug with dev flags turned on
  • Test updates before they go live
  • Keep a full copy of the project, independent of the host

Requirements

The local stack should roughly match the fortrabbit environment:

  • Apache: fortrabbit runs Apache, so .htaccess rules work the same locally. NGINX works too, but ignores .htaccess.
  • MySQL: the database
  • PHP: keep the major and minor version in sync with the environment, see PHP version
  • Git: version control, see the Git intro
  • Composer: PHP dependencies, see the Composer intro
  • Node.js and npm: frontend builds

Container based

Containers keep the stack apart from the host system and can be shared across a team with the project. They need a Docker provider such as Docker Desktop or OrbStack.

  • DDEV (recommended): Docker setup for most PHP frameworks and CMS
  • Laravel Sail: the Docker setup that ships with Laravel
  • Docker: own docker-compose.yml, most control, most configuration

Native apps

These run PHP and a web server directly on the host system. They start faster and use less memory than containers.

PHP built-in server

For a quick test, PHP comes with a built-in web server. It ignores .htaccess and is not meant for production parity.

php -S localhost:8000

# Laravel wraps it
php artisan serve
bash

A flat-file CMS such as Kirby runs with PHP alone, without a database.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗