skip to Main Content

I’m having trouble using Server environment variables with Apache.

Here is some info about the environment :

  • OS : Debian 8.10 Jessie
  • Web hosting plateform : Plesk
  • PHP : 7.1.8

Executing scripts that use the environments variables work fine if I execute with PHP-CGI, but if I execute the script though the web page, I can’t recuperate the environment variables.

The user is different when accessing the script through a web page but i can’t load the environment variables for the page.

So far, i’ve tried setting the environment variables in :

  • /etc/environment
  • .bashrc of the user
  • .htaccess
  • apache2ctl
  • PHP commande “putenv”
  • ld.so.conf.d

So far, nothing works.

My question : how can i recuperate environment variables though a web page and not with php-cgi?

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Ok after 3 weeks of trial and error i have found the solution for my case.

    Here are the steps i had to take to make it work:

    1. Change from PHP fastCGI to FPM served by apache
    2. Add the following code to /opt/php7.1/etc/php-fpm.d/mydomaine.conf

    [php-fpm-pool-settings] env[LD_LIBRARY_PATH]="/var/www/vhosts/localhost.localdomain/httpdocs/sqlanywhere16/lib64:/var/www/vhosts/localhost.localdomain/httpdocs/sqlanywhere16/lib32"

    1. Execute the commands :

    ldconfig -v

    ldconfig -p

    1. Restart the server

  2. If you use Plesk, you can add to “Additional directives” on PHP of your subscription:

    [php-fpm-pool-settings] 
    env[some_env_variable]="cool-value"
    

    enter image description here

    Then, when you check to phpinfo() you can see this:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search