Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom SERVER_ADDR overwritten by a default value #2

Closed
dmytro-samoylenko opened this issue Oct 8, 2022 · 2 comments
Closed

Custom SERVER_ADDR overwritten by a default value #2

dmytro-samoylenko opened this issue Oct 8, 2022 · 2 comments

Comments

@dmytro-samoylenko
Copy link

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_ADDR IP_OF_YOUR_SERVER; # This needs to be your public IP of the server, used to verify WHMCS license
fastcgi_param HTTPS on;
# fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}

  1. include fastcgi_params should be moved to the top of location block because custom SERVER_ADDR will be overwritten by a default value and license check fail.

  2. # This needs to be your public IP of the server -- is a misleading comment. The IP might be anything, e.g. 127.0.0.1. The only requirement for it is to be consistent across all instances, otherwise license check will fail.

Here is a small script which may help to debug a license issues (save as test.php to $document_root and access from a web browser):

<?php

$installIp = "";
if (isset($_SERVER["SERVER_ADDR"])) {
    $installIp = $_SERVER["SERVER_ADDR"];
} else {
    if (isset($_SERVER["LOCAL_ADDR"])) {
        $installIp = $_SERVER["LOCAL_ADDR"];
    } else {
        if (function_exists("gethostname") && function_exists("gethostbyname")) {
            $installIp = gethostbyname(gethostname());
        }
    }
}
$data = [
    "WHMCS_LICENSE_DOMAIN" => isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : "",
    "WHMCS_LICENSE_IP" => $installIp,
    "WHMCS_LICENSE_DIR" => realpath(dirname(__FILE__)),
];

echo(json_encode($data, JSON_PRETTY_PRINT));
#echo(json_encode($_SERVER, JSON_PRETTY_PRINT));
@EdyTheCow
Copy link
Owner

Thank you! I actually just noticed WHMCS license page sees my own installation under a local IP. However, somehow license check is valid, which is why I never even looked into it till now.

@alebeta90
Copy link

I can confirm by moving the include to the top of the location solve the issue

    location ~ \.php$ {
        include fastcgi_params; # Include MOVED to the top of location
        try_files $uri /index.php =404;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SERVER_ADDR x.x.x.x; # This needs to be your public IP of the server, used to verify WHMCS license
        fastcgi_param HTTPS on;

        # fixes timeouts
        fastcgi_read_timeout 600;
    }

Now WHMCS receive the IP defined in SERVER_ADDR

EdyTheCow added a commit that referenced this issue Apr 11, 2023
Move include to top of location block, improve comments #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants