• Resolved decausma

    (@decausma)


    Hi all,

    I am trying to connect to a wordpress blog that is running on a RaspberryPi from the internet. I don’t yet have a domain or a dyndns service. From my admittedly basic understanding of the internet this should be possible regardless. (I understand that as soon as the ISP changes my ip address i have to connect to a new one but this is just a test setup) I have installed a typical lamp stack following one of the many identical tutorials and I can reach the wordpress site from the local network using http:my.local.ip.address

    I have configured port forwarding in the router of port 80 to the static local raspberry IP address.
    (I think portforwarding works because when I call something like this https://my.global.ip.adress/somemadeupsubdir I get a Not found message generated by the apache server on the raspberry. so the router must have forwarded the request.)

    The problem, I think, is that because I do not have a domain, wordpress points to my local ip as WordPress Address (URL) and Site Address (URL) i.e https://192.168.x.x

    so when i connect from the internet (by typing https://myip.igot.from.myisp), the browser arrives at the router, gets forwarded to the raspberry pi and then tries to load that local ip (192.168.x.x), which is of course is not possible because that computer isn’t in the local network.

    I have tried modifying the wp-config.php file in multiple permutations of local and global ip and others and also tried to change etc/hosts file to make an address like site.local point to localhost on the pi and to the global ip on the connecting computer all to no avail. when I connect via the internet it goes looking for that 192.168.x.x address and after a while times out. In the address bar it actually then shows the local ip….

    I tried to google this basically the whole day but haven’t found the solution yet. Could it be a weird non standard function of the router or something?

    Am I trying to do something impossible or intensely stupid? Does WordPress only work with a registered domain? What am I not getting?

    Thanks a lot for helping a newbie along if possible.

    Sven

Viewing 5 replies - 1 through 5 (of 5 total)
  • What you want is certainly possible, however I question the wisdom of hosting a public facing server on your own network.
    Congratulations for getting so far.

    This is a short term solution.
    Say that at the moment that your ISP has assigned ip address “w.x.y.z” to your modem/router.
    In your “hosts” file, details here: https://en.wikipedia.org/wiki/Hosts_(file)
    add two lines like:

    w.x.y.z mydomainname.com
    w.x.y.z www.mydomainname.com

    This works because most web browsers consult the hosts file before using the DNS system to resolve a name to an address, if you are using one of the browsers that don’t do this you are out of luck.

    You will have to edit these lines every time your ISP changes your assigned ip.

    Longer term you will need one of the dynamic dns solutions. Some routers provide support for this.

    • This reply was modified 3 years, 12 months ago by RossMitchell. Reason: clarification
    Thread Starter decausma

    (@decausma)

    Dear Ross,

    thanks a lot for your friendly help and suggestion. I agree that this is a very temporary setup. Basically my dad and sister have decided they need a blog and because I am the computer guy in the family, here we are. I thought I could run a wordpress on a raspberry pi for a while and let them get familiar with it, try a few themes and initial blog posts etc. before having to go for a paying solution with a domain and a hoster (secretly i also think their enthusiasm might wane before that becomes necessary :)) If we decide to bring it out to the world I am sure I’ll be able to port the blog to a hoster.

    Now for the actual fix. I have probably explained it badly and or I don’t understand your solution very well. Firstly, I currently don’t have a domain for the blog. I tried an idea along the lines of changing the hosts file, where in the blogs wp-config.php file I changed the WordPress Address (URL) and Site Address (URL) to https://site.local and then in the hosts file of the connecting (from internet) computer i linked https://site.local to the IP from my isp.

    It didn’t work but I don’t remember why. I think the browser was still redirected to the local 192.168.x.x address which it couldn’t find. Anyways I will try this solution again and see if I just did something wrong. Maybe the browser cached the site or something.

    Is this your suggestion? or are you saying i should change the hosts file of the raspberry? Can you explain why that would help? What can I do to explain my problem better?

    I think you are mostly on the correct track.

    First I think you already have configured the apache2 server on the RaPi to use the virtualhost method where the site is accessed by name rather than some variation of “localhost”, details here: https://httpd.apache.org/docs/current/vhosts/name-based.html
    Say the name you are using is: “decausmafamilyblog.com”, this name need not be registered, it could be the name you will register if required, it does not need to be registered because you are not using the DNS system to resolve it.
    Say that the RaPi has a local network IP address of: 192.168.0.21

    Then
    – in the WordPress configurtion your site address and wordpress address would be:
    https://decausmafamilyblog.com
    – in the file “/etc/hosts” on the rapi you would have this line:
    127.0.0.1 decausmafamilyblog.com
    A browser on the rapi can access your website.
    – On your local LAN each computer can access the website by having this line in its “hosts” file
    192.168.0.21 decausmafamilyblog.com
    – In your modem/router you configure port forwarding to the RaPi
    – Any computer on the wider internet can access the website by having this line in its “hosts” file:
    w.x.y.z decausmafamilyblog.com

    Now when accessing your website from any of the computers mentioned above, you just enter this in the browser’s address bar: https://decausmafamilyblog.com
    The browser is able to access the RaPi.
    As part of the page delivered will be network addresses to access the CSS files and images etc. They will be lines like: <link rel="stylesheet" href="https://decausmafamilyblog.com/wp-content/themes/atheme/style.css" type="text/css" media="all">
    Each hosts file tells the browser how to get to the RaPi using whichever network connection is relevant.

    • This reply was modified 3 years, 11 months ago by RossMitchell.
    Thread Starter decausma

    (@decausma)

    Ross thanks a million!

    your detailed explanation helped me figure this out and it now works.
    So thanks a million.
    You are right also that I was on the right track.

    It turns out the thing i did wrong in the hosts file is, that I wrote:

    w.x.y.z https://decausmafamilyblog.com

    without the https:// it then worked.

    Just out of curiosity, I’m not planning to do this but hey…. if I where to put https://w.x.y.z as the blogs name, could I then connect to it from the internet by just typing its IP addressee? I think i tried that as well but didn’t work, but currently I am unsure why it wouldn’t work…

    Anyways thanks again for your swift and competent help
    It is much appreciated.

    All the best
    sven

    Just out of curiosity, I’m not planning to do this but hey…. if I where to put https://w.x.y.z as the blogs name, could I then connect to it from the internet by just typing its IP addressee?

    Yes, if you set your site address and WordPress address to “https://w.x.y.z&#8221; you could then access the website from the internet using “https://w.x.y.z/&#8221;
    However:
    – It would only work so long as your ISP kept your connection on the same IP
    – It would probably not work on your LAN or on the RaPi, the connection would need to go out to your modem and then come back, maybe the router would understand this wrong sided access, maybe not.

    If you are happy with your result, please mark this thread as resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Connect to WP on RPI from Internet with IP’ is closed to new replies.