How to Disable PHP Updates on Your Server
If you're managing a server with PHP and want to prevent PHP from being automatically updated, you're not alone. Disabling updates can be crucial for maintaining compatibility with specific applications or for ensuring stability in a production environment. Here's a step-by-step guide on how to disable PHP updates on different systems.
Why Disable PHP Updates?
There are several reasons why you might want to lock PHP to a specific version:
Application Compatibility: Certain applications might depend on specific PHP versions and may not be compatible with newer releases.
Stability: In production environments, stability is critical. Updating PHP could inadvertently introduce bugs or compatibility issues.
Testing: Before updating PHP on a production server, you might want to test the new version in a staging environment.
Disabling PHP Updates on Debian/Ubuntu-Based Systems
1. Pin the Package Version
Debian and Ubuntu allow you to "pin" packages to specific versions to prevent them from being upgraded. Here's how:
Create a Pinning File: Open a terminal and create a new file:
sudo nano /etc/apt/preferences.d/php
Add Pinning Configuration: Add the following content to pin PHP packages to version 7.4.x:
Package: php*
Pin: version 7.4.*
Pin-Priority: 1001
Save and close the file. This configuration ensures that only PHP 7.4.x packages are considered for installation or upgrade.
2. Lock the Package Version
Another method is to use apt-mark to hold the PHP package versions:
sudo apt-mark hold php php-cli php-fpm php-common
This command prevents apt-get from upgrading these PHP packages.
Disabling PHP Updates on RHEL/CentOS-Based Systems
1. Exclude PHP Packages
To exclude PHP packages from updates, you'll need to modify your repository configuration:
Edit Repository Configuration: Open the relevant repository file, such as /etc/yum.repos.d/CentOS-Base.repo:
sudo nano /etc/yum.repos.d/CentOS-Base.repo
Add Exclusion: Find the [repository] section and add or modify the exclude line:
exclude=php* php-*This prevents yum from updating PHP packages.
2. Lock the Package Version
You can also use the yum versionlock plugin to lock the PHP packages:
Install the Versionlock Plugin:
sudo yum install yum-plugin-versionlock
Lock the Packages:
sudo yum versionlock add php php-cli php-fpm php-commonDisabling PHP Updates on Systems Using DNF
1. Exclude PHP Packages
For systems using dnf, such as newer versions of Fedora:
Edit DNF Configuration: Open the configuration file:
sudo nano /etc/dnf/dnf.conf
Add Exclusion: Add the following line to exclude PHP packages:
exclude=php* php-*Lock the Package Version
Similar to yum, you can use the dnf versionlock plugin:
Install the Versionlock Plugin:
sudo dnf install dnf-plugin-versionlock
Lock the Packages:
sudo dnf versionlock add php php-cli php-fpm php-common
Conclusion
Disabling automatic updates for PHP can be crucial for maintaining system stability and ensuring compatibility with your applications. By pinning package versions or using package management tools to lock specific versions, you can avoid unexpected changes and ensure that your server runs smoothly. Remember to periodically review your PHP version and test updates in a staging environment to keep your server secure and up-to-date.