py4web server deployment

1,217 views
Skip to first unread message

Auden RovelleQuartz

unread,
Apr 15, 2020, 4:45:58 PM4/15/20
to py4web
Hello team,

If I want to deploy py4web to an actual VPS server (Ubuntu 18.04.3 LTS),

how do I do that?

the following does NOT work:

=========================================================

server
{
    listen 80;
    listen [::]:80;

    server_name example.com;

    root /root/py4web;
    index _dashboard;

    location /
    {
        try_files $uri $uri/ =404;
    }
}


=========================================================

what root do I need to specify? is there a recipie manual anywhere out there for deployment? or is there any script available to do this on a Digital Ocean VPS?

thanks

Massimo

unread,
Apr 21, 2020, 12:31:45 AM4/21/20
to py4web
Hello Auden,

sorry for the late response.
I added this file which contains the setup I have used for nginx.


Let me know if this helps. Feel free to ask questions. I plan to work more on this script and improve it.

Massimo
Message has been deleted

Auden RovelleQuartz

unread,
Apr 27, 2020, 11:17:22 AM4/27/20
to py4web
Thank-you very much Massimo! 

Shortly I'll post, for benefit of the community, a step-by-step recipe that works for me for deploying the py4web framework on a DigitalOcean VPS with an Ubuntu 18.04.3 OS 

Auden RovelleQuartz

unread,
Apr 27, 2020, 2:59:34 PM4/27/20
to py4web
attached is a step-by-step recipe for newbies
py4web_machine_setup.pdf

Daniel Guilhermino

unread,
Apr 27, 2020, 3:11:45 PM4/27/20
to py4web
Many thanks Massino and Auden!

Auden RovelleQuartz

unread,
May 3, 2020, 12:53:23 PM5/3/20
to py4web
here is the latest recipe for a Digital Ocean VPS machine setup (it has been updated to work with latest changes as of 2020-05-03)




On Wednesday, April 15, 2020 at 3:45:58 PM UTC-5, Auden RovelleQuartz wrote:

Ben Lawrence

unread,
May 17, 2020, 3:10:03 PM5/17/20
to py4web
Hi Auden
Thanks for this! I spent a few hours on it, but its not working yet for me as I am trying to implement py4web as a subdomain on a VPS...

Just wondering, have you seen this tool?
It generates nginx configuration files automatically depending on the sites and subdomains you want. I am using this tool at the moment. Hope it works!
Message has been deleted

Auden RovelleQuartz

unread,
May 23, 2020, 2:33:06 AM5/23/20
to py4web
in document:

replace all instances of DOMAIN_NAME with your domain URL (e.g., example.com) if using a domain
replace all instances of DOMAIN_NAME with your subdomain URL (e.g., app.example.com) if using a subdomain

I tested it again on new DigitalOcean VPS setups and works fine for me

By the way, you may want to ensure you are referencing the latest version located here - https://docs.google.com/document/d/13JGsGZtZDS3Q0HseLdWEUB4EtMxGgEBurBbKDkTNSSY - instead of originally posted one.

Feel free to let me know if there are still issues.

rcooke...@gmail.com

unread,
Jun 19, 2020, 10:22:05 AM6/19/20
to py4web
Hi Auden,

Thanks for posting your detailed instructions. I was trying to understand your uwsgi and nginx configuration recently and I think there may be some confusion in how your setup is working.

It looks like you are using uwsgi to start up py4web as a normal bottle http server rather than as a wsgi application. To correctly use nginx + uwsgi your nginx configuration should have a uwsgi_pass configuration rather than  the proxy_pass entry you have. From my recent research I understand that using uwsgi_pass avoids the overhead of processing the http protocol twice (once within nginx and also within bottle) and is therefore more efficient.

I think the correct code for your app.py should be:

import os
from py4web.core import wsgi
password_file
= os.path.abspath(os.path.join(os.path.dirname(__file__),"password.txt"))
application
= wsgi(password_file = password_file, dashboard_mode = "full",apps_folder=os.path.abspath(os.path.dirname(__file__)))

the last line in your instructions actually starts up the bottle server I think, which shouldn't be needed.

In your nginx server configuration you should have the following (where you currently have proxy_pass):

uwsgi_pass unix://home/www-data/py4web/py4web.sock;
include uwsgi_params
;

This would correctly connect to the uwsgi socket you create in your pyweb.ini uwsgi configuration file. As a side note I saw a comment that the correct place to put a socket file is in the /run/ folder on a modern linux system, so /run/uwsgi/py4web.sock might be a sensible path.

I chose to use a port rather than a socket so my configuration files are as follows if anyone wants to do it the same way. This is simpler as it avoids any potential permissions issues on the socket file.

uwsgi config (py4web.ini):

[uwsgi]
socket
= :8081
chdir
= /path/to/py4web/apps
pythonpath
= /path/to/py4web/apps
file
= app.py
plugins
= python
uid
= http
gid
= http

Note: http is the same user account used to run nginx on my system.

This app.py goes into the chdir folder specified above:

import os
from py4web.core import wsgi
password_file
= os.path.abspath(os.path.join(os.path.dirname(__file__),"password.txt"))
application
= wsgi(password_file = password_file, dashboard_mode = "full",      apps_folder=os.path.abspath(os.path.dirname(__file__)))

location entry for specific application in nginx configuration file, sits within a server config block:

  location /app_name {
    uwsgi_pass
127.0.0.1:8081;
    include uwsgi_params
;
 
}

On my system I can now go to http://localhost/app_name to use that specific py4web application. I believe this is now correctly getting nginx to handle all the http protcol and using the more efficient wsgi protocol between nginx and the py4web application.

If you run uwsgi in the command line using the changes suggested above you will not see any reference to bottle starting up and running on port 8080 (or whatever port you specify in your app.py), which proves you are no longer using bottle's http server to handle requests and are in fact using the more efficient wsgi protocol.

I hope this clears up some confusion and is helpful to anyone else trying a similar set up. My system is actually ArchLinux so while I'm happy to share any other steps needed, these may vary from the ubuntu system described in your document.

Richard.

xgp.l...@gmail.com

unread,
Sep 30, 2020, 5:04:08 PM9/30/20
to py4web
Hi,

This works for me.

Question: Is there any rule in nginx to bypass static content? Current not working.

location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {

alias /home/www-data/py4web/apps/$1/static/$2;
expire max;
}


Thanks in advance,

patito feo

unread,
Oct 1, 2020, 10:02:57 AM10/1/20
to py4web
Hi,

Can someone point me in the right direction?
Seems to my python is not processing code.
Python 3.8.2


Cheers,

Val K

unread,
Oct 1, 2020, 11:51:02 AM10/1/20
to py4web
No, it is all ok  with python, just your static files js/css are not loaded - see browser console
четверг, 1 октября 2020 г. в 17:02:57 UTC+3, xgp.l...@gmail.com:

Val K

unread,
Oct 1, 2020, 11:54:50 AM10/1/20
to py4web

curly brackets - Vue templates
четверг, 1 октября 2020 г. в 17:02:57 UTC+3, xgp.l...@gmail.com:
Hi,

Jacinto Parga

unread,
Nov 12, 2020, 1:19:03 PM11/12/20
to py4web
Hello,

I have tried the machine_setup.sh file with these two errors:

machine_setup.sh: 192: popd: not found
machine_setup.sh: 244: Syntax error: end of file unexpected (expecting "then")

xgp.l...@gmail.com

unread,
Nov 16, 2021, 8:35:03 AM11/16/21
to py4web
Hi all,

 pip3 install ombott
ERROR: Could not find a version that satisfies the requirement ombott (from versions: none)
ERROR: No matching distribution found for ombott


Any ideas?

Nico Zanferrari

unread,
Nov 16, 2021, 1:03:22 PM11/16/21
to Jacinto Parga, py4web
@Jacinto Parga 

I've updated the machine_setup.sh one month ago for Ubuntu 20.04.3 LTS, and it seem that you're using the original version. Could you try with the new one (https://github.com/web2py/py4web/blob/master/deployment_tools/ubuntu/machine-setup.sh)?

Nico

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/cde24323-e05a-46fd-a1f7-c048f830c0d3n%40googlegroups.com.

Jacinto Parga

unread,
Nov 21, 2021, 5:45:18 AM11/21/21
to py4web
Hi,  thanks Nico.

Yes. These have been the last lines of the test.

Common Name (e.g. server FQDN or YOUR name) []:JACINTO
Email Address []:jpa...@gmail.com
Enter the password for py4web Dashboard:
./machine-setup.sh: línea 313: py4web: orden no encontrada
Restarting nginx (via systemctl): nginx.service.
jacinto@HP-Pavilion:~/PROGRAMACION/PY4WEBSERVER$ py4web version
py4web: orden no encontrada

It seems that py4web has not been properly installed or that it should have to be installed previously

xgp.l...@gmail.com

unread,
Nov 21, 2021, 10:40:37 AM11/21/21
to py4web
Hi, all.

This is already working. Suddenly pip3 installed the package.


Cheers,

Andreas Schneider

unread,
Jan 10, 2022, 8:58:30 AM1/10/22
to py4web
Hello, 

has someone get it work with this script?
I get the same error.

Thanks and regards,
Andreas

Nico Zanferrari

unread,
Jan 10, 2022, 9:29:35 AM1/10/22
to Andreas Schneider, py4web
Hello Andreas,

what kind of error exactly? Is py4web correctly installed (according to pip)?

Nico

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.

Massimo

unread,
Jan 13, 2022, 10:32:36 PM1/13/22
to py4web
does this work?

mkdir workfolder
cd workfolder
python3.8 -m venv venv
. venv/bin/activate
pip install -U py4web
py4web --help

Andreas Schneider

unread,
Jan 14, 2022, 12:09:06 AM1/14/22
to Massimo, py4web
Hello Massimo,

thanks for your reply. 
I have decide to User Microsoft Azure for hosting. I will try to get it work in Azure using the App Services. I hope i can do it successfuly. 


Regards
Andreas

You received this message because you are subscribed to a topic in the Google Groups "py4web" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/py4web/hp6mr87WQWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/0c934a8a-1887-4a6f-8e5b-96f40b05bb53n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages