# Alias does not work with php

**URL:** <https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968>\
**Category:** NGINX\
**Created:** [December 17, 2011, 10:43am UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968 "2011-12-17T10:43:45Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [December 17, 2011, 10:43am UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/1 "2011-12-17T10:43:45Z")

</div>

Hello,

I’ve set up nginx 1.0.10 with php5-fpm. I’ve tested the setup and I can  
confirm that php works.  
The problem is when I set up an alias under “location /” nginx can’t  
load the php pages. Only static html files work.

Any ideas?

Thank you.

Posted at Nginx Forum:

> **[Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220191#msg-220191)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 1:56pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/2 "2011-12-17T13:56:26Z")

</div>

Hello!

On Sat, Dec 17, 2011 at 04:43:05AM -0500, tapir wrote:

> Hello,
> 
> I’ve set up nginx 1.0.10 with php5-fpm. I’ve tested the setup and I can  
> confirm that php works.  
> The problem is when I set up an alias under “location /” nginx can’t  
> load the php pages. Only static html files work.
> 
> Any ideas?

Most likely, you’ve forgot to add corresponding alias in your .php  
location.

Maxim D.

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 3:47pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/3 "2011-12-17T15:47:42Z")

</div>

yes I didn’t change anything there. why and how should I change it?

thank you

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220196#msg-220196)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 4:33pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/4 "2011-12-17T16:33:25Z")

</div>

On Sat, Dec 17, 2011 at 9:58 PM, tapir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve added “fastcgi\_param SCRIPT\_FILENAME  
> $document\_root/wordpress$fastcgi\_script\_name;”  
> and now it works.
> 
> As you might predict “$document\_root/wordpress” is the alias for  
> “location /”.  
> So what’s the correct way of doing this? I mean I have other aliases as  
> well and I would like php to work with those also.

combining alias and fastcgi (php) is the fastest way to get headache.  
Go with symlink instead.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 3:59pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/5 "2011-12-17T15:59:25Z")

</div>

I’ve added “fastcgi\_param SCRIPT\_FILENAME  
$document\_root/wordpress$fastcgi\_script\_name;”  
and now it works.

As you might predict “$document\_root/wordpress” is the alias for  
“location /”.  
So what’s the correct way of doing this? I mean I have other aliases as  
well and I would like php to work with those also.

Thanks

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220197#msg-220197)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 5:36pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/6 "2011-12-17T17:36:59Z")

</div>

On Sat, Dec 17, 2011 at 11:05 PM, tapir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ok, what exactly do you mean by symlink? is that a nginx feature or you  
> just mean plain old linux symbolic links?

plain old symlink.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 5:06pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/7 "2011-12-17T17:06:10Z")

</div>

ok, what exactly do you mean by symlink? is that a nginx feature or you  
just mean plain old linux symbolic links?

thank you

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220204#msg-220204)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 5:37pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/8 "2011-12-17T17:37:37Z")

</div>

On Sat, Dec 17, 2011 at 11:36 PM, Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sat, Dec 17, 2011 at 11:05 PM, tapir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ok, what exactly do you mean by symlink? is that a nginx feature or you  
> > just mean plain old linux symbolic links?
> 
> plain old symlink.

also, alias in “location /” doesn’t make sense.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 6:12pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/9 "2011-12-17T18:12:47Z")

</div>

On Saturday 17 December 2011 18:58:59 tapir wrote:

> I’ve added “fastcgi\_param SCRIPT\_FILENAME  
> $document\_root/wordpress$fastcgi\_script\_name;”  
> and now it works.
> 
> As you might predict “$document\_root/wordpress” is the alias for  
> “location /”.  
> So what’s the correct way of doing this? I mean I have other aliases as  
> well and I would like php to work with those also.

Why don’t you just use the “root” directive?

root /patch/to/wordpress;

location / {  
…  
}

and respectively:

fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 5:54pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/10 "2011-12-17T17:54:55Z")

</div>

ok I thought it didn’t. what I’m trying to do is to install the  
wordpress on it’s own directory under the document root but I want it to  
be accessible directly from [mydomain.com](http://mydomain.com). Wordpress allows you to do it  
actually but I need a web server level solution because if I change it  
in wordpress, it messes up some links (thousands) generated by poorly  
designed plugins.

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220207#msg-220207)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 6:22pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/11 "2011-12-17T18:22:05Z")

</div>

can I then use other scripts from /path/to/otherscript

my document root looks like this:

phpbb/  
wordpress/  
phpmyadmin/  
piwik/

but I only want wordpress to be accessible from the [mydomain.com](http://mydomain.com). Others  
should be accessible from [mydomain.com/phpbb](http://mydomain.com/phpbb) and so on…

maybe I should have asked this from the start 🙂 how can I achieve this?

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220209#msg-220209)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 18, 2011, 4:04pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/12 "2011-12-18T16:04:45Z")

</div>

thanks. that works.

but somehow I have to define all the fastcgi params everytime. for  
example can’t I just define fatscgi\_pass and fastcgi\_index once instead  
of everytime for a new location.

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220228#msg-220228)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 17, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/13 "2011-12-17T18:39:23Z")

</div>

On Sun, Dec 18, 2011 at 12:21 AM, tapir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> should be accessible from [mydomain.com/phpbb](http://mydomain.com/phpbb) and so on…
> 
> maybe I should have asked this from the start 🙂 how can I achieve this?

location /phpbb {  
root /some/where; #actual phpbb installation in /some/where/phpbb  
location ~ .php$ {  
fastcgi\_pass …;  
…  
}  
}  
location /wordpress {  
root /some/where\_else; #actual wordpress installation in  
/some/where\_else/wordpress  
location ~ .php$ {  
…  
}  
}  
…  
location / {  
root /some/where\_else/wordpress;  
location ~ .php$ {  
…  
}  
}

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 18, 2011, 5:19pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/14 "2011-12-18T17:19:34Z")

</div>

On Sun, Dec 18, 2011 at 10:17 PM, tapir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m sorry it does not work. I didn’t test it properly before.
> 
> here is my settings: [server { root /usr/share/nginx/www; index index.php index.html index.htm; - Pastebin.com](http://pastebin.com/Ln0ccKJw)
> 
> when I go to [mydomain.com](http://mydomain.com) it redirects to wordpress so it works but if I  
> go to [mydomain.com/pma](http://mydomain.com/pma) it says “404 not found”

this line

location /pma {  
root /usr/share/nginx/www/phpmyadmin;

will cause nginx to search for relevant files in  
/usr/share/nginx/www/phpmyadmin/pma. For example

[http://host.com/pma/index.php](http://host.com/pma/index.php) →   
root: /usr/share/nginx/www/phpmyadmin  
$uri: /pma/index.php  
therefore it checks: /usr/share/nginx/www/phpmyadmin/pma/index.php

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 18, 2011, 4:18pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/15 "2011-12-18T16:18:22Z")

</div>

I’m sorry it does not work. I didn’t test it properly before.

here is my settings: [server { root /usr/share/nginx/www; index index.php index.html index.htm; - Pastebin.com](http://pastebin.com/Ln0ccKJw)

when I go to [mydomain.com](http://mydomain.com) it redirects to wordpress so it works but if I  
go to [mydomain.com/pma](http://mydomain.com/pma) it says “404 not found”

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220229#msg-220229)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 18, 2011, 5:35pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/16 "2011-12-18T17:35:39Z")

</div>

okay now I get it → [server { root /usr/share/nginx/www; index index.php index.html index.htm; - Pastebin.com](http://pastebin.com/UMHhR4UM)

one last question: how can I get rid off the same fastcgi lines. can’t I  
just define those globally? do I have to type the same thing for every  
location?

Posted at Nginx Forum:

> **[Re: Alias does not work with php](https://forum.nginx.org/read.php?2,220191,220231#msg-220231)**
>
> Hello, I've set up nginx 1.0.10 with php5-fpm. I've tested the setup and I can confirm that php works. The problem is when I set up an alias under "location /" nginx can't load the php pages. Only static html files work. Any ideas? Thank

---

<div class="post-metadata">

**Author:** ![tapir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c2a13f/32.png) [@tapir](https://www.ruby-forum.com/u/tapir)\
**Post date:** [December 18, 2011, 6:28pm UTC](https://www.ruby-forum.com/t/alias-does-not-work-with-php/214968/17 "2011-12-18T18:28:15Z")

</div>

On 18 Dez 2011 16h35 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> okay now I get it → [server { root /usr/share/nginx/www; index index.php index.html index.htm; - Pastebin.com](http://pastebin.com/UMHhR4UM)
> 
> one last question: how can I get rid off the same fastcgi  
> lines. can’t I just define those globally? do I have to type the  
> same thing for every location?

> **[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

— appa
