php *.php和/usr/local/php/bin/php *.php的区别

单独编译php7,并安装在/usr/local/php7/中,今天开发插件修改了 php.ini 的配置信息,但是什么都没生效。

下来我们就在不同的地方输出phpinfo()查看php的基本信息,果然,

图片 1

怎么加入这些扩展?

解决

在文件末尾加上如下两行代码

strace /usr/local/php7/sbin/php-fpm -i 2>1.log

PATH=/usr/local/php/bin:$PATH

它会去找/usr/local/lib/php.ini,我也不知道为什么,我编译是有设置--with-config-file-path=/xxx/xxx。反正找到具体路径了,把php.ini拷过去就解决了。

要是刚才的修改马上生效,需要执行以下代码

打开文件发现:

问题找到了,改怎么解决的?

另外我strace /usr/local/php7/bin/php -i 2>1.log发现,如果不是php-fpm而是php,它会找/usr/local/php7/bin/php.ini,原因未知。

说一个基本概念,很多人可能会遇到过这种情况,有些PHP程序因为部署原因会在linux命令行下执行,这样就会用到php命令执行,例如:

图片 2

现在使用php命令和/usr/local/php/bin/php是一个效果了,指向了同样的php.ini文件。

通过phpinfo()查看配置信息:

配置php环境变量,让php命令指向/usr/local/php/bin/php,我们以centOS为例配置环境变量进行说明:

前言

linux环境下:

排查

Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini

用strace去跟踪一下:

# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}
if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`id -u`
        UID=`id -ru`
    fi
    USER="`id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi
HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
    umask 002
else
    umask 022
fi
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null 2>&1
        fi
    fi
done
unset i
unset pathmunge
PATH=/usr/local/php/bin:$PATH
export PATH

发现Loaded Configuration File => (none),表明没有载入php.ini文件。然而/usr/local/php7/etc/php.ini这个文件确实是存在的。

Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

为什么会出先这样的情况呢?

确定问题现象,我们以lnmp环境为例,一步步分析,

通过上面的信息可以看出,两边用的php完全是不一样的,为了确定,我们验证了下通过/usr/local/php/bin/php来执行先前的报错的php程序,发现一切正常PDO,Curl,Redis都正常调用。

删除“不经意”的操作中安装编译的php

本文由美洲杯赌球发布于计算机教程,转载请注明出处:php *.php和/usr/local/php/bin/php *.php的区别

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。