Note: URLs, usernames, etc. have been changed for privacy.
I am designing an API in Flask, but the website is originally in PHP. Eventually this will be changed, but for the moment I would like both to run side by side on the same url, we will call it domain.com. The Flask API should be located at www.domain.com/api and the PHP website at www.domain.com.
The Apache file for the websites is located at: /etc/apache2/sites-available/domain.com. By using one of the individual settings below and restarting apache, I can get that framework to run alone, but I have not figured out how to get them both in the file and running without issues.
Flask (www.domain.com/api):
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName www.domain.com
WSGIDaemonProcess api user=www-data group=www-data threads=5
WSGIScriptAlias /api /home/user/public_html/api/api.wsgi
<Directory /home/user/public_html/api>
WSGIProcessGroup api
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
PHP (www.domain.com):
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName www.domain.com
DirectoryIndex index.php
DocumentRoot /home/user/public_html/domain.com/
</VirtualHost>
I have experimented with a number of things like Directory and Alias, but I have not been able to find a solution yet.
The answer was pretty simple when I discovered that WSGIScriptAlias works similarly to Alias. Then I can simply combine the two and it works how I want it to.
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName www.domain.com
DirectoryIndex index.php
DocumentRoot /home/user/public_html/domain.com/
WSGIDaemonProcess api user=www-data group=www-data threads=5
WSGIScriptAlias /api /home/user/public_html/api/api.wsgi
<Directory /home/user/public_html/api>
WSGIProcessGroup api
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>