phpemailnginxwebmailroundcube

"Unable to open primary script: /usr/share/webapps/roundcubemail/webmail/index.php (No such file or directory)"


I have configured roundcubemail according to this archlinux wiki using nginx.

When I visit the /webmail using: https://mail.hackeac.com/webmail page (In the browser) renders: "No input file specified" and when I check on the logs at /var/log/nginx/roundcubemail_error.log I see

2017/12/11 13:44:10 [error] 5827#5827: *1 "/usr/share/webapps/roundcubemailwebmail/index.html" is not found (2: No such file or directory), client: 169.255.184.153, server: mail.hackeac.com, request: "GET /webmail/ HTTP/2.0", host: "mail.hackeac.com"
2017/12/11 13:44:19 [error] 5827#5827: *1 "/usr/share/webapps/roundcubemailwebmail/index.html" is not found (2: No such file or directory), client: 169.255.184.153, server: mail.hackeac.com, request: "GET /webmail/ HTTP/2.0", host: "mail.hackeac.com"

Nginx config:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name mail.hackeac.com;

    ssl_certificate /etc/letsencrypt/live/hackeac.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/hackeac.com/privkey.pem;

    location /webmail {
        alias /usr/share/webapps/roundcubemail;
        access_log /var/log/nginx/roundcube_access.log;
        error_log /var/log/nginx/roundcube_error.log;
# Favicon
        location ~ ^/webmail/favicon.ico$ {
            root /usr/share/webapps/roundcubemail/skins/classic/images;
            log_not_found off;
            access_log off;
            expires max;
        }
# Robots file
        location ~ ^/webmail/robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
# Deny Protected directories
        location ~ ^/webmail/(config|temp|logs)/ {
            deny all;
        }
        location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
            deny all;
        }
        location ~ ^/webmail/(bin|SQL)/ {
            deny all;
        }
# Hide .md files
        location ~ ^/webmail/(.+\.md)$ {
            deny all;
        }
# Hide all dot files
        location ~ ^/webmail/\. {
            deny all;
            access_log off;
            log_not_found off;
        }
#Roundcube fastcgi config
        location ~ /webmail(/.*\.php)$ {
            include fastcgi.conf;
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_split_path_info ^/webmail/(.+\.php)(/.*)$;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/webapps/roundcubemail$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PHP_VALUE open_basedir="/tmp/:/var/cache/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail";
        }
    }
}

Or (with better indentation) Here.

Please help.


Solution

  • You were using fastcgi_param SCRIPT_FILENAME /usr/share/webapps/roundcubemail$fastcgi_script_name; to compute the path to the script file. It is simpler to use $request_filename which computes the correct value with both root and alias directives.

    For example:

    location /webmail {
        alias /usr/share/webapps/roundcubemail;
        ...
        location ~ \.php$ {
            include fastcgi.conf;
            ...
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }
    

    See this document for details.