search

Home  >  Q&A  >  body text

php - 系统环境变量的使用

我设置了环境变量
export SMARTY_DIR='/usr/local/lib/Smarty/'

echo $SMARTY_DIR
/usr/local/lib/Smarty/

为何这个验证无法执行
<?php
require_once(getenv("SMARTY_DIR").'Smarty.class.php');
$smarty  = new Smarty();
$smarty->testInstall();
?>

写成这样就可以
<?php
require_once('/usr/local/lib/Smarty/Smarty.class.php');
$smarty  = new Smarty();
$smarty->testInstall();
?>    



PHP中文网PHP中文网2914 days ago280

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-10 17:40:08

    你是在执行 export 的那个 shell 里运行的 PHP 程序吗?环境变量只对子进程有效的。

    reply
    0
  • Cancelreply