在哪里取消设置或更改 $_SERVER['LD_LIBRARY_PATH']?

在哪里取消设置或更改 $_SERVER['LD_LIBRARY_PATH']?

我有一个 Apache 2.4 代理到 PHP7.4.4 php-fpm,并且我正在尝试隐藏或取消设置 $_SERVER['LD_LIBRARY_PATH'] 变量。

如何在 PHP 输出中更改或删除此变量 $_SERVER['LD_LIBRARY_PATH']?

假设apache2.4安装到/apache24。

==userX-fpm-pool.conf==
[userX]
user = userX
group = userX
listen = 127.0.0.1:9003
clear_env = yes
env['LD_LIBRARY_PATH'] = /fakepath

==php.ini==
variables_order = "GPCS"

==userX-vhost.conf==
<VirtualHost *:80>
    ServerName userX.xxxxxx.com

    ServerAdmin webmaster@localhost
    DocumentRoot /userX/home/www

    UnsetEnv LD_LIBRARY_PATH

    <Directory /userX/home/www>
            Options Indexes FollowSymLinks
            DirectoryIndex index.php index.html
            Require all granted
            AllowOverride All
    </Directory>

    ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9003/"
</VirtualHost>

==index.php==
<?php
print_r($_ENV);
print_r($_SERVER);

卷曲输出:

curl -H "Host: userX.xxxxxx.com" http://127.0.0.1
Array
(
)
Array
(
    [LD_LIBRARY_PATH] => /apache24/lib --> How do I change or get rid of this variable?
    [USER] => userX
    [HOME] => /home
    [SCRIPT_NAME] => /index.php
    [REQUEST_URI] => /
    [QUERY_STRING] =>
    [REQUEST_METHOD] => GET
    [SERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [REMOTE_PORT] => 49248
    [SCRIPT_FILENAME] => //index.php
    [SERVER_ADMIN] => webmaster@localhost
    [CONTEXT_DOCUMENT_ROOT] => /userX/home/www
    [CONTEXT_PREFIX] =>
    [REQUEST_SCHEME] => http
    [DOCUMENT_ROOT] => /userX/home/www
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_NAME] => userX.xxxxxx.com
    [SERVER_SOFTWARE] => Apache/2.4.43 (Unix) OpenSSL/1.1.1 PHP/7.4.4
    [SERVER_SIGNATURE] =>
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    [HTTP_ACCEPT] => */*
    [HTTP_USER_AGENT] => curl/7.58.0
    [HTTP_HOST] => userX.xxxxxx.com
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1587830093.9565
    [REQUEST_TIME] => 1587830093
)

答案1

不要“print_r($_SERVER);”,它就不会出现在您的输出中。它是 Apache(= 服务器)启动时设置的环境变量。您可以在 Apache 启动脚本或 Apache 配置中对其进行操作。如果您删除它,Apache 不再启动也不要感到惊讶。

答案2

解决了。​​解决方案是注释掉 httpd-2.4.3 的 bin 目录中 envvars 文件中的 LD_LIBRARY_PATH 设置和导出行,然后将 FPM 池配置文件更改为所需的环境值。由于 lib/ 目录用于外部链接,而我不需要它,因此 apachectl 可以正常启动。唯一需要注意的是 ./apachectl restart 不起作用,您必须手动执行 ./apachectl stop,然后执行 ./apachectl start 才能使更改生效。

==envvars==
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# envvars-std - default environment variables for apachectl
#
# This file is generated from envvars-std.in
#
#if test "x$LD_LIBRARY_PATH" != "x" ; then
#  LD_LIBRARY_PATH="/apache24/lib:$LD_LIBRARY_PATH"
#else
#  LD_LIBRARY_PATH="/apache24/lib"
#fi
#export LD_LIBRARY_PATH
#

==userX-fpm-pool.conf==
[userX]
user = userX
group = userX
listen = 127.0.0.1:9003
clear_env = yes
env['LD_LIBRARY_PATH'] = /fakepath


root@instance:/apache24/bin# ./apachectl stop && ./apachectl start

curl -H "Host: userX.xxxxxx.com" http://127.0.0.1
Array
(
)
Array
(
    [LD_LIBRARY_PATH] => /fakepath
    [USER] => userX
    [HOME] => /home
    [SCRIPT_NAME] => /index.php
    [REQUEST_URI] => /
    [QUERY_STRING] =>
    [REQUEST_METHOD] => GET
    [SERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [REMOTE_PORT] => 49348
    [SCRIPT_FILENAME] => //index.php
    [SERVER_ADMIN] => webmaster@localhost
    [CONTEXT_DOCUMENT_ROOT] => /userX/home/www
    [CONTEXT_PREFIX] =>
    [REQUEST_SCHEME] => http
    [DOCUMENT_ROOT] => /userX/home/www
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_NAME] => userX.xxxxxx.com
    [SERVER_SOFTWARE] => Apache/2.4.43 (Unix) OpenSSL/1.1.1 PHP/7.4.4
    [SERVER_SIGNATURE] =>
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    [HTTP_ACCEPT] => */*
    [HTTP_USER_AGENT] => curl/7.58.0
    [HTTP_HOST] => userX.xxxxxx.com
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1587866614.9455
    [REQUEST_TIME] => 1587866614
)

相关内容