ServBay Multi-Environment Configuration Guide: PHP Version Management for Command Line and Web Services
1. Command Line Environment: Deep Application of .servbay.config
Through the project-level configuration file .servbay.config
, developers can precisely control the PHP version in the command line environment, enabling parallel development across multiple projects and version isolation.
1. Core Features and Principles
• Multi-Version Coexistence: ServBay natively supports coexistence of all versions from PHP 5.6 to 8.5-dev, with each project specifying the required version through an independent configuration file.
• Non-Intrusive Switching: When executing commands, ServBay automatically detects the .servbay.config
in the project directory, dynamically loading the corresponding PHP environment to avoid global configuration conflicts.
2. Configuration Method
Create a .servbay.config
file in the project root directory and add the following content:
# Specify PHP version (example: PHP 8.5-dev)
PHP_VERSION=8.5
2
Verification of Effectiveness:
$ php -v # The output version should be 8.5
$ composer install # Dependency resolution is based on the current PHP version
2
3. Advanced Tips and Limitations
• Version Compatibility Check: If you encounter errors like "Class not found," verify the compatibility of the dependency packages with the specified PHP version (e.g., the mcrypt
extension removed in PHP 8.x).
• Global Default Value: If not configured, use the ServBay global default version (which can be modified in ServBay's settings
).
• Multi-Service Collaboration: Combine with Node.js version configuration (NODE_VERSION=20
) to achieve dual environment control involving PHP and Node.js.
4. Running Example
The following provides a practical example demonstrating the operational mechanism of .servbay.config
.
2. Web Service Environment: Website-Level Management of Multi-Version PHP
ServBay's Graphical Website Configuration Interface provides PHP version management capabilities for web services, operating independently from the command line environment.
1. Configuration Process
Add/Edit Website:
• Open ServBay and navigate to the Hosts tab.
• Click + to create a new website or edit an existing one.
• Select the desired version from the PHP Version dropdown menu (e.g., 8.3, 8.5-dev, etc.).Path and Domain Binding:
• Root Directory: Specify the project's public directory (e.g., Laravel's/Applications/ServBay/www/laravel-app/public
).
• Domain: Set a custom domain (e.g.,laravel.host
), supporting automatic HTTPS provision.
2. Technical Implementation and Optimization
• Service Isolation: Each PHP version runs in an independent process, avoiding memory leaks across versions.
• Performance Tuning: Optimizations for ARM64/X86_64 architecture.
• Error Troubleshooting:
• Check logs: /Applications/ServBay/var/log/php/php_error.log
• Use servbayctl status php 8.5
to view process status.
3. Multi-Server Expansion
• Apache/Nginx/Caddy Support: Ability to switch web servers in ServBay 1.7.0+.
• Database Integration: Combine with multiple versions of MySQL/MariaDB/PostgreSQL (e.g., adapting Laravel projects to MariaDB 11.5).
3. Best Practices for Cross-Environment Collaboration
Scenario | Command Line Configuration | Web Service Configuration | |
---|---|---|---|
Legacy System Maintenance | Set PHP 5.6 in .servbay.config | Choose PHP 5.6 in website config | |
Laravel 11 Development | Configure PHP 8.3 + Node 20 | Bind domain and enable HTTPS | |
New Version Testing | Use PHP 8.5-dev | Pair with Redis 7.x for caching optimization |
Notes:
• PHP modules for command line and web services may differ (e.g., opcache
is disabled by default in CLI mode).
• Upgrade ServBay Runtime to 1.0.20/1.1.20+ to access the latest PHP features.
Through the above scenario-based management, developers can fully utilize ServBay's multi-version control capabilities, balancing development flexibility with production environment consistency.