Anvil-app-server cheatsheet

I put the following together for an IT department, to document steps used to install and interact with production apps running on anvil-app-server:

https://pythonanvil.com/anvil_app_server_install_instructions.txt

Perhaps it’s useful as a starting point for anyone interested in deploying apps with the open source server. If any interest is expressed here, I’ll write some tutorials and perform a few video walk-throughs which demonstrate all the details of setting up production apps to run on the open source platform (in-house, or on cheap unmanaged VPS hosting accounts, in managed IT environments, etc.).

13 Likes

Hi - a typo?
you have (in a few places)

python3 -m venv anvildir
cd anvildir
source /bin/activate

where it should be (change the /bin → bin)

python3 -m venv anvildir
cd anvildir
source bin/activate

1 Like

Thank you, good eye :slight_smile: The text is updated

(hopefully, anyone installing anvil-app-server knows enough Linux and Python, that environment configuration is understood).

2 Likes

I made a video run-through demonstrating how to install anvil-app-server on A2 unmanaged VPS, using SSH and tmux. I suggest watching at 1.5x speed:

This video runs through how to install an app dependency (in this case anvil extras):

This video runs through how to interact with the embedded Postgres database that ships with anvil-app-server, using SQL in psql-anvil-app-server:

This video walks through installing and running an Anvil app on Windows 11:

This video walks through using a separate install of postgres (as opposed to the embedded version that comes packaged with anvil-app-server), on a very old machine (originally Windows XP, manufactured 15-20 years ago, now with Q4OS Linux):

Explanations of all the anvil-app-server command line options, psql guidelines, etc. are in the official anvil-app-server Git repo:

Please keep in mind that anvil.works does not provide any support for the open source anvil-app-server, but they do offer a commercial version which is supported.

3 Likes

EDIT: I updated the video links above to much better versions.

EDIT 2: Added a walk-through video of installing and running an Anvil app on Windows.

EDIT 3: Added walk-through video of running anvil-app-server on a 2 decade old PC, without embedded postgres.

2 Likes

I remembered seeing this and now need it! Awesome work!

1 Like

There’s more to add, especially for systems which have trouble using the embedded Postgres database, and for example, for situations in which the Java server can’t be downloaded properly. I’ve been swamped lately, so haven’t been as active on the forum. At some point want to share literally hundreds of application examples containing interesting solutions to what I think are likely common problems - just need to take a vacation to collect them all…

2 Likes

A vacation of any kind sounds awesome right now! Anything you do eventually share will be super valuable, as the app-server is such a powerful reason to use Anvil and it’ll act as a draw.

Thank you thank you thank you

Every time I attempt this I struggle, figure it out, and then forget what I did a few months later.

2 Likes

Why this error please
anvil.server.RuntimeUnavailableError: Server resources not available for ‘python3-full’. If this error persists for more than a few minutes, please contact support@anvil.works.

thank you for your help.

This thread is about the open source anvil-app-server. Are you experiencing that error with an application running on the hosted anvil.works platform, or with a self-hosted app running on your own server with anvil-app-server? (If it’s related to the hosted service, that question should be posted in a separate thread on the forum (be sure to search existing topics on the forum, since there are likely dozens of threads related to that sort of error already)).

Hi @nickantonaccio
I do not have much experience with setting this on Windows and I was not able to find anything related in the github repo.
I am facing this issue:


Does it mean it will not work on Windows Server 2019 Operating System?
Or there is some workaround available?

You can ignore the question. Stupid me as I did not search Anvil forum :slight_smile:
What worked for me was found in this thread:

There was an example of that in one of the videos above. You can install your own postgres server, and connect Anvil to it.

1 Like

@nickantonaccio thanks for the tutorials! It is very helpful! And I love a2hosting. I am struggling to deploy my app using https. I think you mentioned in your first vid that you would show how to do it. Can you please point me to the resource?

I’ll make a video detailing exactly how I set it up, as soon as I return from the holiday rounds :slight_smile: In the meantime, if you have a single Anvil application, and an open port 443, in a Linux environment, the easiest way is to let Anvil’s embedded Traefik binary do it all for you automatically. Just run your application with an https:// origin.

If you want to run on a port other than 443, or if you have multiple applications that you want to terminate at different ports, you can apt install caddy then:

sudo nano /etc/caddy/Caddyfile

Edit that file with settings such as:

{
    email name@yourdomain.com
    debug
    auto_https disable_redirects
}

# app 1
https://yourdomain.com:1111 {
    reverse_proxy 127.0.0.1:2222
}

# app 2
https://yourdomain.com:3333 {
    reverse_proxy 127.0.0.1:4444
}

# continue with more applications...

Run Caddy with:

sudo systemctl restart caddy

On the command line where you run your Anvil application, set the origin URL to the https port which you’ve defined in the caddy file. Set the --port value to the http port you’ve defined in the caddy file. For example, this caddy file setting:

https://yourdomain.com:1111 {
    reverse_proxy 127.0.0.1:2222
}

is valid for an Anvil app started with the following command line:

anvil-app-server --app Your_App_Name --origin https://yourdomain.com:1111 --auto-migrate --dep-id C6ZZPAPN4YYF5NVJ=anvil_extras_main --secret my_key=abc123 --smtp-host mail.yourdomain.com --smtp-port 465 --smtp-encryption ssl --smtp-username name@yourdomain.com --smtp-password abc123 --port 2222 --disable-tls

1 Like

@nickantonaccio I appreciate your response! Am also looking forward to the video. I was actually getting an error about Traefik; perhaps, the port was not open, will give it another shot. Happy Holidays! :christmas_tree:

Hi @nickantonaccio, thanks for your guide, I followed it and installed my app.
However, whenever my app tries to call server side code, I have this error:

AppOfflineError: Connection to server failed (error)

Looking with the browser inspector I see it tries to call:

http://XX.XX.XX.XX:8080/_/check-app-online?t=1737049473287

(XX.XX.XX.XX is the public IP of the host)
This request resolves in a OK 200 response, but with an empty response.
The APP is using the Users and Data Tables services only, and some server-side code.

Do you know what the cause of this error could be?
Should the host have some other ports open to make the anvil.server.call(....) calls work?

Thanks and BR