# Php not working from aliased subdir

**URL:** <https://www.ruby-forum.com/t/php-not-working-from-aliased-subdir/243863>\
**Category:** NGINX\
**Created:** [January 19, 2016, 10:22am UTC](https://www.ruby-forum.com/t/php-not-working-from-aliased-subdir/243863 "2016-01-19T10:22:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [January 19, 2016, 10:22am UTC](https://www.ruby-forum.com/t/php-not-working-from-aliased-subdir/243863/1 "2016-01-19T10:22:05Z")

</div>

Hello,

I have been adding (to my nginx config) directories outside of the  
default “root” tree like:

```
 location ~ /newlocation(.*) {
     alias /var/websites/externaldir$1;
 }

```

This works OK.

however, I find that the above config does not process php files. I  
tried adding (before the above):

```
 location ~ /newlocation/(.*)\.php$ {

     alias /var/websites/externaldir$1.php;

     fastcgi_cache off;

     try_files $uri =404;
     include /etc/nginx/fastcgi_params;
     fastcgi_param PATH_INFO $fastcgi_script_name;
     fastcgi_intercept_errors on;

     fastcgi_buffer_size 128k;
     fastcgi_buffers 256 16k;
     fastcgi_busy_buffers_size 256k;

     fastcgi_temp_file_write_size 256k;
     fastcgi_read_timeout 240;

     fastcgi_pass unix:/tmp/php-fpm.sock;

     fastcgi_index index.php;

 }

```

This config however always leads to “404 Not Found” errors for php  
files.

What am I doing wrong?

Please correct me.

Thanks!  
Nick

---

<div class="post-metadata">

**Author:** ![Nikolaos\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecc23a/32.png) [@Nikolaos\_M](https://www.ruby-forum.com/u/Nikolaos_M)\
**Post date:** [January 19, 2016, 9:59pm UTC](https://www.ruby-forum.com/t/php-not-working-from-aliased-subdir/243863/2 "2016-01-19T21:59:00Z")

</div>

On Tue, Jan 19, 2016 at 11:21:46AM +0200, Nikolaos M. wrote:

Hi there,

> ```
> location ~ /newlocation/(.*)\.php$ {
> 
> alias /var/websites/externaldir$1.php;
> 
> fastcgi_cache off;
> 
> try_files $uri =404;
> include /etc/nginx/fastcgi_params;
> 
> ```

> This config however always leads to “404 Not Found” errors for php files.
> 
> What am I doing wrong?

add “debug\_connection 127.0.0.12;” to your events{} section, then do  
“curl -v [http://127.0.0.12/newlocation/X.php](http://127.0.0.12/newlocation/X.php)”, and then read the error  
log that was generated.

You should see, among other lines, something like

http request line: “GET /newlocation/X.php HTTP/1.1”  
http uri: “/newlocation/X.php”  
test location: ~ “/newlocation/(._).php$"  
using configuration "/newlocation/(._).php$”  
try files phase: 11  
trying to use file: “/newlocation/X.php”  
“/var/websites/externaldirX.php/newlocation/X.php”  
http special response: 404, “/newlocation/X.php?”

Two things there: “alias” and “try\_files” is not a good combination;  
and your config loses the “/” that should be between “externaldir” and  
“X.php”.

If you temporarily remove the try\_files line that is blocking you, and  
repeat the “curl” command, then you will see what is sent to the fastcgi  
server. Usually, the most interesting parameter is SCRIPT\_FILENAME.

What value do you see for that? Is it exactly the filename that you want  
your fastcgi server to process?

If not, what file do you want your fastcgi server to process?

After that, you can decide whether you want to use a try\_files directive  
in this location{} block, and if so, what exactly you want there.

(I tested this using a nginx/1.9.1, because that’s what I had  
handy. Different versions may show different output.)

Good luck with it,

## f

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