Php *. php and/usr/local/php/bin/php *. php-PHP source code

Source: Internet
Author: User
Let's take a look at the differences between php *. php and usrlocalphpbinphp *. php in php. We can take a look at this small Editor. Next let's take a look at an article about php *. php and/usr/local/php/bin/php *. what is the difference between php? This small editor does not understand yet. Let's take a look at it.

Script ec (2); script

This is a basic concept. Many people may encounter this situation. Some PHP programs will be executed under the linux Command Line for deployment reasons, so php commands will be used for execution. For example:

Php index. php

Very convenient, but there will also be some problems, such:

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 are collectively referred to as the Class not found in problem. in fact, the reason seems to be that we have not added the extension, but the question will come out from here,

How to add these extensions?

Why don't these problems occur in the same environment when the browser accesses the web program, and these extension classes can be called normally?

For question 1, for many online tutorials, you can enter google.com and then enter Linux php to add a certain extension. Let's focus on Question 2.

Determine the problem. We will take the lnmp environment as an example to analyze it step by step,

First of all, these extension classes are related to php. Is the loading successful through php. ini? We initially determined whether different php. ini is used on both sides?

Next, we output phpinfo () in different places to view the basic information of php,

In linux:

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

The above information shows that the php on both sides is completely different. To confirm, we verified that the previous php program with/usr/local/php/bin/php was executed and found that all the normal PDO, Curl, and Redis calls were normal.

Why is this happening first?

That's because, after you install PHP, you "inadvertently" perform the php installation and compilation operation again, resulting in two different php files. INI file, php in lnmp environment. ini is placed in/usr/local/php/etc/php. ini. Special Operations are stored in/etc/php by default. ini, And If php * is not configured *. php environment variable, which reads/etc/php by default. configuration Information in ini. As a result, the use of php commands in linux is inconsistent with that in web.

The problem is found. How can this problem be solved?

Delete the compiled php installation in the "casual" Operation

Configure the php environment variables and direct the php Command to/usr/local/php/bin/php. We will use centOS as an example to configure the environment variables:

[Root @ CentOS ~] # Vi/etc/profile

Edit the profile file and note that the following operations are permanently valid.

Add the following two lines of code to 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 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'
History Size = 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 cocould 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

If the modification takes effect immediately, run the following code:

[Root @ CentOS ~] # Source/etc/profile

Then, check the system environment variables to see that the added item has taken 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 the php Command and/usr/local/php/bin/php is an effect, pointing to the same php. ini file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.