# nginx + php-fpm + phpmyadmin



## digrouz (Dec 10, 2011)

Hello,

I've installed, nginx and php-fpm from the ports which are working fine togheter.

I've also installed phpmyadmin from the ports but I cannot configure nginx to serve it correctly and I get permission denied (403). here is my /usr/local/etc/nginx/nginx.conf:


```
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location /phpMyAdmin/ {
                alias       /usr/local/www/phpMyAdmin;
                index index.php index.html;
                }
        location /phpmyadmin {
                rewrite  ^/*  /phpMyAdmin last;

        }

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

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

        location ~ \.php$ {
            root /usr/local/www/data;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_intercept_errors on;
            error_page 404 /error/404.php;
            include fastcgi_params;
        }
    }
}
```

Which lines should be added to get it to work?


----------



## gzbk (Dec 25, 2011)

Hello,

I come here and see this post becomes a bit old now but still has no answer; do you still encounter the issue? I think your issue, your issue should come from the following directive:

```
alias       /usr/local/www/phpMyAdmin;
```
alias is not root, if I'm not wrong alias could only serve as a kind of shortcut (actually, an _alias_) to serve file below your root directory.

I'm currently setting up a similar configuration, and actually the easiest way I found was to simply add a symbolic link toward phpMyAdmin directory within the document root directory, thus in you case:
`# ln -s /usr/local/www/phpMyAdmin /usr/local/www/data/phpMyAdmin`
And drop your location /phpMyAdmin/ section which adds unneeded complexity to your configuration (more complexity always mean more trouble than anything else; unless otherwise needed keep it simple and efficient  ).

Regards,
Gzbk.


----------



## digrouz (Dec 27, 2011)

Hello,

I've corrected this issue. Now my nginx is working fine unless the reverse proxy to firefly which return me incomplete pages, I opened a new thread about this. 

But it can be interesting for me to trim my configuration file. Can you explain me which part of my configuration are unneeded or should be done another way and why? (I'm new to nginx and I want to learn)


Here is my /usr/local/etc/nginx/nginx.conf file:

```
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    client_max_body_size 128M;
    keepalive_timeout  65;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 9;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    client_body_buffer_size 128k;
    client_header_buffer_size 64k;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffer_size   16k;
    proxy_buffers       32   16k;
    proxy_busy_buffers_size 64k;


    server {
        listen       80;
        server_name  www.my.domain;

        location /phpMyAdmin {
                root /usr/local/www;
                index index.php;
        }
        
        location ~ ^/phpMyAdmin.+\.php$ {
                root /usr/local/www;
                include fastcgi_params;
        }

        location ~ ^/phpMyAdmin.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
                root /usr/local/www;
                expires max;
                log_not_found off;
        }

        location /phpmyadmin {
                rewrite ^/* /phpMyAdmin last;
        }

        location /mediawiki {
                if (!-e $request_filename) {
                        rewrite ^/mediawiki/([^?]*)(?:\?(.*))? /mediawiki/index.php?title=$1&$2 last;
                }
                root /usr/local/www;
                index index.php;
        }

        location ~ ^/mediawiki.+\.php$ {
                root /usr/local/www;
                include fastcgi_params;
        }

        location ~ ^/mediawiki.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
                root /usr/local/www;
                expires max;
                log_not_found off;
        }


        location /wiki {
                rewrite ^/* /mediawiki last;
        }


        location /wordpress {
                root /usr/local/www;
                try_files $uri $uri/ /wordpress/index.php;
                index index.php;
        }

        location = / {
                rewrite ^/* /wordpress last;
        }


        location ~ ^/wordpress.+\.php$ {
                root /usr/local/www;
                include fastcgi_params;
        }

        location ~ ^/wordpress.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
                root /usr/local/www;
                expires max;
                log_not_found off;
        }


        location /blog {
                rewrite ^/* /wordpress last;
        }

        # BEGIN W3TC Browser Cache
        gzip on;
        gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ ^/wordpress.+\.(css|js|htc)$ {
                expires 31536000s;
                add_header Pragma "public";
                add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
                add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        }
        location ~ ^/wordpress.+\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
                expires 3600s;
                add_header Pragma "public";
                add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
                add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        }
        location ~ ^/wordpress.+\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|
mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xl
a|xls|xlsx|xlt|xlw|zip)$ {
                expires 31536000s;
                add_header Pragma "public";
                add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
                add_header X-Powered-By "W3 Total Cache/0.9.2.4";
        }
        # END W3TC Browser Cache
        # BEGIN W3TC Minify core
        rewrite ^/wordpress/wp-content/w3tc/min/w3tc_rewrite_test$ /wordpress/wp-content/w3tc/min/index.php?w3tc_rewrite_test=1 last;
        rewrite ^/wordpress/wp-content/w3tc/min/(.+\.(css|js))$ /wordpress/wp-content/w3tc/min/index.php?file=$1 last;
        # END W3TC Minify core
        
        location /phpBB3 {
                root /usr/local/www;
                index index.php;
        }

        # Deny access to internal phpbb files.
        location ~ ^/phpBB3/(config\.php|common\.php|includes|cache|files|store|images/avatars/upload){
                root /usr/local/www;
                deny all;
                internal;
        }

        location ~ ^/phpBB3.+\.php$ {
                root /usr/local/www;
                include fastcgi_params;
        }

        location ~ ^/phpBB3.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
                root /usr/local/www;
                expires max;
                log_not_found off;
        }

        location /phpBB {
                rewrite ^/* /phpBB3 last;
        }

        location /transmission {
            proxy_pass      http://127.0.0.1:9091/transmission;
            auth_basic "Transmission authentication";
            auth_basic_user_file /usr/local/etc/nginx/nasusers.htpasswd;
        }

        location /firefly {
            proxy_pass      http://127.0.0.1:3689/;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect   http://127.0.0.1:3689/      /firefly/;
        }

        location / {
            try_files $uri $uri/ /index.php;
            root   /usr/local/www/data;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /usr/local/www/nginx-dist;
        }

        location ~ \.php$ {
            root /usr/local/www/data;
            fastcgi_intercept_errors on;
            error_page 404 /error/404.php;
            include fastcgi_params;
        }

        location ~ /\.ht {
            deny  all;
        }
  }
}
```


----------

