PHMATE is a lightweight command-line utility that simplifies management of PHP's built-in web server for local development. It streamlines server startup, configuration, and monitoring with sensible defaults and multiple profile support.
- Server Management: Start, stop, restart, and check status of PHP's built-in web server
- Interactive Wizard: Configure server settings via a guided setup with
phmate wizard - Multiple Profiles: Create and manage different server configurations with the
--profileoption - Document Root-based Configuration: Configuration files stored in each project's document root for isolation
- Multiple Concurrent Servers: Run multiple PHP servers simultaneously in different projects
- Custom PHP Settings: Specify PHP binary path and custom php.ini files
- Router Script Support: Use custom PHP router script files with auto-detection
- Auto-Router Detection: Automatically detects and uses
router.phpin document root if present - Configurable Host/Port: Run servers on custom hostnames and ports
- Robust Error Handling: Comprehensive error checking, validation, and detailed logs
- Logging: Detailed logs with configurable verbosity levels (DEBUG, INFO, WARNING, ERROR)
- Status Monitoring: View running server status including uptime and process information
- Project Isolation: Each project maintains its own configuration and server state
- Bash: Version 4.0 or higher
- PHP: Version 8.0 or higher with built-in web server support
- Standard Unix Tools: ps, kill, netstat/ss (optional for port checking)
-
Download the script:
curl -o phmate.sh https://raw.githubusercontent.com/dlzi/phmate/main/phmate.sh
-
Make it executable:
chmod +x phmate.sh
-
Optionally, move to a directory in your PATH:
sudo mv phmate.sh /usr/local/bin/phmate
If you've cloned the repository, you can use the provided Makefile for a complete installation including documentation and bash completion:
git clone https://github.com/dlzi/phmate.git
cd phmate
make installThis will install PHMATE to /usr/local/bin/phmate by default. To install to a different location:
make install PREFIX=~/.localTo uninstall PHMATE when installed with the Makefile:
make uninstallThe repository includes an installation script that properly installs all components including documentation and bash completion:
git clone https://github.com/dlzi/phmate.git
cd phmate
./install.shYou can customize the installation directories by setting environment variables:
PREFIX=~/.local ./install.shTo uninstall PHMATE when installed with the install script:
./uninstall.shFor Arch Linux and derivatives (Manjaro, EndeavourOS, etc.), a PKGBUILD is provided:
git clone https://github.com/dlzi/phmate.git
cd phmate/packages/arch
makepkg -siVerify installation:
phmate versionPHMATE uses the syntax: phmate COMMAND [OPTIONS] [<hostname>:<port>]
- Server Control:
phmate start [<hostname>:<port>] [options]: Start the PHP serverphmate stop: Stop the running serverphmate restart [options]: Restart the serverphmate status: Check server statusphmate list: List available profiles in current document rootphmate wizard: Interactively configure server settingsphmate config: Display current configurationphmate help: Show help informationphmate version: Display version information
--docroot=<path>: Set document root directory (default: current directory)--php=<path>: Specify PHP binary path--php-ini=<path>: Use custom PHP ini file--profile=<name>: Use specific configuration profile (default: default)--router=<file>: Set router script (file path)--debug: Enable debug logging (sets LOG_LEVEL=DEBUG)
PHMATE automatically detects and uses a router.php file in the document root directory if:
- No explicit
--routeroption is provided - A
router.phpfile exists in the document root
This feature makes it convenient for projects that follow the common convention of using router.php as the main routing script.
Precedence: Explicit --router option always takes precedence over auto-detection.
-
Start a server on the default host/port (localhost:8000):
phmate start
-
Start a server on a specific host and port:
phmate start localhost:8080
-
Use a custom PHP router script (explicit):
phmate start --router=custom_router.php
-
Start server with auto-detection of router.php:
phmate start --docroot=/path/to/www # Will automatically use /path/to/www/router.php if it exists -
Start server with a specific document root:
phmate start --docroot=/path/to/www
-
Use a specific PHP version:
phmate start --php=/usr/bin/php8.1
-
Use a custom PHP ini file:
phmate start --php-ini=/etc/php/8.1/php.ini
-
Create and use a named configuration profile:
phmate start --profile=dev
-
List available profiles in current project:
phmate list
-
Check server status:
phmate status
-
Stop the server:
phmate stop
-
Restart the server:
phmate restart
-
Configure interactively:
phmate wizard
PHMATE now supports running multiple servers simultaneously:
# Start server in project 1
cd /path/to/project1
phmate start localhost:8000 --profile=main
# Start server in project 2
cd /path/to/project2
phmate start localhost:8001 --profile=staging
# Start another profile in project 1
cd /path/to/project1
phmate start localhost:8002 --profile=devEach server maintains its own configuration, logs, and process state.
Starting with version 1.2.0, PHMATE stores configuration files in the document root directory:
- Configuration Directory:
<docroot>/.phmate/ - Profile Configuration:
<docroot>/.phmate/config_<profile> - PID Files:
<docroot>/.phmate/phmate_<profile>.pid - Log Files:
<docroot>/.phmate/phmate_<profile>.log - Global Fallback:
${HOME}/.config/phmate/(customize withPHMATE_CONFIG_DIR)
- Project Isolation: Each project has its own server configuration
- Multiple Servers: Run different projects simultaneously without conflicts
- Portable Configuration: Configuration travels with the project
- Team Collaboration: Share project-specific server settings with team members
- Version Control: Optionally commit
.phmatedirectory for consistent team setup
PHMATE_CONFIG_DIR: Override default global configuration directoryLOG_LEVEL: Set logging verbosity (DEBUG, INFO, WARNING, ERROR)
- All Profiles: Configuration settings are now saved to disk in the document root
- Project-specific: Each project maintains its own set of profiles
- Persistence: Settings persist between sessions within each project
- Isolation: Profiles in different projects are completely independent
your-project/
├── .phmate/
│ ├── config_default # Default profile configuration
│ ├── config_dev # Development profile configuration
│ ├── config_staging # Staging profile configuration
│ ├── phmate_default.pid # Default profile PID file
│ ├── phmate_dev.pid # Development profile PID file
│ ├── phmate_default.log # Default profile log file
│ └── phmate_dev.log # Development profile log file
├── index.php
├── router.php # Auto-detected if present
└── ... (your project files)
A custom PHP router script allows you to handle HTTP requests in specific ways, such as routing requests to a single entry point or serving static files directly. Here's a simple example:
<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) {
return false; // Serve the requested file as-is
} else {
include_once 'index.php'; // Route all other requests to index.php
}-
Auto-Detection: Place a
router.phpfile in your document root and start the server:phmate start # Automatically detects and uses ./router.php -
Explicit Router: Specify a custom router script:
phmate start --router=custom_router.php
-
Different Document Root: Auto-detection works with custom document roots:
phmate start --docroot=/var/www/html # Will use /var/www/html/router.php if it exists
- Port Already in Use: Use
phmate stopto stop any existing server, or specify a different port - Permission Denied: Ensure the script is executable (
chmod +x phmate.sh) - PHP Not Found: Specify PHP path with
--php=/path/to/php - PHP Version Too Old: Update to PHP 8.0+ or install compatible version
- Log File Access: Check that the document root directory is writable for
.phmatedirectory creation - Router Script Issues: Ensure
router.phphas correct PHP syntax and is readable - Configuration Conflicts: Use different profiles (
--profile=name) for different server configurations - Multiple Servers: Check
phmate listto see all running profiles in current project - Detailed Errors: Use
--debugflag for verbose logging
Check logs for more information:
- Project logs:
<docroot>/.phmate/phmate_<profile>.log - Global fallback:
${HOME}/.config/phmate/phmate.log
If you're upgrading from a version prior to 1.2.0:
- Existing configurations in
~/.config/phmate/will continue to work as a fallback - New configurations will be created in document root directories
- Manual migration: Copy old configs to new locations if desired:
# Example migration mkdir -p /path/to/project/.phmate cp ~/.config/phmate/config_default /path/to/project/.phmate/
PHMATE_CONFIG_DIR: Override default global configuration directoryLOG_LEVEL: Set logging verbosity (DEBUG, INFO, WARNING, ERROR)
PHMATE is released under the MIT License.
Developed by Daniel Zilli.