The web address like localhost and 127.0.0.1 only serve locally not serve over public Ip

Profamx 1 Reputation point
2022-04-22T11:41:25.657+00:00

Hi ,

Welcome Everyone

Here we take a example , in which we try to serve a simple program of any kind from local address to public ip..
But i faces some issue..

Ok Let start

os - ubuntu / any

Suppose we use php to serve a php file ...
Then , i assured you know this comman things to server by php.

php -S localhost:8080
php -S 127.0.0.1:8080

But But their is a problem

What? Do you want to listen

When you use (localhost/127.0.0.1) as address then php or any other app will start serving but the serve is limited to localhost ip it does not show over public ip...

But when we uses

php -S 0.0.0.0:8080
php -S 10.0.0.4:8080

Then it will serve not only localhost also visible through public it ..

Can you please fix it and what the reason

Community Center Not monitored
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Takahito Iwasa 4,851 Reputation points MVP Volunteer Moderator
    2022-04-22T21:34:11.923+00:00

    Hi, @Profamx

    It's PHP's Built-in web server feature.

    Please check the following URL.
    https://www.php.net/manual/en/features.commandline.webserver.php

    If 0.0.0.0 is specified, it can be accessed from any remote server. This is a PHP built-in web server specification, not an Azure issue.

    The PHP documentation also notes the following:
    You should not use it on public networks.

    Warning
    The built-in Web Server should not be used on a public network.

    From here, I will talk about what you can do with Azure.

    If you want to keep your Azure virtual network private, don't give it a public IP address.

    https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/public-ip-addresses

    If you publish your PHP application on a public network, we recommend hosting it with Apache or Nginx and controlling the communication with a virtual network or firewall.
    https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-lamp-stack

    You can also host your PHP application on Azure App Service.
    https://learn.microsoft.com/en-us/azure/app-service/


  2. Profamx 1 Reputation point
    2022-04-24T06:58:04.563+00:00

    You give me a Good reason for this i Appreciate it

    But your reason in only valid over php...
    In php , they say to use 0.0.0.0 for public and 127.0.0.1 for local
    Ya i know that it true

    But their is something

    I said that when any program ( like php etc) run over localhost address then it is not visible over public ip..

    So how we can visible this over public ip???
    if i need ..

    Lets take another example with python
    May you know about ? You know

    Create simple app.py

    we user import flash and simple hello world , and create something

    Mean when i visited over this file on hosted address it return me " Hello world"

    Then we deploy this application with simple command

    flash run -p 8080

    It will run this program over locahost:8080

    We test it works on not > curl localhost:8080
    so it return > hello world and some errors ( debug enable )

    so we try to access same program over our public ip

    visited or curl over public ip and the port
    It will not serve their ...

    So what how i serve over their ,
    Because in PhP you easily say about php function not a matter of azure
    Ok
    Then what is this !

    Basically i know the answer and i also know how to serve over public ip
    But i want to know from you???

    Please reply it ??

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.