Is it possible to use environment variables in php.ini?(是否可以在 php.ini 中使用环境变量?)
问题描述
我不想在我的 php.ini 配置中硬连接一些路径,而是想使用在其他一些地方(例如我的 Apache 配置)中共享的系统变量来配置它们.我已经进行了一些搜索,但找不到正确的关键字组合来发现是否有办法做到这一点.
Rather than hard-wiring some paths in my php.ini configuration, I'd like to configure them using system variables that are shared in some other places such as my Apache configuration. I've done some searching and couldn't find the right mix of keywords to discover if there's a way to do this.
有人知道这是否可以做到吗?
Does anyone know if this can be done?
upload_tmp_dir = $SCRATCH_HOME/uploads
现在 SCRATCH_HOME 可以在环境中导出为/tmp 或/var/scratch 或任何我想要的.
Now SCRATCH_HOME can be exported in the environment as /tmp or /var/scratch or whatever I want it to be.
推荐答案
官方文档:https://www.php.net/manual/en/configuration.file.php#example-36
在开始之前,我只想指定我的配置:我使用的是 Windows 7-64 位、PHP 5.4.3、Apache HTTP Server 2.2.x,我已经设置了环境变量 PHP_HOME=C: oolsphp-5.4.3
(PHP 安装目录).我在 httpd.conf
和 php.ini
文件
Before I begin, I just want to specify my configurations:
I'm using Windows 7-64bit, PHP 5.4.3, Apache HTTP Server 2.2.x, I've set my environmental variable PHP_HOME=C: oolsphp-5.4.3
(PHP installation directory).
I use the variable in my httpd.conf
and php.ini
file
注意:为简洁起见,我将省略一些文字.
Note: I will be omitting some text for brevity.
在httpd.conf
文件中
# For PHP 5 do something like this:
LoadModule php5_module "${PHP_HOME}/php5apache2_2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "${PHP_HOME}"
在php.ini
文件中
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "${PHP_HOME}/ext"
这篇关于是否可以在 php.ini 中使用环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 php.ini 中使用环境变量?
基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01