Table of Contents
Quick solution:
Specific process:
Home Backend Development PHP Problem Why are the PHP versions output by php -v and phpinfo() inconsistent?

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

Aug 15, 2020 am 10:50 AM
php version

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}
Copy after login
Copy after login

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

source ~/.bash_profile
Copy after login
Copy after login

Then execute

source ~/.zshrc
Copy after login

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

sudo killall php-fpm
Copy after login
Copy after login
sudo php-fpm -D
Copy after login
Copy after login

Specific process:

1. Check the current php version

php -v
Copy after login

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
Copy after login

2. Check the php installation location

which php
Copy after login

or

whereis php
Copy after login

and get the following output:

/usr/local/Cellar/php@7.2/7.2.23/bin/php
Copy after login

3. Check the php-fpm version and installation location

php-fpm -v
Copy after login

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
Copy after login
which php-fpm
Copy after login

Get the following output:

/usr/sbin/php-fpm
Copy after login

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}
Copy after login
Copy after login

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

source ~/.bash_profile
Copy after login
Copy after login

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
Copy after login

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
Copy after login
Copy after login

Start php-fpm and run it in the background:

sudo php-fpm -D
Copy after login
Copy after login

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 of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP version development history (1995-2022) PHP version development history (1995-2022) Jun 01, 2020 pm 01:59 PM

As a PHP learner and developer, how can I not understand its history? The following PHP Chinese website will lead PHP enthusiasts to review the various historical versions of PHP.

Pagoda Panel Tutorial: A Simple Guide to PHP Version Switching Pagoda Panel Tutorial: A Simple Guide to PHP Version Switching Mar 05, 2024 am 09:27 AM

Pagoda Panel is a powerful and easy-to-use server management panel that can help users easily manage websites, databases, FTP and other services. In the process of using the Pagoda Panel, sometimes you need to switch the PHP version to adapt to different website needs. This article will provide you with a simple guide for PHP version switching, and provide specific code examples to help readers quickly complete the PHP version switching operation. First, we need to log in to the Pagoda panel and enter the website settings page. Find the "Website" option in the left navigation bar and click

Pagoda Panel Operation Guide: Sharing PHP Version Switching Tips Pagoda Panel Operation Guide: Sharing PHP Version Switching Tips Mar 04, 2024 am 10:42 AM

BTPanel is a powerful and easy-to-use server management panel that can help users easily manage servers, websites, databases and other services. As a website developer or administrator, it is very important to master the skills of switching PHP versions in the Pagoda panel. In this article, we will share how to operate and switch PHP versions in the Pagoda panel, and provide specific code examples to help readers better master this skill. 1. Log in to the Pagoda panel. First, enter the server IP address or domain name in the browser, and add the Pagoda

How to update PHP version in Eclipse How to update PHP version in Eclipse Mar 28, 2024 pm 09:54 PM

Eclipse is a widely used integrated development environment (IDE) that can be used to develop projects in various programming languages. When using Eclipse to develop PHP projects, it is sometimes necessary to update the PHP version to adapt to new features or fix bugs. This article will explain how to update the PHP version in Eclipse and provide specific code examples. 1. Preparations for updating the PHP version Before updating the PHP version, we need to ensure that Eclipse and the PHP development environment have been installed. in addition,

Understand the meaning and importance of PHP version NTS Understand the meaning and importance of PHP version NTS Mar 27, 2024 pm 12:15 PM

The meaning and importance of PHP version NTS PHP (Hypertext Preprocessor) is a widely used open source server-side scripting language that is used to develop dynamic web pages. PHP versions include NTS (Non-ThreadSafe) and TS (ThreadSafe). In this article, we will focus on the meaning and importance of NTS versions and provide some concrete code examples. The NTS version refers to the non-thread-safe version of PHP, which was originally designed to

How to deal with errors caused by PHP version upgrade How to deal with errors caused by PHP version upgrade May 11, 2023 am 08:48 AM

When developing a website or application using PHP, version upgrades are a necessary task because each version brings new features and fixes known issues. However, PHP version upgrades can also introduce new bugs because the new version may no longer support the functionality or syntax of the older version. In this article, we will introduce how to deal with errors caused by PHP version upgrade to ensure the normal operation of the application. 1. Back up the application and server. Before upgrading the PHP version, you must back up the application and server. The backup application can be

How do version updates of PHP functions affect development? How do version updates of PHP functions affect development? Apr 18, 2024 pm 02:54 PM

Impact of PHP function version updates: Impact of new features: New features are introduced to facilitate the development of complex tasks. Fix the impact of the bug: Improve function behavior and improve code stability. Impact of behavior change: Most disruptive, requiring updates to code that uses the function. Best practices: Test updates in a test environment, check interactive code, and update affected dependencies.

New features of PHP7 version and their impact on mini program development New features of PHP7 version and their impact on mini program development Jul 04, 2023 pm 06:15 PM

New features of PHP7 version and their impact on mini program development. With the continuous development of technology, the Internet industry is also changing with each passing day. In recent years, mini programs have become a hot topic in mobile application development. At the same time, the release of PHP7 version has also become the focus of developers' attention. This article will explore the new features of the PHP7 version and analyze its impact on the development of small programs. 1. New features of PHP7 version As a major update of the PHP language, PHP7 version brings many new features and performance improvements. Here are a few important new features: Sex

See all articles