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:


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

Pin: version 7.4.*

Pin-Priority: 1001

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

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

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

Similar to yum, you can use the dnf versionlock plugin:

Install the Versionlock Plugin:

sudo dnf install dnf-plugin-versionlock



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.