First of all, sorry if this isn’t the appropriate place, but after browsing other forums for a couple of hours, I’m yet to find a solution.
Basically, I have an Apache Server set up in a CentOS machine, where I’m trying to host a streamlit app. For testing purposes, lets assume this is the script:
#!/usr/bin/python3
print("Content-Type: text/plain;charset=utf-8 \n\n")
import streamlit as st
def main():
print("Hello World")
a = 2
print("\nthe value of a is ", a)
st.write('streamlit dummy message')
if st.button('First Button'):
print('1 - button pressed')
b = a + 2
print("\n the value of b is ", b)
if __name__ == '__main__':
main()
But when accessing the respective page, all i see is:
Basically, anything non-streamlit renders normally, while streamlit related commands like button or write provide no output whatsoever.
I tried changing the content-type in the html parameters to application or so, but nothing worked so far.
Also, i must admit I’m quite a beginner in terms of web-hosting so that might be the cause of the problem (and again, sorry for asking this in the wrong place).
Also related, my httpd.confi file for this particular script:
If there’s any help you can give I’d be forever in your doubt.
And if there’s more info you need, please don’t hesitate.
Thanks for your question! You’re on the right track, it’s just that Streamlit’s execution model won’t really play nice with ExecCGI.
You should run your streamlit app on an unprivileged port (8501 is fine, say), and then use a “reverse proxy” to forward all requests from port 80 (the usual HTTP port) to your streamlit app.
Here’s an example config you can edit for your purposes (and let us know how it goes):
<VirtualHost _default_:80>
DocumentRoot /home/user/website_folder
RewriteEngine On
# Redirect all requests to the local Apache server to port 8080
RewriteRule ^.*$ http://%{HTTP_HOST}:8501%{REQUEST_URI}
</VirtualHost>
@monchier thanks for your help, but alas, all the modules were already installed and configured.
There has been an update, though:
Using the following configuration, I think we’ve made some progress as I am no longer getting any error. The bad news is that all i get now is a blank page.
But when i try to open http://streamlit.group.pt/test1 all i get is a blank page.
Opening http://streamlit.group.pt/ returns the default html file though, located at /var/www/example.com/html.
The example .py file I’m currently running from streamlit is also located at /var/www/example.com/html.
I’m going to try and modify the above config and see if can progress further, but any help is more than welcome.
Edit:
Forgot to add something:
If I try to open http://streamlit.group.pt:8501 I can see the streamlit report without any issues. It’s only when I try to use http://streamlit.group.pt/test1 that I have this problem. And yes, I have to use the /test1 alias or some sort of alias when providing streamlit services to my clients
I am wondering you are hitting an issue we found out recently. We recently found a bug in the way the path to the static resources is calculated. Can you try to use a slash at the end of your target path?
Hey @marciorpcoelho - this seems like an Apache configuration error, and I’m not sure any of us here have enough direct Apache experience to be very useful for debugging it further , apologies.
Have you tried asking the Apache experts at StackOverflow?
Streamlit’s web server is not terribly exotic (it serves both HTTP and Websocket traffic over :8501, by default), so I would assume someone more well-versed in Apache than we are would be able to offer more assistance!
hi @marciorpcoelho
I am facing the same or a similar problem trying to setup Virtual Host on Apache. Did you progress with this issue on StackOverflow?
The only problem so far, is that when opening the link streamlit.group.pt/streamlit_report_name the link automatically changes to streamlit.group.pt:8502, as I still haven’t managed to find a correct configuraton for this.
Thanks so much, @marciorpcoelho, this worked like a charm. The only problem remaining is the one you mention. From our organization, addresses with port numbers are blocked, I reckon many others do the same. I will continue searching for a solution for this and I am most interested in case you find a solution on your end. However, this first part was really important for me so thanks again.
Hi @marciorpcoelho, thanks a lot for your answer, it helped me a lot. I am just wondering if you have fingered out how to solve the issue wih changing to streemlit.group.pt:8502. Thanks again.
Glad it helped, but so far I haven’t managed to solve that small problem. Admittedly I didn’t try much more as it currently serves its purpose and the port displaying isn’t an issue in our company.
@marciorpcoelho Question…where in the config are you referring to your streamlit app (i.e .py file)…
I see it was mentioned in initial question but is not present in this solution?
Hello @Gaura
You don’t need to refer to the .py file as they are not related. The config file just sets rules of where the traffic from port 8502 should point to.
You then just need to run your streamlit app (.py file) in the configured port ( in my case, it was 8502) and that’s it. If tomorrow you’d like to change the app, just terminate and run the new app in the same port.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.