In this blog post, we’ll address a common issue encountered when trying to set a specific PHP version as the default on CentOS 7, specifically PHP 7.3, while avoiding an unexpected upgrade to PHP 8.0. Let’s go over the necessary steps to install PHP 7.3 and its related packages as the default without PHP 8.0 dependencies interfering.
When managing software installations on CentOS, it’s common to use the yum
package manager, which automatically resolves dependencies for the required software. However, this can sometimes lead to unintended outcomes, like installing an incompatible PHP version.
In this case, the problem arises because running:
does not lock the system to PHP 7.3 specifically. Despite enabling the remi-php73
repository, yum
may still select PHP 8.0 packages (from remi-php80
) as dependencies, resulting in a conflict with the existing project dependencies.
Step-by-Step Guide to Forcing PHP 7.3 as the Default
Let’s go through each step to ensure that only PHP 7.3 packages are installed and set as the default.
Step 1: Enable the Remi Repository
The Remi repository is a third-party repository that provides various PHP versions for CentOS. If you haven’t already done so, install and enable the Remi repository:
After this, enable the remi-php73
repository specifically:
Step 2: Install PHP 7.3 Packages Without Triggering PHP 8.0
Now that the remi-php73
repository is enabled, you’ll need to install PHP 7.3 and its related packages. Instead of using general PHP package names (like php
or php-cli
), specify php73-
prefixes to ensure that only PHP 7.3 versions are installed. Here’s how to do this:
Using the php73-
prefix ensures that yum
pulls only PHP 7.3 packages and avoids PHP 8.0.
Step 3: Set PHP 7.3 as the Default Version
After installing, you may still need to set PHP 7.3 as the system’s default PHP version. The update-alternatives
command can manage multiple PHP versions and select the default:
This will ensure that calling php
from the command line will use PHP 7.3.
Step 4: Verify the PHP Version
To confirm that PHP 7.3 is correctly set as the default, run:
You should see output similar to:
Step 5: Test PHP-FPM (Optional)
If you’re using PHP-FPM for web server integration, restart the php-fpm
service and make sure it’s the PHP 7.3 version:
Troubleshooting Common Issues
If you encounter any issues during installation, here are some common solutions:
Dependency Conflicts: Ensure no PHP 8.0 or other PHP packages are already installed. If they are, remove them with:
Then repeat the installation steps above.
Re-Enable the Remi Repository: If you switch between different PHP versions in the Remi repository, it may be necessary to disable or enable the desired version with:
PHP-FPM Service Name: Depending on the installed PHP version, the service name for PHP-FPM might vary (
php-fpm
,php73-php-fpm
). Verify the correct service name with:
Conclusion
Setting PHP 7.3 as the default version on CentOS 7 while avoiding PHP 8.0 dependencies requires a few specific steps. By enabling the correct repository, installing version-specific packages, and setting the default version, you can maintain a stable PHP environment tailored to your project’s requirements. Following these steps ensures compatibility and helps you avoid unexpected version conflicts in the future.
0 comments:
Post a Comment