Skip to content

Commit 1fd6b9e

Browse files
committed
update installation instructions
I've tested these instructions with a fresh Ubuntu 24.04 machine.
1 parent 220456d commit 1fd6b9e

File tree

4 files changed

+85
-42
lines changed

4 files changed

+85
-42
lines changed

docs/server-installation/ubuntu-web.rst

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,16 @@ For more information, consult `the Django documentation <https://docs.djangoproj
1111

1212
.. note::
1313

14-
The following instructions are for a server running Ubuntu Xenial (16.04) or newer.
14+
The following instructions are for a server running Ubuntu 24.04 or newer.
1515

1616
Essential package installation
1717
------------------------------
1818

19-
Packages that would be installed as part of a standard Ubuntu install
20-
are not listed.
19+
#. Install required packages using the ``apt`` packaging system::
2120

22-
#. Install Apache, Git, Apache WSGI module, MySQL and Python 3 using the ``apt`` packaging system::
23-
24-
apt-get install apache2 apache2-dev git-core mysql-server \
25-
mysql-common python3 acl libmysqlclient-dev python-dev \
26-
libapache2-mod-wsgi-py3 python-tk tcl-dev tk-dev
27-
28-
#. Enable ``mod_wsgi``, if it's not already::
29-
30-
a2enmod wsgi
21+
apt install nginx git-core mysql-server \
22+
mysql-common python3 acl libmysqlclient-dev python3-dev \
23+
supervisor python3-pip python3-virtualenv pkg-config
3124

3225
Virtualenv
3326
----------
@@ -43,23 +36,15 @@ approach is to use `virtualenv <https://virtualenv.pypa.io>`_, which is a tool t
4336
4437
You might need to start a new terminal, or log out and back in, for the group change to take effect.
4538

46-
#. Install Pip::
47-
48-
apt-get install python3-pip
49-
50-
#. Install virtualenv::
51-
52-
pip3 install virtualenv
53-
5439
#. Create the virtualenv in a suitable location::
5540
56-
mkdir /opt/python
57-
setfacl -dR -m g:numbas:rwx /opt/python
58-
virtualenv /opt/python/numbas-editor
41+
mkdir /opt/numbas_python
42+
setfacl -dR -m g:numbas:rwx /opt/numbas_python
43+
virtualenv -p python3 /opt/numbas_python
5944

6045
#. Activate the virtualenv::
6146

62-
source /opt/python/numbas-editor/bin/activate
47+
source /opt/numbas_python/bin/activate
6348
6449
(This ensures that subsequent python packages are installed in this isolated environment, and not in the system environment.)
6550

@@ -77,7 +62,8 @@ Database
7762
#. Create a database user and grant privileges on ``numbas_editor``
7863
database, with a password of your choice::
7964

80-
grant all privileges on numbas_editor.* to 'numbas_editor'@'localhost' identified by 'password';
65+
create user 'numbas_editor'@'localhost' identified by 'password';
66+
grant all privileges on numbas_editor.* to 'numbas_editor'@'localhost';
8167

8268
Create directories and set permissions
8369
--------------------------------------
@@ -87,6 +73,7 @@ Create directories and set permissions
8773
8874
mkdir /srv/numbas
8975
mkdir /srv/numbas/compiler
76+
mkdir /srv/numbas/editor
9077
mkdir /srv/numbas/media
9178
mkdir /srv/numbas/previews
9279
mkdir /srv/numbas/static
@@ -105,17 +92,17 @@ Clone the editor and compiler repositories
10592

10693
#. Clone the Numbas repository::
10794

108-
git clone git://github.com/numbas/Numbas /srv/numbas/compiler
95+
git clone https://github.com/numbas/Numbas /srv/numbas/compiler
10996

11097
#. Clone the editor under the webroot directory::
11198

112-
git clone git://github.com/numbas/editor /srv/www/numbas_editor
99+
git clone https://github.com/numbas/editor /srv/numbas/editor
113100

114101
#. Install the Python module dependencies of the editor (in the virtualenv)::
115102

116-
pip install -r /srv/www/numbas_editor/requirements.txt
103+
pip install -r /srv/numbas/editor/requirements.txt
117104
pip install -r /srv/numbas/compiler/requirements.txt
118-
pip install mysqlclient mod_wsgi
105+
pip install mysqlclient gunicorn
119106

120107
Configuration
121108
-------------
@@ -133,16 +120,71 @@ Configuration
133120
If you make any mistakes, you can run the script again, or edit
134121
``numbas/settings.py`` directly.
135122

136-
#. Create the apache config file and enable the site.
123+
#. Create the supervisor, gunicorn and nginx config files and enable the site.
124+
125+
- Copy the WSGI file::
126+
127+
mkdir /var/log/gunicorn
128+
chown www-data:www-data /var/log/gunicorn
129+
cd /srv/numbas/editor
130+
131+
- Edit ``/srv/numbas/editor/web/gunicorn.conf.py`` with these contents::
132+
133+
# Serve on port 8001
134+
bind = "0.0.0.0:8001"
135+
# Number of worker processes to run. Increase when there is more traffic.
136+
workers = 1
137+
# Access log - records incoming HTTP requests
138+
accesslog = "/var/log/gunicorn/numbas_editor_access.log"
139+
# Error log - records Gunicorn server goings-on
140+
errorlog = "/var/log/gunicorn/numbas_editor_error.log"
141+
# Whether to send Django output to the error log
142+
capture_output = True
143+
# How verbose the Gunicorn error logs should be
144+
loglevel = "info"
145+
146+
- Edit ``/etc/supervisor/conf.d/numbas_editor.conf`` with these contents::
147+
148+
[program:numbas_editor]
149+
command=/opt/numbas_python/bin/gunicorn -c /srv/numbas/editor/web/gunicorn.conf.py web.wsgi:application
150+
directory=/srv/numbas/editor/
151+
user=www-data
152+
autostart=true
153+
autorestart=true
154+
stopasgroup=true
155+
environment=DJANGO_SETTINGS_MODULE=numbas.settings
156+
numprocs=1
157+
158+
- Overwrite ``/etc/nginx/sites-enabled/default`` with these contents::
159+
160+
server {
161+
listen 80;
162+
163+
client_max_body_size 100M;
164+
165+
location = /favicon.ico { access_log off; log_not_found off; }
166+
location /static/ {
167+
alias /srv/numbas/static/;
168+
}
169+
location /media/ {
170+
alias /srv/numbas/media/;
171+
}
172+
location /numbas-previews {
173+
alias /srv/numbas/previews/;
174+
add_header 'Access-Control-Allow-Origin' '*';
175+
}
176+
177+
location / {
178+
include proxy_params;
179+
proxy_pass http://localhost:8001;
180+
proxy_read_timeout 120s;
181+
}
182+
}
183+
137184

138-
- Edit ``/etc/apache2/sites-available/numbas_editor.conf`` with
139-
contents similar to that in :download:`this prepared config file <apache2_ubuntu.conf>`.
140-
If following these instructions exactly, then you only need to change the lines containing ``ServerName`` and ``ServerAdmin``.
185+
- Restart supervisor and nginx::
141186

142-
- Enable the configuration::
143-
144-
a2ensite numbas_editor.conf
145-
service apache2 reload
187+
systemctl restart nginx supervisor
146188

147189
#. Point a web browser at the server hosting the editor.
148190

@@ -151,16 +193,16 @@ Ongoing maintenance
151193

152194
To keep the editor up to date, run the following script::
153195

154-
source /opt/python/numbas-editor/bin/activate
196+
source /opt/numbas_python/bin/activate
155197
cd /srv/numbas/compiler
156198
git pull origin master
157199
pip install -r requirements.txt
158-
cd /srv/www/numbas_editor
200+
cd /srv/numbas/editor
159201
git pull origin master
160202
python manage.py migrate
161203
python manage.py collectstatic --noinput
162204
pip install -r requirements.txt
163-
touch web/django.wsgi
205+
supervisorctl restart numbas_editor
164206

165207
Note that if any changes are made to the editor code, including
166208
editing the settings files, then for the web server to recognise

first_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def write_files(self):
357357
self.sub_settings()
358358

359359
if not self.values['DEBUG']:
360-
self.sub_file(Path('web', 'django.wsgi'), [ (r"sys.path.append\('(.*?)'\)", 'PWD') ])
360+
self.sub_file(Path('web', 'wsgi.py'), [ (r"sys.path.append\('(.*?)'\)", 'PWD') ])
361361

362362
index_subs = [
363363
(r"Welcome to (the Numbas editor)", 'SITE_TITLE'),

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ six==1.16.0
1818
mistune==2.0.3
1919
emoji==0.6.0
2020
pycryptodome==3.14.1
21+
setuptools==70.0.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os, sys
2-
sys.path.append('/srv/www/numbas_editor')
2+
sys.path.append('/srv/numbas/editor')
33
os.environ['DJANGO_SETTINGS_MODULE'] = 'numbas.settings'
44

55
from django.core.wsgi import get_wsgi_application

0 commit comments

Comments
 (0)