How to configure apache for flask and php on the same server
P粉547170972
P粉547170972 2024-01-10 17:18:45
0
1
429

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粉547170972
P粉547170972

reply all(1)
P粉431220279

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template