Set Server for PHP apache/nginx environment variable win7 apache Apache struts2 Apache

Source: Internet
Author: User
Tags php server
Setting environment variables common places to differentiate a development environment/production environment, or to define account passwords for some databases

Setting Apache Environment variables

Instructions

Sets the current environment variable toDEV

SETENV runtime_enviroment DEV

Database account password

SetEnv mysql_username rootsetenv Mysql_password Root

Configuration file format

 
  
   
      ServerAdmin admin@admin.com    documentroot "/var/www/"    ServerName localhost    SetEnv runtime_enviroment DEV    SETENV mysql_username Root    SETENV Mysql_password root    errorlog "Logs/error.log"    customlog "Logs/access.log" common
 
  

Setting Nginx Environment variables

Instructions

Sets the current environment variable toDEV

Fastcgi_param runtime_enviroment ' DEV '

Database account password

Fastcgi_param mysql_username ' root ' fastcgi_param mysql_password ' root '

Configuration file format

Configuring in the Fastcgi_params file

Fastcgi_param runtime_enviroment ' DEV '; fastcgi_param mysql_username ' root '; Fastcgi_param mysql_password ' root ';

Configuring in Nginx.conf

server {    listen   ;     root/var/www;    Index index.php;    server_name localhost;    Location/    {            index index.php;    }       Location ~. *\. (PHP|PHP5) $ {        Fastcgi_pass 127.0.0.1:9000;        Fastcgi_index index.php;        Include Fastcgi_params;    }   }

Setting environment variables for PHP scripts

Temporarily set for the current user

Temporary settings only need to be performed

Export Key=value

Permanently set for the current user

~/.bashrcwritten in (different systems vary)

Set for all users (not including root)

Create /etc/profile.d/test.sh a file, write

Key=value

Set for all users (including root)

In the /etc/environment write

Key=value

Note that this file's effective time is when the user logs in, so for root, the machine needs to be restarted

Set in supervisor

Sometimes PHP scripts are controlled with supervisor, so remember to set the environment in the supervisor configuration

Invoking server environment variables in PHP

There are two ways to call in PHP:

$env = getenv (' runtime_enviroment ');

There are also hyper-global variable modes:

$env = $_server[' runtime_enviroment ');

The above describes the settings for PHP server Apache/nginx environment variables, including the apache,nginx aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.