Django's 'python manage.py runserver' does not create a local website I can access - python-3.x

I am trying to follow this online class, and I am stuck on the part where I access a local website made by django. The tutorial that I follow is this one by freecodecamp, and I get stuck by the 11min mark where I try to access the output site http://127.0.0.1:8000/ . I am following this tutorial on the browser version of Jupyter Notebook.
Tutorial: https://www.freecodecamp.org/news/create-an-e-commerce-site-with-django-and-vue/
The 'python manage.py runserver' line runs, and I get the following output:
System check identified no issues (0 silenced).
April 16, 2021 - 03:37:04
Django version 3.2, using settings 'djacket_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
When I copy and paste the server address into the browser, I just get the following error saying that I wasn't able to connect to the site:
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1:8000.
The only resource I really found that addressed this issue was the following post, but when I went through my netstat list, there were no IPs listing :8000, so I don't think that I am using up that address already.
Post:
Django manage.py runserver is not working

Sounds like you are using WSL2 and have not yet discovered that the WSL2 VM's IP address is not the same as the Windows IP address. Windows has its own idea of what localhost might be!
TL;DR: Use GWSL to run WSL2 apps on X Windows. This will allow you to run a browser from WSL2 over X Windows, and no worries.

Related

How to set up custom hostnames and ports for servers (eg node.js) running in WSL 2

(I've provided a simple working solution in response)
I recently moved from macOS to WSL 2. I have two node servers running within WSL 2 (Ubuntu distro). Each must be accessible through a custom hostname for development vs production purposes. I've had difficulty accessing the node servers via custom hostnames (ie set in some ../etc/hosts file) especially given WSL 2's dynamic IP that changes per WSL/pc 'boot'. How does one go about setting custom hostnames in WSL 2?
Scenario:
Each node.js app server (again running within WSL 2) must be accessed from the browser with the following urls/custom hostnames:
www.app1.com:3010
www.app2.com:3020
After searching around I have found the following relatively simple process works. I thought I'd share and save some time and headache for those new to WSL 2. Note, although I'm using node as the server stack, this process should more or less be the same for other app/web server stacks.
Note the following SE post is the basis of the solution. It's also worthwhile to examine MSFT's reference on WSL vs WSL 2. Also note, I haven't provided deep rationale on why these steps are required, why we might need custom hostnames, ipv6 options in ../etc/hosts, the meaning of 127.0.0.1, loopback addresses, WSL 2 and distro management, etc. These are subjects beyond the scope of this post.
Simple scenario:
nodeApp1: node application server with custom hostname: 'www.app1.com' on port 3010 (or whatever)
nodeApp2: node application serverwith custom hostname: 'www.app2.com' on port 3020 (or whatever)
Each node.js app server (again running within wsl 2) can be accessed from the browser with the following urls:
www.app1.com:3010
www.app2.com:3020
Two key items:
The correct etc/hosts files to be modified is on the Windows side (not WSL distro) at: C:\Windows\System32\drivers\etc\hosts (yes in Windows folders). This is a 'hot' update so no need for WSL 2 reboot. The content for this scenario is:
127.0.0.1 localhost
127.0.0.1 www.app1.com
127.0.0.1 www.app2.com
255.255.255.255 broadcasthost
::1 localhost www.app1.com www.app2.com
Please add C:\Users\"you"\.wslconfig with the following content (yes in Windows folders):
[wsl2]
localhostForwarding=true
Note: there's a reference to this in WSL 2 Ubuntu distro's /etc/hosts.
Also note, this requires WSL shutdown and reboot. Shutting down your terminal is insufficient. Also total machine boot is not
required. Simply run:
wsl --shutdown (in Powershell) or
wsl.exe --shutdown (within Ubuntu)
Then restart the Windows Terminal app (or any WSL terminal) to access the updated WSL 2 environment. The apps with custom urls/hostnames will now work in the browser permanently and WSL 2's dynamic IP is circumvented.

noVNC Multiple Localhost Servers

Ive got 4 dev VMs for four projects (all VMware Player VMs w/ubuntu 15.04 host) where each is running VNC (ports 5900, 5901, 5902, 5903) respectively.
I downloaded noVNC and saved to /var/www/html (my apache2 server on same host). Based on the ReadMe I then ran on my terminal
./utils/launch.sh --vnc localhost:5900
I received a missing websockify error, so downloaded it and placed it into the util folder. I then ran the same command and it worked! The terminal told me to Navigate to a url and sure enough I could control my VM.
However -- I'm wondering how can I use noVnc to access all 4 VM's? Is there some simple way to extend the port to a range like in iptables or firewalld?
./utils/launch.sh --vnc localhost:5900-5903
Okay, Ill answer for myself here in case it helps someone in the future...
First, create a token file where each line has a nickname, ip address, and port.
I created a file named token.list where each line looks like:
localhostnickname1: localhost:5900
localhostnickname2: localhost:5901
...
Then I use my terminal to go into the websockify folder so I can see the run file. I issue it the command:
./run --web /path/to/noVNC --target-config /path/to/token.list localhost:6080
Finally, I open my web browser and go to :
http://localhost:6080/vnc_auto.html?path=?token=localhostnickname1
Where localhost1 is the nickname of my first server on the first line of token.list
This link was my reference. If you want to serve this outside of localhost -- change the parameter localhost:8060 from localhost to an IP

Selenium testing setup on remote server

I'm trying to install and run Selenium on a remote server to run web tests for a Drupal 7 install. I need to find a way for the browsers installed on the server to output their display onto the computer that is connected to the server, and I need to figure out why Selenium is failing to run. Error messages down below.
My server set up:
centOS 7.1 on Linux running NGinX web server
X11Forwarding available and enabled
Drupal 7 install
Selenium 7.x-3.0 Drupal Module
Selenium Standalone Server 2.46.0
Firefox 38.1.0 installed
Google Chrome stable 43.0.2357.132
Chromedriver 2.16 for 64-bit Linux, set to executable, with symlink to driver in /usr/bin and /usr/local/bin (the local is the only necessary one, the usr/bin is just a fallback)
Note: my solution must have the server hosting the selenium server as the website will be delivered to a client when it's ready for production. It won't work for me to just install the selenium server and browsers on my own machine.
My issues:
When I ssh -X user#server, it doesn't seem to matter what I set the DISPLAY to, firefox can't open the display when I run 'firefox &' [e1]. I've tried export DISPLAY=localhost:0.0, localhost:10.0 and [myIP]:0.0/10.0.
When I run the selenium server and attempt to run the sample test cases on my website, the Firefox instance of the test fails to connect through 127.0.0.1 port 7055 [e2] and the Chrome instance is either unable to find the driver or shuts down unexpectedly [e3]
Errors:
e1 - Error: cannot open display: host:#.# <== (Whatever variant I've attempted)
e2 - Message: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: (blank)
e3 - Message: chrome not reachable
SimpleTest isn't a suitable replacement as the things I'm trying to test require too much custom setup to configure a stock Drupal sandbox properly. Consequently, I'm relying on Selenium's option to test on the original site instead of a sandbox.

Guacamole internal error

So I followed a bunch of tutorials and installed tomcat7 and guacamole (http://guac-dev.org/) on an ubuntu server (virtual machine).
I managed to set everything up...tomcat is running perfectly.But whenever I try to connect via localhost:8080/guacamole/ and log in..I get this error saying:
Internal error... with a countdown that reloads the page
I used guacd -f to and found out that apparently it is "Unable to bind socket to any addresses."
Looking at the manual (http://guac-dev.org/doc/gug/troubleshooting.html) I found this error and followed the instructions on how to fix it and changed the port information.
Didn't work! And I didn't find anything after hours of google searches.
Do you have an idea what I can do?

Web2Py on AWS EC2 Linux

I have an instance running Linux at Amazon AWS EC2 after carefully following the instructions provided by Amazon here: Setting Up to Host a Web App on AWS.
I have set-up the security groups as mentioned in the documentation provided by Amazon.
The default security group has all traffic, all protocols, on all ports open.
In addition to the above security rule, I have setup SSH on port 22 and then, using CyberDuck (a great FTP app), I have uploaded the Web2Py source code into a folder named web2py at AWS.
After successfully FTP the source code into this web2py folder, I have SSH'ed into the AWS machine using the Terminal (on Mac locally) having the my-keys-file.pem on hand:
ssh -i my-keys-file.pem ec2-user#ec2-xx-xx-xx-xx.compute-1.amazonaws.com
(where the xx are the numbers in the Public DNS as they appear on my instance on EC2 page)
Then I have checked whether my AWS instance has python installed and it does have it.
Thus, I have proceeded to install Web2Py.
python2.6 web2py.py
password = pwd
it warns that GUI not available since Tlk library is not installed, but Massimo says here (http://comments.gmane.org/gmane.comp.python.web2py/129181) that it's not critical.
Running the Web2Py ....
If I try:
python web2py.py -a pwd -i 0.0.0.0 -p 80
It says:
there is an error with the Rocket Server with that specific port (used by another process that is not willing to share...)
If I try:
python web2py.py -a pwd
it says nothing (which begs the question: is web2py running ?) and when I try to access the web2py server
http://ec2-xx-xx-xx-xxx.compute-1.amazonaws.com/
or
https://ec2-xx-xx-xx-xxx.compute-1.amazonaws.com/admin
in both cases it says page is not available since it takes too long to access it (nothing about security cause).
If I try:
python web2py.py -a pwd -i 0.0.0.0 -p 8000
again - it says nothing (is web2py running ?)
trying to access the Web2Py server at
http://ec2-xx-xx-xx-xxx.compute-1.amazonaws.com/
or
https://ec2-xx-xx-xx-xxx.compute-1.amazonaws.com/admin
in both cases it says page is not available, same as above.
I have tried to use the IP address instead, but it is immediately translated to the amazon format of ec2-xx-xx-xx-xxx.etc...
I have tried to access web2py by explicitly mentioning the port (8000) in the address - still it doesn't work while giving no reason except page is not available
My questions:
Is there any DETAILED recipe on how to install AND run Web2Py on AWS EC2 ?
Is the web2py server running ? How can I know if it is running ? If it is not - what am I doing incorrectly ?
If the web2py server is running how can I access it ?
Any help would be much appreciated.
Thanks
I have deployed my Web2py to an EC2 instance running Ubuntu, but I guess you can adapt the same approach to your system.
The simplest way to deploy Web2py is following the 'One step production deployment' script introduced in the official Web2py book.
wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
chmod +x setup-web2py-ubuntu.sh
sudo ./setup-web2py-ubuntu.sh
Running this will install and configure everything you need.
When finished, simply type your IP or domain name into a web browser and you will see the default web2py website.

Resources