Skip to content

🐧 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) error

Parameters

ParameterTypeDescription
distro*DistroInfoDistribution info, obtained from DetectLinuxDistro
useSudoboolWhether to run the install command with sudo

Return Value

  • error: nil on 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 the php81-* series. 📦
  • Called by Installer.Install (with AutoInstallPHP=true) and InstallWithProgress when PHP is missing. 🔗
  • Not supported on macOS/Windows; check with GetPlatformName before calling. 🚫

Released under the MIT License