search
HomeBackend DevelopmentPHP ProblemWhy are the PHP versions output by php -v and phpinfo() inconsistent?

The php version is inconsistent because the system's own php version and the newly installed php advanced version exist at the same time, and the location of the files loaded by the terminal and phpinfo are inconsistent. The solution is to put the higher version of php in the installation directory. The installation directory of the higher version "php-fpm" is also added to the terminal configuration file.

Why are the PHP versions output by php -v and phpinfo() inconsistent?

Recommended: "PHP Video Tutorial"

The problem is the PHP version that comes with the system and the new installation The advanced version of php exists at the same time, and the file locations loaded by the terminal and phpinfo() are inconsistent.

Among them,

nginx service parsing phpinfo() relies on php-fpm, so the output of phpinfo() is the version started by php-fpm;

And the terminal Executing php -v loads the php version corresponding to the php installation directory set in the terminal configuration file;

Therefore, the main cause of the inconsistency between the two php versions is started php-fpm The version is inconsistent with the php version configured in the terminal.

The direct solution is to add the high version php-fpm installation directory under the high version php installation directory to the terminal configuration file, so that the system can automatically load the high version php-fpm.

Quick solution:

Configuration~/.bash_profile:

export PATH=/usr/local/Cellar/php@7.2/7.2.23/bin:/usr/local/Cellar/php@7.2/7.2.23/sbin:${PATH}

If the system uses zsh, add it at the end of the ~/.zshrc file :

source ~/.bash_profile

Then execute

source ~/.zshrc

to make the configuration take effect, and restart php-fpm

sudo killall php-fpm
sudo php-fpm -D

Specific process:

1. Check the current php version

php -v

and get the following output:

PHP 7.2.23 (cli) (built: Oct 10 2019 10:15:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.23, Copyright (c) 1999-2018, by Zend Technologies

2. Check the php installation location

which php

or

whereis php

and get the following output:

/usr/local/Cellar/php@7.2/7.2.23/bin/php

3. Check the php-fpm version and installation location

php-fpm -v

Get the following output:

PHP 5.6.30 (fpm-fcgi) (built: Oct 29 2017 20:31:21)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
which php-fpm

Get the following output:

/usr/sbin/php-fpm

After checking the above , found that the installation directory loaded by php is the newly installed advanced version of php, and php-fpm is still the lower version that comes with the mac system. The reason is that the installation location of the new version of php is configured in the system terminal configuration file, but php-fpm is not configured. The installation location causes the system's lower version of php-fpm to be automatically loaded when starting php-fpm. When the php framework relies on a higher version of php, it will not run.

4. Configure the new version of php-fpm loading directory

Configuration~/.bash_profile:

export PATH=/usr/local/Cellar/php@7.2/7.2.23/bin:/usr/local/Cellar/php@7.2/7.2.23/sbin:${PATH}

If the system uses zsh, just ~/.zshrcAt the end of the file, add:

source ~/.bash_profile

or directly set the above path configuration in the ~/.zshrc file.

Then execute source ~/.zshrc to make the configuration take effect

5. Check the current php-fpm version

(base)  qingshan@qingshan  ~  php-fpm -v
PHP 7.2.23 (fpm-fcgi) (built: Oct 10 2019 10:15:34)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.23, Copyright (c) 1999-2018, by Zend Technologies

The higher version of php has been automatically loaded -fpm.

6. Restart php-fpm

Terminate the php-fpm process running in the background

sudo killall php-fpm

Start php-fpm and run it in the background:

sudo php-fpm -D

At this time The PHP version information output by phpinfo is the latest version 7.2

The above is the detailed content of Why are the PHP versions output by php -v and phpinfo() inconsistent?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment