Understanding the "Received SIGHUP" Error When Installing PHP on macOS
If you are attempting to upgrade PHP from version 5.5 to 7.1 on a Mac, you might encounter a specific failure mode that often confuses developers: the script briefly opens your .bash_profile, then immediately terminates with Received SIGHUP or SIGTERM. This error message indicates that the terminal session was interrupted before the installation process could complete its file system modifications.
The command you are likely using is based on legacy repositories, such as php-osx.liip.ch, which provided pre-compiled binaries for older macOS versions and specific PHP releases. While these scripts worked years ago, they often fail on modern macOS environments (Catalina through Sonoma) due to changes in system permissions, security sandboxes, and the removal of 32-bit architecture support. When a script tries to modify environment variables or install binaries without sufficient privileges or compatible paths, it gets killed by the shell itself, resulting in that SIGHUP signal.
Why the Script Fails on Modern macOS
The core issue with installing PHP directly into your user home directory via these legacy scripts is permission handling and path resolution. When the installer attempts to write to /usr/local/bin or modify your .bash_profile, it expects a specific shell environment. If your current terminal session has restricted permissions (common in newer macOS versions) or if the script detects an incompatible system, it aborts.
The SIGHUP signal specifically means the controlling terminal is closing or the process is being terminated by the shell. In this context, the installation script likely tried to execute a command that required elevated privileges or a path that no longer exists in your current user space. The result is a partial installation where files might be buffered (as seen in your .bash_profile.save.6) but never committed.
A More Robust Approach: Homebrew
For modern development workflows, relying on ad-hoc shell scripts is generally discouraged. The standard and most reliable method for managing PHP versions on macOS is using Homebrew. This approach isolates PHP installations from the system directories, avoids permission issues entirely, and provides a clear mechanism to switch between versions.
To begin, ensure Homebrew is installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is ready, you can install PHP 7.1 (or any other supported version) by specifying the exact version tag. Note that as of recent years, official support for PHP 7.1 has ended in favor of versions 8.x or 9.x. However, if you have a legacy application requiring 7.1:
brew install php@7.1
After installation, you can link the binaries to your system path:
brew link --force php@7.1
Managing Versions and Switching
One of the primary advantages of using Homebrew over legacy scripts is the ability to coexist with multiple PHP versions without conflicting environment variables. You can install PHP 8.x alongside PHP 7.1 if necessary:
brew install php@8.2
brew link --force php@8.2
To switch between versions, you simply unlink the current one and link the desired version:
brew unlink php
brew link --force php@7.1
You can then verify the active version using php -v. If you are working with a Laravel project or any framework that relies on specific PHP features, ensuring the correct version is linked globally or via an environment-specific setup is crucial.
Integrating with Your Environment
After linking the new version, you must ensure your shell configuration reflects the change. The legacy scripts often tried to append paths to .bash_profile directly, which can lead to duplication if done manually. With Homebrew, you should run:
echo 'export PATH="/opt/homebrew/opt/php@7.1/bin:$PATH"' >> ~/.zshrc
(Note: On Apple Silicon Macs or newer Intel systems, the path may differ slightly depending on your shell. Check where brew --prefix points for accurate paths.)
If you are using Zsh (the default on macOS Catalina and later), edit ~/.zshrc instead of .bash_profile. Always restart your terminal session after making these changes to ensure the environment variables load correctly.
Final Considerations
Before proceeding with an upgrade, consider whether PHP 7.1 is truly necessary. The vast majority of modern frameworks, including Laravel (which you might be using given the context of such upgrades), have dropped support for PHP 7.x in favor of PHP 8.2 or higher. Sticking to older versions limits your access to performance improvements, security patches, and new language features.
If you are maintaining legacy code that strictly requires 7.1, Homebrew remains the safest route. It handles dependencies cleanly, respects your system permissions, and avoids the SIGHUP trap that plagues outdated installation scripts. Always verify your PHP version and ensure your Composer dependencies are compatible with the new runtime before deploying any application changes.
