Intro to local development with PHP
π©π»βπ»
It works on my machine!
A local development environment is key for successful application lifetime management and continuous deployment.
# Why local development?
- See code changes in real time
- Test your code before deploying
- Debug issues with dev flags enabled
- Experiment with new features
- Validate compatibility
- Maintain an up-to-date backup
- Stay independent from your hosting provider
Not having a local PHP development environment can lead to chaos. Developers may perform "open heart surgery"βrunning major updates directly on the server. The fortrabbit platform aims to make deployment from local development to remote environments seamless and safe.
# Requirements
The following open source software should run in your local development environment to match with the fortrabbit platform:
- Apache or NGNIX β a web server
- MySQL - database
- PHP - server side scripting language
- Git - version control - see Git into
- Composer - dependency manager for PHP - see intro
- Node.js and NPM (or similar) - frontend build processes
There are various ways to set up your local development stack, depending on your skills, needs, and operating system (Windows, macOS, or Linux). Choose the approach that best suits you. Luckily with Composer driven PHP development it's usually enough to roughly match the remote environment. Specifically major and minor PHP versions should be kept im sync.
# Local development with virtualization
Utilizing containers allows replication of local setup across a team. Having everything stashed into a virtual machine very much nullifies any interference with the local host system. It keeps things clean. A project with a containerized local development environment can also be frozen to the software specific versions used at that time. Modern container technology is lightweight and fast and usually headless.
- DDEV (recommended): See guide
- Laravel Herd: See guide
- Laravel Sail: See guide
- Docker: maximum flexibility and control, more configuration.
# Local development on the host
Run a web server and PHP directly on your laptop. This is often quick and lightweight to get up and running. Your options:
- Laravel Valet: See guide
# PHP built-in server
For simple tasks or quick tests, you don't strictly need a full web server stack. PHP comes with a built-in web server.
php -S localhost:8000bash
If you are using Laravel, you can use the Artisan command which wraps the PHP built-in server:
php artisan servebash
This is great for quick prototyping but not recommended for complex applications or production parity.
# Desktop virtualization
This is the old school way. Example VM applications are: VirtualBox(free by Oracle) or VMware(paid). VirtualBox controlled by Vagrant helps when setting up reproducible development environments. Homestead, which builds upon Vagrant is still popular with Laravel.
# Other options
Classical GUIs These solution stacks are easy to handle through a graphical interface and they interfere with the rest of your system as little as possible. The most commonly used here are MAMP (free and paid version) and XAAMP. Please mind that those don't include Git and Composer.
Manual setup Install and manage a web server to run your laptop. Specifically for lightweight applications, such as Kirby CMS, which does not need a database, installing the PHP runtime might be sufficient.