How set an environment variable in PHP with Apache/FastCGI?

前端 未结 1 1303
不知归路
不知归路 2021-01-15 13:55

I need to define an environment variable named SQLANY17 and this variable should be available in PHP (i.e. under \"Environment\" in the standard phpinfo(

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-15 14:29

    First, you need to make sure the module is loaded. Are you sure it is?

    PHP applications are usually configured using the FcgidWrapper directive and a corresponding wrapper script. The wrapper script can be an appropriate place to define any environment variables required by the application, such as PHP_FCGI_MAX_REQUESTS or anything else. (Environment variables can also be set with FcgidInitialEnv, but they then apply to all applications.)

    Here is an example that uses a wrapper script to invoke PHP:

    PHP application - /usr/local/phpapp/phpinfo.php

    
    

    Configuration directives

    # FcgidMaxRequestsPerProcess should be <= PHP_FCGI_MAX_REQUESTS
    # The example PHP wrapper script overrides the default PHP setting.
    FcgidMaxRequestsPerProcess 10000
    
    # Uncomment the following line if cgi.fix_pathinfo is set to 1 in
    # php.ini:
    # FcgidFixPathinfo 1
    
    Alias /phpapp/ /usr/local/phpapp/
    
    AddHandler fcgid-script .php
    Options +ExecCGI
    FcgidWrapper /usr/local/bin/php-wrapper .php
    
    # Customize the next two directives for your requirements.
    Order allow,deny
    Allow from all
    
    

    PHP wrapper script - /usr/local/bin/php-wrapper

    #!/bin/sh
    # Set desired PHP_FCGI_* environment variables.
    # Example:
    # PHP FastCGI processes exit after 500 requests by default.
    PHP_FCGI_MAX_REQUESTS=10000
    export PHP_FCGI_MAX_REQUESTS
    
    # Replace with the path to your FastCGI-enabled PHP executable
    exec /usr/local/bin/php-cgi
    

    Referenced: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

    0 讨论(0)
提交回复
热议问题