As I struggled a few hours to get this UAR, I wrote down my notes and post it to my website as it might be helpfull to others too.
To get a django app work on apache2 with ISPConfig:
1.Install python3 and pip on your server. With pip install django and required modules for django. You probably know how to do this, as you are reading this to deploy your tested django app (alternatively, you can use anaconda instead of pip, use google to find out how).
2. Install and enable passenger. The install instructions from the makers you find here.
I faced my first problem here, passenger is using port 3000. I have gitlab running on that instance, which has a grafana component using port 3000 as well. I mitigated this by setting the grafana port to 3030 in /etc/gitlab/gitlab.rb and execute sudo gitlab-ctl reconfigure
3. This is somewhat tricky I think. Currently, passenger crashes on starting apache2. The problem and the workaround is expained here on stackoverflow. Just as mentioned in the comments in the gitub issue linked there, I guess this is a dirty workaround, the probable real issue is not in apache but in passenger and in the end, should be solved there.
In my case, I commented out the line in /etc/systemd/system/multi-user.target.wants/apache2.service
I want to reactivate it asap after there is a proper fix for it!
4. create the website on ISPConfig
5. create a shell user
6. ssh as this shell user to your server
7. cd ~/web
8. git clone <django site>
9. pip virtualenv env (or pip3, see 1, just how python and pip are configured)
10. git clone <django-git-url> (I maintain my django apps on git, you can also do it your own way)
11. create passenger_wsgi.py with following content:
import sys, os ApplicationDirectory = '<dirname>' ApplicationName = 'appname' VirtualEnvDirectory = 'env' VirtualEnv = os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin', 'python') if sys.executable != VirtualEnv: os.execl(VirtualEnv, VirtualEnv, *sys.argv) sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory)) sys.path.insert(0, os.path.join(os.getcwd(), ApplicationDirectory, ApplicationName)) sys.path.insert(0, os.path.join(os.getcwd(), VirtualEnvDirectory, 'bin')) os.chdir(os.path.join(os.getcwd(), ApplicationDirectory)) os.environ.setdefault('DJANGO_SETTINGS_MODULE', ApplicationName + '.settings') from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
12. Create a tmp dir in the root of your webdirectory and create an exmtpy file named 'restart.txt.' in that directory. Again, stackoverflow came to the rescue.
mkdir tmp && touch tmp/restart.txt
13. Assuming the rootdirectory of your web now looks like similar like this:
├── <django app dir>
├── <django appname>
├── <django app1>
├── <django app2>
└── <django app ....>
Go to the options tab of your site in ISPConfig, and put below in the "Apache Directives" textbox:
# Prevent al sorts of complaining about index files not found DirectoryIndex disabled Alias /static/ /var/www/clients/<client#>/<site>/web/<path/to/static/ <Directory /var/www/clients/<client#>/<site>/web/path/to/static> Require all granted </Directory> Alias /favicon.ico /var/www/clients/<client#>/<site>/web/path/to/static/favicon.ico # No index files found <Directory /var/www/clients/<client#>/<site>/web> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> <Directory /var/www/clients/<client#>/<site>/web> <Files passenger_wsgi.py> Require all granted </Files> </Directory> PassengerEnabled On PassengerAppType wsgi PassengerStartupFile passenger_wsgi.py # https://stackoverflow.com/questions/60197621/passenger-does-not-recognize-application-message-from-phusion-end-time-can-not PassengerDisableAnonymousTelemetry on # https://stackoverflow.com/questions/23619262/passenger-on-apache-doesnt-seem-to-be-running-app-page-gives-403-what-next PassengerAppRoot /var/www/clients/<client#>/<site>/web
Offcourse, it is outmost important that you change paths and names to your individual situation!
13. Hit save. You should be all set now!