I have apache running on a Raspberry Pi. My website is using running Python scripts. How do I make, say, start.py, as the default document for the site? In other words, if the host name for the Raspberry Pi is pi, I want my users to just use http://pi and start.py will execute.
I would use apache's mod_fastcgi module, mapping a virtual host in apache to a script folder containing python scripts. Note however, this is far from production quality, or secure! However, if your Pi is on a trusted intranet network such as a home, it should be fine.
Here's one blog which spells it out, step by step: http://raspberryserver.blogspot.com/. The final step in the tutorial is to install apc, which you can skip. It's for PHP.
Essentially, you'll be able to drop python files into the /var/www/fastcgi folder, and profit.
Related
I have written a Python Dash Application and it works completely fine on my local computer. Now, I want to be able to deploy this application on a server within the corporate network. I do NOT want to deploy this on Heroku etc because the datasource is an internal API. How do I go about deploying this application on the server? It's a Linux based machine.
I found this post that says use the code below but not quite sure where to add this piece of code.
waitress-serve --host=0.0.0.0 --port=8080 appname:app.server
The code you are referring to, waitress-serve, is a command-line wrapper bound to the function waitress.serve provided by Waitress.
You run it in your terminal or from a shell script.
Waitress is a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones which live in the Python standard library. It runs on CPython on Unix and Windows under Python 3.7+.
You can install it with pip install waitress.
#see waitress-serve documentation here.
My apologies if this has been answered somewhere. I looked and did not find an answer to this rather specific question.
My environment:
PC: Windows 10 Home, Dual Monitors, Git Bash, PyCharm, static IP assigned
Raspberry Pi: GPS Module (NMEA 0183 interface connected via USB
Developing a data logger utilizing Python with flask and serial modules
Since my PC is much easier to develop on, I have been updating the code there but I need to actually test it on the Raspberry Pi because it has the GPS module and is my target environment. I was pushing the changes via GIT to BitBucket. I would then pull the changes back down to my R Pi - this was working OK but it required me to commit and push after each update. I was trying eliminate a step using my local network.
I added a remote name "Pi3" to my project on the PC but when I tried to push the updates to my Pi I got a message saying "[remote rejected] (branch is currently checked out). I could checkout the master, push the updates and then re-checkout my development branch but by the time I do this I might as well hop through BitBucket.
I then tried doing a pull or fetch from my Pi 3 but since I do not have an sshd (SSH server) running on my PC, it naturally failed. A quick look at setting up a SSH Server on Windows 10 looks like a huge pain. I am willing to endure that pain for long term gain but I am unsure if this would get me there even after I set it up.
I guess another solution is to script using scp to copy the files that I want but that requires maintenance as the project grows or I work on a different project. I can't be the only one that codes on one system and tests on another.
Any suggestions or feedback is appreciated.
It sounds like your workflow is based around git and new commits should be made available on the remote machine (Pi). You might want to define a post-commit or post-receive hook to copy your latest code over to the Pi, preferably via rsync.
See more about git hooks here.
Another option is to define your remote git as bare clone (see here), so you can just push to the remote git without conflicting checked-out branches in the way.
I'm hosting a website on AWS. Its a web interface with a SQL database. The website will be used to:
1. View results of query from Database
2. Insert data into database
3. View the data and update it where needed.
The codes and connections works file when I run the application on localhost (Apache on my C drive). But we want to host it on AWS so that people around me can use it.
So, In AWS I uploaded the code on EC2 and installed apache on it, all the html links are working but the python file is simply displaying the code.
I'm guessing it has something to do with the shebang. Currently my code has the following shebang:
#!C:\Python27\python.exe
Can someone guide me if its the shebang or if there is something else i need to do.
I have installed boto, but not sure what to do next. The AWS website and most of the forums talk about using Elastic Beanstalk. I want to host a fully functioning Python webApp on AWS without using Elastic Beanstalk.
When apache displays code, that is a clear sign that Apache is not configured properly to execute python. You should look to see if mod_python is installed and configured correctly.
Also, #! is generally used with Linux not windows. If apache/mod_python is installed and configured correctly I can't imagine what code you'd have that would need #! since the .py extension would be enough.
IF your EC2 instance is indeed running Linux, and your code does indeed need #! try:
#!/bin/python
OR
#!/usr/local/bin/python
(Depends on where the python binary is, and those are the most common locations.)
If your EC2 instance is running Windows then "Unless you are using cygwin, windows has no shebang support"
Hi have you logged into your EC2 instance through the endpoint and then run your script, from the command line. I have some experience with EC2 running apache2 only my application was written in Java, having previously used python scripts I was able to run them by logging into my EC2 instance, you can do this from AWS management console. hope this helps you somewhat.
I am writing a web python application with tornado framework on a raspberry pi.
What i actually do is to connect to my raspberry with ssh. I am writing my source code with vi, on the raspberry.
What i want to do is to write source code on my development computer but i do not know how to synchronize (transfer) this source code to raspberry.
It is possible to do that with ftp for example but i will have to do something manual.
I am looking for a system where i can press F5 on my IDE and this IDE will transfer modified source files. Do you know how can i do that ?
Thanks
Some IDEs like JetBrains PyCharm are supporting automatically file upload via ssh/scp/ftp.
Following a couple of bad experiences where I lost code which was only on my Pi's SD card, I now run WinSCP on my laptop, and edit files from Pi on my laptop, they open in Notepad++ and WinSCP automatically saves edits to Pi. And also I can use WinSCP folder sync feature to copy contents of SD card folder to my latop. Not perfect, but better what I was doing before
I have done this before using bitbucket as a standard repository and it is not too bad. If you set up cron scripts to git pull it's almost like continuous integration.
On my RPi (b model) Flask is installed.
I can access the webpage "It works" via another browser on another computer.
Works great. As well on my LAN as from the outside world.
And also, I can write and run Python scripts and let it act as server and so on.
But how do I enable my own Python script for Flask as standard at boot from RPi.
It's seated in the /home/pi/myproject dir and I'd like it to be standard.
I can't find the standard python script and templates to replace.
Any help is welcome.