Home  >  Q&A  >  body text

How to configure apache for flask and php on the same server

The server I have been upgrading/updating has pages using php and python. I rewrote the python based page using the Flask framework and configured apache using wsgi:

<VirtualHost *:443>
    ServerName my_fake_site
    ...
    AliasMatch ^\/((?:flask_dir1|flask_dir2).*)\.((css|php|png)$((?:\?.*)?)) /var/www/html/app/.
    AliasMatch ^\/(.*)\.(css|html|php|png) /var/www/html/.

    WSGIDaemonProcess main_proc processes=8 python-home=/var/www/html/venv
    WSGIScriptAlias / /var/www/html/wsgi.py
    <Directory /var/www/html/>
        WSGIProcessGroup main_proc
        WSGIApplicationGroup %{GLOBAL} 
        Require all granted
    </Directory>

    SSLEngine on
    ...
</VirtualHost>

WSGIPythonPath /var/www/html
WSGIPythonHome /var/www/html/venv

On the old server, the url pointing to the directory defaulted to index.php using the DirectoryIndex option (set in another conf file). On the new server, I get an "Internal Server Error" message and a 500 response code in the error log.

So the ultimate question is, how do you configure apache to serve both pages processed by php and pages processed by python? (Note: There are several PHP-processed pages in the flask directory)

Edit: I added another AliasMatch line and it seems to do what I want. I was also able to remove "php" from the second AliasMatch line:

AliasMatch ^\/((?:flask_dir1|flask_dir2).*)\.((css|php|png)$((?:\?.*)?)) /var/www/html/app/.
AliasMatch ^\/(.*)\.(css|html|png) /var/www/html/.
AliasMatch ^\/((?:php_dir1|php_dir2).*) /var/www/html/

P粉547170972P粉547170972306 days ago410

reply all(1)I'll reply

  • P粉431220279

    P粉4312202792024-01-11 00:36:41

    As mentioned in my edit, the AliasMatch directive worked. From the documentation, this allows Apache to host static files, which I guess also includes php files.

    reply
    0
  • Cancelreply