惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
T
Tenable Blog
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hacker News: Front Page
S
Secure Thoughts
AWS News Blog
AWS News Blog
L
LINUX DO - 最新话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
MIT News - Artificial intelligence
T
Tor Project blog
S
Schneier on Security
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
美团技术团队
Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
罗磊的独立博客
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V
V2EX
C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
D
Docker
J
Java Code Geeks
GbyAI
GbyAI
H
Heimdal Security Blog
The Hacker News
The Hacker News
MongoDB | Blog
MongoDB | Blog
V
Vulnerabilities – Threatpost
T
Tailwind CSS Blog
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
C
CERT Recently Published Vulnerability Notes
Y
Y Combinator Blog
Recorded Future
Recorded Future
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
The Register - Security
The Register - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - zakun

适配 WSL 的 proxy 完整脚本 Gitlab CI 本地开发部署 Golang grpc 实践 Mongo 聚合演示 真・一键激活 JetBrains 全家桶! Kafka 分区细说 解决国内Homebrew安装 Homebrew How to Install PHP Install Elasticsearch with Docke wsl2 网络相关设置 php docker image nginx 反向代理常用设置说明 Golang常见的并发模式 Gin框架的几种热加载方法 协程 Mysql Full-Text Index 介绍 gitlab runner 使用摘要 Gitlab Docker 使用摘要 Docker 简介 linux-查看文件夹大小 Linux 如何删除乱码文件-inode删除 Nginx反爬虫: 禁止某些User Agent抓取网站
PHP添加$_SERVER服务器环境变量
zakun · 2022-12-23 · via 博客园 - zakun

PHP添加$_SERVER服务器环境变量

  • 通过nginx的fastcgi_param来设置
  • 通过php主配置文件php-fpm.conf来设置
  • 通过Apache设置环境变量

NGINX 设置

  • 通过nginxfastcgi_param来设置

在nginx配置文件中,可以在nginx总体的配置文件nginx.conf中,也可以在单独的网站配置环境中进行设置,如:www.regskynet.com.conf, 如果要添加自定义的RUNTIME_ENVIROMENT的server变量

location ~ .php$ { 
	limit_conn conn_zone 15; 
	limit_req zone=req_zone burst=25 nodelay; 
	try_files $uri /index.php =404; 
	fastcgi_split_path_info ^(.+.php)(/.+)$; 
	root $root; f
	astcgi_pass 127.0.0.1:9000; 
	fastcgi_index index.php; 
	fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name; 
	include fastcgi_params; 
	fastcgi_param RUNTIME_ENVIROMENT 'PRO'; 
}

然后重启重启nginx

nginx -s reload

php-fpm 设置

这个设置必须放在主配置文件php-fpm.conf里,不能放到include指令设置的子配置文件里,否则会报错

Array are not allowed in the global section

如果php-fpm.conf位置在/etc/php-fpm.conf 直接在配置文件中添加

env[RUNTIME_ENVIROMENT] = 'PRO'

添加后重启php-fpm

service php-fpm reload

通过上面2种方式添加$_SERVER变量值后,我们就可以直接在php文件中通过$_SERVER来获取相应的变量值了

Apache设置

语法格式如下

SetEnv 变量名 变量值

配置如下

<VirtualHost *:80> 
ServerAdmin ... 
DocumentRoot ... 
ServerName www.regskynet.com 
ErrorLog ... 
CustomLog ... 
SetEnv RUNTIME_ENVIROMENT PRO 
<Directory "..."> 
Options Indexes FollowSymLinks 
AllowOverride All 
Require all granted 
</Directory> 
</VirtualHost>