Streamlit Ports

I am trying to call a streamlit file from PHP script. It gets called when I use a port number. But when I make changes to the file and execute it on the port, the changes don’t get updated. I want to clear the contents present in the file and then over write it

Thank you

Hi @akshat,

Thanks for posting! If you’re doing this locally, I have recorded my screen running an example app with the scenario you provided; updating the Streamlit app and seeing changes propagate to the port.

Directory tree structure:

├──   # Streamlit app file
└── php_app.php        # PHP script to run the Streamlit app

Here’s the code for my .php file;


// Command to run Streamlit app
$command = 'streamlit run';

// Execute the command
$output = shell_exec($command);

// Print the output 
echo $output;

Python/Streamlit code;

import streamlit as st

st.title('Hello from Streamlit! 🎈')
st.write('This app is run from PHP!')

code = '''<?php

// Command to run Streamlit app
$command = 'streamlit run';

// Execute the command
$output = shell_exec($command);

// Print the output 
echo $output;

st.code(code, language="php")

if st.button("Click to see baloons!"):

On the terminal, run php -S localhost:8000 then open a browser window and go to http://localhost:8000/php_app.php. This will execute the PHP code and in turn, run the Streamlit app automatically. If you modify and save the code in your Streamlit app, it should rerun your app now.

Screen recording of running the app ↓

Please let me know if this helps!

1 Like

Thank you so much for the reply.
I have my majority of code in python in streamlit. I just want to keep the file running and refreshing on the same port. I have my file stored in ‘htdocs’ of XAMPP. Could that possibly be a reason for my config.toml file not being read because I have made changes to the colors but they don’t reflect on the site.
Is there anyway for changing the URL which will be displayed? Like instead of localhost:8501 I want it to display the website I want?
I have hosted the website on a beta server as well but it doesn’t load.
Thanks in advance

php code

        function launchStreamlit() {
            // Redirect the entire page to the Streamlit app URL
            $path = base_url();
            $port = 8516;

            $title_logo = base_url() . "assets/images/favicon.ico";
            exec("streamlit  run --server.port ".$port." python/ $path $title_logo");

            host = window.location.hostname; // Replace with your Streamlit app URL
            window.location.replace("http://" + host + ':' + <?= $port ?>);


When I make this work on localhost using Apache XAMPP, the file gets executed but it doesn’t work when I try running it on server.

Thanks for the info. When you’re running locally and change the theme in .streamlit/config.toml, you have to restart the app again by running streamlit run <you_app_name>.py for the changes to reflect.
I’m not entirely sure you can change the domain but there are possible ways around this like using a reverse proxy (although I haven’t given it a shot, yet) like Nginx or Apache. Here’s a tutorial someone made on deploying Streamlit app with custom domain on Apache 2.

Thank You! I will definitely give it a try.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.