The Missing Link: Fixing PHP 7.2 PATH Issues on CentOS 7
When installing a specific version of PHP like 7.2 on CentOS 7 using Remi's repository, you often encounter a scenario where php72 --version works perfectly, but the standard php command remains elusive. This isn't necessarily a broken installation; it is almost exclusively a shell environment issue caused by how the system prioritizes binaries in your search path.
The tutorial you are referencing installs the package correctly into /usr/bin/php72. However, CentOS 7 ships with its own version of PHP (usually 5.4 or 5.6) located at /usr/bin/php. When you run php, the system executes the default binary found first in your $PATH variable, not the newly installed 7.2 build. To make the new installation work seamlessly with scripts and frameworks that rely on the generic php command, you must update your shell environment to prioritize the newer version.
Understanding the Binary Conflict
The root cause lies in the order of entries within your shell configuration files. When the shell resolves a command like php, it scans directories listed in the $PATH variable from left to right. If /usr/bin (the default system location) appears before your custom installation path, the older PHP version executes.
In many manual installations, or when using EPEL without Remi, this might not be an issue because no conflicting versions exist. However, mixing a system PHP with a third-party repository like Remi often results in this conflict. The php72 command works because it is explicitly named to distinguish itself from the default package, but standard development tools and web servers expect php to resolve to the active interpreter.
Resolving the PATH Issue
To fix this, you need to ensure that the directory containing php72 appears before /usr/bin in your $PATH. The specific path depends on how Remi installed the binaries, but they are typically located in a dedicated directory for that version.
Check which directory holds your new binary:
which php72
This will likely return something like /usr/bin/php72 or a path under /opt/remi/php72/. If the command is found directly in /usr/bin, you are still dealing with the conflict mentioned earlier.
You have two primary strategies to resolve this: updating your shell profile or creating an alias.
Updating Your Shell Profile
The cleanest solution is to modify your environment configuration file (e.g., ~/.bashrc or ~/.profile). Add the following line before any existing path settings that reference system binaries, or ensure it sits above them:
export PATH="/usr/bin/php72:$PATH"
Note: If Remi installed binaries to a subdirectory like /usr/bin/remi-php72, you must adjust the path accordingly based on the output of which php72.
After adding this line, reload your shell configuration without logging out:
source ~/.bashrc
Verify the fix by running php --version. It should now display PHP 7.2.x instead of the system default or an error message.
Using a Symlink (Alternative Approach)
If you prefer not to manage path precedence, you can create a symbolic link from php to php72 in /usr/bin. However, be cautious with this method. Since /usr/bin is owned by the root user and managed by the system package manager, modifying it directly might break on future updates or require elevated privileges.
sudo ln -s /usr/bin/php72 /usr/bin/php
This approach overrides the default binary entirely. While effective for local development, it can cause issues if other services expect the legacy PHP version to remain untouched.
Integrating with Web Servers
Once the CLI is working correctly, ensure your web server (Apache or Nginx) also targets the correct interpreter. If you installed PHP-FPM for this version, verify that your php.ini configuration and the web server's cgi-fcgi or fastcgi settings point to the PHP 7.2 binary or socket path provided by Remi. A mismatch here will result in a "502 Bad Gateway" error or a fallback to the old PHP version, defeating the purpose of the upgrade.
For Laravel developers specifically, ensuring the CLI matches your server environment is critical for caching operations and artisan commands. If you are managing production environments, consider using phpenv or asdf to manage multiple versions cleanly rather than relying on system PATH manipulation, which can be fragile in containerized or orchestrated setups.