🐧 InstallPHP
Installs PHP via the system package manager.
When to Use
Use this when PHP is detected as missing and you want to install it automatically. Only effective on Linux and depends on distribution info. 🛠️
Signature
go
func InstallPHP(distro *DistroInfo, useSudo bool) errorParameters
| Parameter | Type | Description |
|---|---|---|
distro | *DistroInfo | Distribution info, obtained from DetectLinuxDistro |
useSudo | bool | Whether to run the install command with sudo |
Return Value
error:nilon success; returns an error when the distro or package manager is unknown; returns a wrapped error on command execution failure. ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
distro, err := installer.DetectLinuxDistro()
if err != nil {
log.Fatalf("failed to detect distro: %v", err)
}
if err := installer.InstallPHP(distro, true); err != nil {
log.Fatalf("failed to install PHP: %v", err)
}
fmt.Println("PHP installed")
}Advanced
- Packages installed vary by distro: apt/dnf/yum install
php php-cli php-mbstring php-xml php-curl; apk installs thephp81-*series. 📦 - Called by
Installer.Install(withAutoInstallPHP=true) andInstallWithProgresswhen PHP is missing. 🔗 - Not supported on macOS/Windows; check with
GetPlatformNamebefore calling. 🚫