npm live-server not running on mobile - npm-live-server

Everything runs correctly when I start the npm live-server from my laptop, but when I type the address on the iPhone's browser 127.0.0.1:8080 it says the address can't be found.
I remember before that when running the live server from the terminal you can also see the web page from mobile too.
I'm not using file:// to run the page.
Appreciate the help.
Thanks

according to the documentation page, I can see that it seems to work like ng serve, and you need to add the parameter --host 0.0.0.0 to make the server bind to all IPs and not just 127.0.0.1 (which is not reachable from your phone)

Related

Localhost refused to connect on WSL2 when accessed via https://localhost:8000/ but works when using internal WSL IP adress

What I'm Trying to Achieve
To access localhost from my local machine during the development of a Symfony web app.
My Environment
WSL2 running on Windows 10
Linux, Apache2, MySQL, PHP-7.4 stack (with Xdebug3 intalled)
Debian 10
Symfony 5.4 (although not sure on if relevant to this problem)
Steps I've Taken
Set up WSL2 according to this Microsoft WSL2 tutorial
Set up LAMP stack according to this Digital Ocean tutorial
Set up Symfony according to this Symfony tutorial
Run the following bash script on startup to start my services and set the host to the virtual WSL IP in my xdebug.ini file
#!/bin/sh
REMOTEIP=`cat /etc/resolv.conf | grep nameserver | sed 's/nameserver\s//'`
sed -i -E "s/client_host=[0-9\.]+/client_host=$REMOTEIP/g" /etc/php/7.4/mods-available/xdebug.ini
service php7.4-fpm start
service apache2 start
service mysql start
Run my Symfony project on the development server using symfony serve -d (Symfony then tells me "The Web server is using PHP FPM 7.4.23 https://127.0.0.1:8000")
Go to https://localhost:8000/ in Chrome where the app is running
What I Expect to Happen
My Symfony web app to be running on https://localhost:8000/ when I visit the URL in my Chrome browser
What Actually Happens
I get "This site can't be reached localhost refused to connect." in the Chrome browser
What I've Tried
This used to happen less frequently and I would give my laptop a restart, repeat the process above, and I could connect via https://localhost:8000/. However, it refuses to connect more regularly now (like 8/10 times I start up for the day)
Connecting to https://127.0.0.1:8000 yields the same result.
Connecting to the site using the internal WSL IP address, found using hostname -I and replacing localhost with this IP (still on port 8000). This is an adequate workaround to use my app, however I am unable to interact with my database via MySQL Workbench without having to set up a new connection, therefore a fix where I can use localhost would be very helpful!
(Based off comments) Only ran symfony serve -d without starting apache and PHP services separately - still sometimes allows connections to localhost but sometimes doesn't work.
Conclusion
The behaviour is odd as it works sometimes but other times it doesn't when the exact same steps are carried out. I am unsure where else to look for answers and I can't seem to find anything online with this same problem. Please let me know if any config files, etc would be helpful. Thank you so much for your help! :)
When it's working normally, as you are clearly aware, the "localhost forwarding" feature of WSL2 means that you can access services running inside WSL2 using the "localhost" address of the Windows host.
Sometimes, however, that feature breaks down. This is known to happen when you either:
Hibernate
Have the Windows "Fast Startup" feature enabled (and it is the default). Fast Startup is a pseudo-hibernation which triggers the same problem.
Typically the best solution is to disable Hibernation and Fast Startup. However, if you do need these features, you can reset the WSL localhost feature by:
Exiting any WSL instances
Issuing wsl --shutdown
Restarting your instance
It's my experience that localhost forwarding will work after that. However, if it doesn't, thanks to #lwohlhart in the comments for mentioning that another thing to try is disabling IPv6 on WSL2, since (I believe) there's a possibility that the application is listening on IPv6 while the Windows->WSL2 connection localhost connection is being attempted on IPv6.
You can disable IPv6 on WSL2 per this Github comment by creating or editing .wslconfig in your Windows user profile directory with the following:
[wsl2]
kernelCommandLine=ipv6.disable=1
A wsl --shutdown and restart will be necessary to complete the changes.
If you find that this works, it may be possible to solve the issue by making sure to either use the IPv4 (127.0.0.1) or IPv6 (::1) address specifically in place of localhost on the Windows side, or by configuring the service to listen on both addresses.
Try to run command netstat -nltp. It shows active addresses and ports. Your nginx process should be run at 0.0.0.0:8000. 0.0.0.0 means the nginx process is available from anywhere.
If your nginx process is ran by any specific ip address, you should access it by that ip address, e.g http://192.168.4.2:8000.

Is there a way to acces my local project from another pc

I added my laravel project to docker as it appears in the first picture.
enter image description here
And I push my images to a repository in the docker hub as it appears in the second picture.
enter image description here
Now I want to run my application on another pc, I trying to pull my images but I don't know how to run the project in the browser.
Another question is there a way to test if the project will work on another pc from my pc something like a virtual machine.
If you want your project to be accessed globally then the easiest way is to use NGROK. It requires node>=10.19.0
Two simple steps to share your locally running app with others:
//Installing ngrok globally
npm install ngrok -g
//Expose a locally running application at port 8080 to the internet.
ngrok http 8000
If you want to share locally then both the PC's should be connected to the same network and you can just type the http://{IP address of PC running APP}:{PORT} to access the application.
To check the IP address use ifconfig command. Let's say it gives you 192.168.100.1, and the app is running on port 8000. To access the app on the other PC, you have to enter the following URL in the browser:
http://192.168.100.1:8000

docker: what is the similar url in docker as compared to XAMMP/MAMP

I am using docker for the codeigniter project development. Initially, when I used MAMP or XAMMP, the login page was localhost/xyz/admin/login as the server used to run on localhost (php server). But, the docker server is running on localhost:8000 and I am trying to open localhost:8000/xyz/admin/login but it shows an error that page you requested not found. Does someone know the answer to this problem? I have also tried localhost:8000/myapp_1/xyz/admin/login , localhost:8000/myapp_1/admin/login etc. but nothing seems to work.
Thanks in advance!

Xampp Is Messing Up?

First Apache wouldn't work with me so I had to change the port number which fixed everything so that is good, but then I went online and found this
"Start Apache and MySQL and go to localhost in your browser (on the same machine as your server). If this is your first time browsing the local site, you should now see a webpage with the XAMPP logo and a choice of languages. Click on your preferred language."
When I type in localhost:8080 (Apache port), it comes up this I have no clue how to make it so I'm taken to the XAMPP Logo where the languages are. -.- Help please.
Try this :
Just create a sample html page in htdocs of your apache folder and try to access it in browser.
If you name it is as index.html, you just have to write localhost in the browser or localhost/.html
This will make sure your server is working.
And in cmd prompt run mysql -u -p status to check the status of mysql that will check whether mysql is working or not.

Way to open localhost with different URL

I have tried http://localhost/projectname and http://127.0.0.1/project_name to open my Project in LocalHost
but
I want to open this with some other URL so user can not able to know that I have opened with localhost.
Edited:
My Users currently accessing my project with localhost but now i
want to use some static string to open as url. I mean if currently
users accessing project with localhost/proj but i want to do like
staticString/proj Is it possible?
Is there any way to open project with different URL rather than localhost?
Thanks.
You have to Configure first Virtual Host in your XAMPP or any Web server.
After you can use that name instead of Localhost or IP Address.
Follow this link to configure Virtual Host.
http://sawmac.com/xampp/virtualhosts/
and this also
http://foundationphp.com/tutorials/apache_vhosts.php
You can make use of virtual host configuration in your web server.
Edit your hosts file to include 127.0.0.1 thisismyhost.com
Then can should be able to access your project using thisismyhost.com/my_project
I follow solution of accepted answer but I found one tricky Magic solution for that which i can use without any configuration:
You can use yourString.google It will directly open you localhost.
For Example: Open this link in your browser: pratik.google/
if you have installed xampp it will open your localhost
Really amazing magical trick.
I don't know how it works, May be this is functionality of browsers.
I believe what you are looking for is local tunnel
Use node and npm to install it globally using npm install -g localtunnel
then give the port you want to export lt --port <port>
you will get a link you can share anywhere and anyone can access your localhost site. there are multiple ways and options to it. you can view about it - here!
if you change the port you will see the result like this
> http://localhost:5906/projectname/abc.aspx
right click on the project click on properties and there will be one option web in that change the specific port
hope this may help

Resources