LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2021, 02:14 AM   #1
sirlinux
LQ Newbie
 
Registered: Aug 2020
Distribution: debian, ubuntu
Posts: 19

Rep: Reputation: Disabled
[Python] Setup environment to run python webapps


I created with Vmware workstation an Ubuntu 20.04 server VM in which I also installed LAMP in order to run my little php/mysql projects. It works fine.
I started learning python as well, and I'd like now to develop little webapps which run in my browser (I flask too, I guess), the way I do with my php files.
Unfortunately, I haven't yet understood how to create a python server/environment to run my projects in my browser. I read plenty of articles about that, but each and every of them said somethign different, and, as a result, I am more confused than I was.
Could you help me figure it out please?
Thanks
 
Old 02-16-2021, 02:21 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
I guess you are speaking about python venv (but not really sure).
 
Old 02-16-2021, 02:38 AM   #3
sirlinux
LQ Newbie
 
Registered: Aug 2020
Distribution: debian, ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I guess you are speaking about python venv (but not really sure).
I'm not sure either
 
Old 02-16-2021, 06:53 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,627

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556

I don't think you're asking about venv stuff - which I believe is for isolating dependencies of different applications (so still something you might want, but it wont solve the server aspect).


When I tried to figure this out, I first resorted to simply using Jetty FastCGI to connect to a Python script which manually printed HTTP responses - basically "import cgi,cgitb,os,sys" then parsing "os.getenv('PATH_INFO',''") and "os.getenv('QUERY_STRING','')" to figure out what to do, and finally sending the HTTP response with "sys.stdout.write"

It's not a great approach - in particular it means re-starting the application on every request - but it did allow me to just get started on the important code.

Later I came back and wrote a basic WSGI server for the app using wsgiref.simple_server.make_server, which runs the server+application continually until stopped.

I still need to return to that project at some point and figure out if that's an appropriate solution - I remember vague warnings about it only being for "evaluation purposes" or some similar nonsense, so need to confirm whether it's enough to put Jetty/Apache/nginx/etc in front of it, or whether I need yet another approach.

 
Old 02-16-2021, 08:45 AM   #5
sirlinux
LQ Newbie
 
Registered: Aug 2020
Distribution: debian, ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
I don't think you're asking about venv stuff - which I believe is for isolating dependencies of different applications (so still something you might want, but it wont solve the server aspect).


When I tried to figure this out, I first resorted to simply using Jetty FastCGI to connect to a Python script which manually printed HTTP responses - basically "import cgi,cgitb,os,sys" then parsing "os.getenv('PATH_INFO',''") and "os.getenv('QUERY_STRING','')" to figure out what to do, and finally sending the HTTP response with "sys.stdout.write"

It's not a great approach - in particular it means re-starting the application on every request - but it did allow me to just get started on the important code.

Later I came back and wrote a basic WSGI server for the app using wsgiref.simple_server.make_server, which runs the server+application continually until stopped.

I still need to return to that project at some point and figure out if that's an appropriate solution - I remember vague warnings about it only being for "evaluation purposes" or some similar nonsense, so need to confirm whether it's enough to put Jetty/Apache/nginx/etc in front of it, or whether I need yet another approach.

I found this:

https://projects.raspberrypi.org/en/...r-with-flask/1

I did what it says step by step and it works now, I mean, I have that "Hello world" message in my browser.
However, I am trying to figure out if there is a way to get it better than that since I got:

Code:
john@ubuntu-02:~/webapp$ python3 app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
when I ran python3 app.py in my linux shell.
Futhermore, am I supposed to run the same command everytime I reboot the server?

Your thoughts, please.

Thanks

Last edited by sirlinux; 02-16-2021 at 08:48 AM.
 
Old 02-16-2021, 09:24 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
You’re using Apache?

https://flask.palletsprojects.com/en...ying/mod_wsgi/

https://www.google.com/amp/s/www.dig...ubuntu-vps.amp
 
Old 02-16-2021, 09:38 AM   #7
sirlinux
LQ Newbie
 
Registered: Aug 2020
Distribution: debian, ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
Yes, of course. As I said, I installed LAMP on that linux machine, so I already have Apache, PHP, and mysql running on it.



Interesting links, I'll read them through.

Thank you

Last edited by sirlinux; 02-16-2021 at 09:56 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
an idea for a webapp in python preets100 Linux - Newbie 1 07-02-2011 11:18 AM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
webapp does not start automatically in tomcat craftereric Linux - Software 1 11-05-2008 03:31 AM
Webapp that emulates FTP? cabe Linux - Software 16 12-13-2006 09:48 PM
Shared Document Webapp? humbletech99 Linux - Networking 1 12-13-2006 09:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration