R
R
RacceGatel2021-05-31 16:04:12
PHP
RacceGatel, 2021-05-31 16:04:12

Is it possible to have Flask and PHP on the same server?

Experimental question: there is a flask application that can receive post requests for parsing information that is then entered into the database, there is also a ready-made php site that lies on the server. Is it possible to somehow put flask on a server, then configure it so that requests are not accepted from outside, and create a function on the site that, when called, via php makes a request to the flask?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
MikUrrey, 2021-05-31
@MikUrrey

Perhaps the best way to do this is to use Docker. Flask in one container, PHP in another, database in a third. Run everything through Docker compose, and let them communicate with each other over the internal network.
You can do it right as it is, in one space, but then you need to set up ports and web servers.
Although you can also try to force Flask to listen on some specific port, say 82, and then the site, theoretically, will be able to knock on it through 127.0.0.1:82. But in practice, without fine-tuning, elements of the environment can fight among themselves.

S
Sergey Gornostaev, 2021-06-01
@sergey-gornostaev

Just install Nginx, set up two virtual hosts in it, one will have php-fpm upstream, the other will have uWSGI and that's it.

B
Boris Syomov, 2021-05-31
@kotomyava

Of course you can.
To do this, you don’t even need to configure anything additionally, just don’t proxy requests to flask on the web server. By default, flask starts at 127.0.0.1:5000, and until a web server is raised nearby that will proxy requests to it, or the configuration is not changed so that it is available on the external interface, it will not be available from the outside, but will be available to your php application.

R
rPman, 2021-05-31
@rPman

Yes, you can specify in the flask application settings to listen to incoming at localhost address (or if there are other subnets on the server, for example, a local network or vpn, then listen there) as well as an alternative, configure a firewall
app.run(host='127.0.0.1')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question