使php变量/常量可用于所有网站的所有脚本 [英] Make php variable/constant available to all scripts ad all sites
问题描述
我在自己的Apache虚拟主机上有大约150个网站,它们在ubuntu 16上运行php7.每个网站的根目录中都有一个config.php,其中包含常量:define('MYVAR','myval'); >
我想创建一个新的常数,我必须每2个月左右更新一次.我不想打开每个配置并对其进行编辑.如何让每个站点/虚拟主机都知道我要设置的常数.我想像$ _SERVER ['REMOTE_ADDRESS']一样随处可见;是.
我不想创建一个文件,将它们符号链接到每个站点,那很麻烦.我想编辑apache配置或在某个地方编辑php配置以在其中具有define().
这是可能的吗?还是我卡住了sym链接文件或编辑所有配置?
如果要使某些变量在PHP中全局可用,则需要在apache配置文件中添加这些变量.
(如果使用的是ubuntu open /etc/apache2/apache2.conf
文件),并且如果使用的是windows open httpd.conf
.并添加以下行.
SetEnv VARIABLE_NAME您想要的任何值"
I have about 150 websites each on its own Apache virtual host running php7 on ubuntu 16. Each site has a config.php in the root dir with constants in it: define('MYVAR','myval');
I want to make a new constant that I will have to update every 2 months or so. I don't want to open each config and edit them. How can I have each site/virtual host be aware of this constant I want to set. I want to be available everywhere just like $_SERVER['REMOTE_ADDRESS']; is.
I do not want to create a file them symlink it to each site, thats messy. I would like to edit the apache config or edit a php config someplace to have a define() in it.
Is this possibe? or am I stuck sym linking a file or editing all my configs?
If want to make some variables globally available in PHP you need to add those variable in the apache config file.
if you're using ubuntu open /etc/apache2/apache2.conf
file, And if you're using windows open httpd.conf
. And add the following line.
SetEnv VARIABLE_NAME 'whatever value you want'
这篇关于使php变量/常量可用于所有网站的所有脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!