# $document\_root variable not working

**URL:** <https://www.ruby-forum.com/t/document-root-variable-not-working/220027>\
**Category:** NGINX\
**Created:** [May 24, 2012, 11:45pm UTC](https://www.ruby-forum.com/t/document-root-variable-not-working/220027 "2012-05-24T23:45:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 24, 2012, 11:45pm UTC](https://www.ruby-forum.com/t/document-root-variable-not-working/220027/1 "2012-05-24T23:45:53Z")

</div>

Hi,

I’m running nginx 1.2.0 under FreeBSD 9.0.  
I configured phpMyAdmin to execute unter  
[https://server/pma](https://server/pma)  
which is working fine, but php scripts outside  
/pma I get “File not found.”  
(e.g. [https://server/info.php](https://server/info.php))

this is my config:

location / {  
root /usr/local/www/nginx;  
index index.html index.php;  
}

location /pma {  
root /usr/local/www;  
index index.php;  
}

location ~ .php$ {  
set $php\_root $document\_root;  
if ($request\_uri ~\* /pma) {  
set $php\_root /usr/local/www;  
}

```
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
 include /usr/local/etc/nginx/fastcgi_params

```

}

The problem is the config line  
set $php\_root $document\_root;  
When I replace it with  
set $php\_root /usr/local/www/nginx;  
everything is okay. I found in the documentation,  
that $document\_root should contain the value  
of “root”, but obvious it isn’t.

Any ideas whats wrong?

Regards,  
Tom.

---

<div class="post-metadata">

**Author:** ![Thomas\_Krause](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aeb1de/32.png) [@Thomas\_Krause](https://www.ruby-forum.com/u/Thomas_Krause)\
**Post date:** [May 25, 2012, 12:43am UTC](https://www.ruby-forum.com/t/document-root-variable-not-working/220027/2 "2012-05-25T00:43:26Z")

</div>

On Thu, May 24, 2012 at 11:45:07PM +0200, Thomas Krause wrote:

Hi there,

> The problem is the config line  
> set $php\_root $document\_root;  
> When I replace it with  
> set $php\_root /usr/local/www/nginx;  
> everything is okay.

You’ve found a configuration that works for you, so there is no need to  
change anything.

If you choose to change things, I would suggest removing the  
if-within-location, and removing the top-level regex location – and  
duplicating the php configuration.

But that’s mostly for future convenience.

> I found in the documentation,  
> that $document\_root should contain the value  
> of “root”, but obvious it isn’t.

Why do you think that it isn’t?

What do you think “root” is set to within your “location ~ .php$”  
block?

(Hint: the configuration you have shown does _not_ show what it is set  
to.)

> Any ideas whats wrong?

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

is my guess.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
