To say a basic concept, many people may have encountered this situation, some PHP programs for deployment because of the Linux command line execution, which will use the PHP command execution, such as:
PHP index.php
Very convenient, but there are also some problems, such as:
PHP Fatal error:class ' PDO ' not found in
PHP Fatal error:class ' Curl ' not found in
PHP Fatal error:class ' Redis ' not found in
... And so on, we collectively refer to the class not found in problem, but the reason seems to have not joined the expansion, but the question comes out from here,
How do you add these extensions?
Why is it that sometimes the same environment does not have these problems when the browser accesses the Web application, and can call these extended classes normally?
For question 1, many tutorials on the web can input google.com and then enter Linux PHP to join a certain extension to see the solution, we focus on the question 2.
To determine the problem, we take LNMP environment as an example, step-by-step analysis,
First of all, these extension classes and PHP are related to the success of loading through the php.ini to see, we initially judged on both sides is not using a different php.ini?
Down we'll be in different places output phpinfo () to view the basic information of PHP, sure enough,
Linux Environment:
Configuration File (php.ini) Path =>/etc
Loaded Configuration File =>/etc/php.ini
In the Web environment:
Configuration File (php.ini) Path =>/usr/local/php/etc
Loaded Configuration File =>/usr/local/php/etc/php.ini
Through the above information can be seen, on both sides of the PHP is completely different, in order to determine, we verified the next through the/usr/local/php/bin/php to execute the previous error of the PHP program, found that all normal pdo,curl,redis normal call.
Why does this happen first?
That is because, after you install PHP, "inadvertently" in the operation of a PHP installation and compile operations, resulting in the storage of two different php.ini files, LNMP environment under the php.ini is placed in/usr/local/php/etc/ PHP.ini, Special operations are placed by default in/etc/php.ini, and if you do not configure the PHP *.php environment variable, he will read the configuration information under/etc/php.ini by default. This leads to the use of PHP commands under Linux and inconsistent results under the web.
The problem has been found, how to solve it?
To remove a compiled PHP from an "inadvertent" operation
Configure the PHP environment variable, let the PHP command point to/usr/local/php/bin/php, we take CentOS as an example to configure the environment variable to explain:
[Root@centos ~]# Vi/etc/profile
Edit profile, note that the following actions are permanently valid.
Add the following two lines of code at the end of the file
Path=/usr/local/php/bin: $PATH
Export PATH
#/etc/profile
# System wide environment and startup programs, for login setup
# functions and aliases Go IN/ETC/BASHRC
# It's not a good the idea of this file unless your 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
# would prevent the need for merging in future updates.
Pathmunge () {
Case ": ${path}:" In
*: "$":*)
;;
*)
If ["$" = "after"]; Then
Path= $PATH: $
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 is the sets it for login shell
# current threshold to 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; Todo
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
If the modification takes effect immediately, you need to execute the following code
[Root@centos ~]# Source/etc/profile
Then look at the system environment variables, you can see what just added is already in effect
[Root@centos ~]# Echo $PATH
/usr/local/php/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Now using PHP commands and/usr/local/php/bin/php is an effect that points to the same php.ini file.