Skip to content

Commit 6266e10

Browse files
authored
Merge pull request #54 from drgrice1/apache2-production-setup
Update the build and deployment method for apache2 on Ubuntu
2 parents 5cb9cc6 + 193b458 commit 6266e10

File tree

6 files changed

+165
-35
lines changed

6 files changed

+165
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pnpm-debug.log*
2727
# Project files
2828
sample_db.sqlite
2929
conf/webwork3.yml
30+
conf/apache2/webwork3-apache2.conf
31+
conf/apache2/webwork3.service
32+
conf/apache2/renderer.service
3033

3134
# Devel::Cover
3235
cover_db/

README.md

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,45 +109,75 @@ This section builds all of the UI code using webpack and fires up a browser wind
109109
4. You should get a "Login to WeBWorK" screen. You can use the Lisa Simpson account with the username `lisa` and the
110110
password `lisa`.
111111

112-
### Production build and deployment (instructions for apache2 on Ubuntu2)
112+
### Production build and deployment (instructions for apache2 on Ubuntu)
113113

114114
TODO: add instructions for other servers and operating systems and add a docker deployment approach
115115

116-
1. Inside the `webwork3` directory, execute `yarn install` or `npm install`.
117-
118-
2. Build the client side user interface with `quasar build`.
119-
120-
3. Copy `webwork3/dist/spa` to `/var/www/html/webwork3` (or create a link).
121-
122-
4. Add the following lines to your apache2 site configuration file:
123-
124-
```apacheconf
125-
# Vue Router configuration for webwork3
126-
<IfModule mod_rewrite.c>
127-
<Directory "/var/www/html/webwork3">
128-
RewriteEngine On
129-
RewriteBase /webwork3/
130-
RewriteRule ^webwork3/index\.html$ - [L]
131-
RewriteCond %{REQUEST_FILENAME} !-f
132-
RewriteCond %{REQUEST_FILENAME} !-d
133-
RewriteRule . /webwork3/index.html [L]
134-
</Directory>
135-
</IfModule>
136-
# Mojolicious configuration for webwork3
137-
<Proxy /webwork3/api/*>
138-
Require all granted
139-
</Proxy>
140-
ProxyRequests Off
141-
ProxyPreserveHost On
142-
ProxyPass /webwork3/api http://localhost:8080/webwork3/api keepalive=On
143-
ProxyPassReverse /webwork3/api http://localhost:8080/webwork3/api
144-
ProxyPass /webwork3/api/* http://localhost:8080/webwork3/api/ keepalive=On
145-
ProxyPassReverse /webwork3/api/* http://localhost:8080/webwork3/api/
146-
RequestHeader set X-Forwarded-Proto "http"
116+
1. Install node version 16 with the following.
117+
118+
```sh
119+
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
120+
sudo apt install nodejs
121+
```
122+
123+
2. Inside the `webwork3` directory, execute `yarn install` or `npm install`.
124+
125+
3. Build the client side user interface with `quasar build` or `npm run build`.
126+
127+
4. Copy `webwork3/dist/spa` to `/var/www/html/webwork3` (or create a link).
128+
129+
5. Enable the necessary apache2 modules.
130+
131+
```sh
132+
sudo a2enmod headers proxy proxy_http rewrite
133+
```
134+
135+
6. Copy `conf/apache2/webwork3-apache2.dist.conf` to `conf/apache2/webwork3-apache2.conf`, and create a link to that
136+
file in `/etc/apache2/conf-enabled`. This can be accomplished by executing the following commands from the webwork3
137+
directory.
138+
139+
```sh
140+
cp conf/apache2/webwork3-apache2.dist.conf conf/apache2/webwork3-apache2.conf
141+
sudo ln -s $(pwd)/conf/apache2/webwork3-apache2.conf /etc/apache2/conf-enabled
142+
```
143+
144+
7. Restart apache2 with `sudo systemctl restart apache2`.
145+
146+
8. Set up permissions for the api with the following commands executed from the webwork3 directory.
147+
148+
```sh
149+
sudo chown -R youruser:www-data logs
150+
sudo chmod g+rw logs/*
151+
```
152+
153+
9. Copy `conf/apache2/webwork3.dist.service` to `conf/apache2/webwork3.service` and modify `WorkingDirectory` with the
154+
correct path to the webwork3 location. Make sure to uncomment the hypnotoad `pid_file` setting in the `webwork3.yml`
155+
file. Then enable and start the webwork3 api service by executing the following from within the `webwork3`
156+
directory.
157+
158+
```sh
159+
sudo systemctl enable $(pwd)/conf/apache2/webwork3.service
160+
sudo systemctl start webwork3
147161
```
148162

149-
4. Restart apache2 with `sudo systemctl restart apache2` (or the appropriate command for your system).
163+
10. Set up permissions for the renderer with the following commands executed from the renderer directory.
164+
165+
```sh
166+
sudo chown -R youruser:www-data logs
167+
sudo chmod g+rw logs/standalone_results.log
168+
sudo chmod -R g+rw lib/WeBWorK/tmp/* lib/WeBWorK/htdocs/tmp/*
169+
```
170+
171+
11. Copy `conf/apache2/renderer.dist.service` to `conf/apache2/renderer.service` and modify `WorkingDirectory` in the
172+
copied file with the correct path to the webwork3 location. Add `pid_file => '/var/run/webwork3/renderer.pid'` and
173+
`proxy => 1` to the hypnotoad configuration in the `render_app.conf` file. Then enable and start the renderer
174+
service by executing the following from within the `webwork3` directory.
175+
176+
```sh
177+
sudo systemctl enable $(pwd)/conf/apache2/renderer.service
178+
sudo systemctl start renderer
179+
```
150180

151-
5. Run `hypnotoad bin/webwork3` from within the `webwork3` directory.
181+
Note that anytime the server is rebooted the webwork3 api and renderer services will be automatically started.
152182

153-
6. Visit `localhost/webwork3`.
183+
12. Visit `localhost/webwork3`.

conf/apache2/renderer.dist.service

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[Unit]
2+
Description=Standalone Renderer for WeBWorK 3
3+
After=network.target
4+
5+
[Service]
6+
Type=forking
7+
User=www-data
8+
Group=www-data
9+
PIDFile=/var/run/webwork3/renderer.pid
10+
PermissionsStartOnly=true
11+
ExecStartPre=-/bin/mkdir /var/run/webwork3
12+
ExecStartPre=/bin/chown -R www-data:www-data /var/run/webwork3
13+
# Change /path/to to the full path to the renderer directory.
14+
WorkingDirectory=/path/to/renderer
15+
ExecStart=/usr/local/bin/hypnotoad script/render_app
16+
ExecReload=/usr/local/bin/hypnotoad script/render_app
17+
KillMode=process
18+
19+
[Install]
20+
WantedBy=multi-user.target
21+
22+
# vim: syntax=systemd
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Vue router client ui configuration
2+
<IfModule mod_rewrite.c>
3+
# Note that this must be consistent with the value of publicPath in quasar.conf.js.
4+
<Directory "/var/www/html/webwork3">
5+
RewriteEngine On
6+
RewriteBase /webwork3/
7+
RewriteRule ^/webwork3/index\.html$ - [L]
8+
RewriteCond %{REQUEST_FILENAME} !-f
9+
RewriteCond %{REQUEST_FILENAME} !-d
10+
RewriteRule . /webwork3/index.html [L]
11+
</Directory>
12+
</IfModule>
13+
14+
# Server side api configuration
15+
<Proxy /webwork3/api/*>
16+
Require all granted
17+
</Proxy>
18+
ProxyRequests Off
19+
ProxyPreserveHost On
20+
ProxyPass /webwork3/api http://localhost:3000/webwork3/api keepalive=On
21+
ProxyPassReverse /webwork3/api http://localhost:3000/webwork3/api
22+
ProxyPass /webwork3/api/* http://localhost:3000/webwork3/api/ keepalive=On
23+
ProxyPassReverse /webwork3/api/* http://localhost:3000/webwork3/api/
24+
RequestHeader set X-Forwarded-Proto "http"
25+
26+
# renderer configuration
27+
<Proxy /renderer/*>
28+
Require all granted
29+
</Proxy>
30+
ProxyRequests Off
31+
ProxyPreserveHost On
32+
ProxyPass /renderer http://localhost:3001/renderer keepalive=On
33+
ProxyPassReverse /renderer http://localhost:3001/renderer
34+
ProxyPass /renderer/* http://localhost:3001/renderer/ keepalive=On
35+
ProxyPassReverse /renderer/* http://localhost:3001/renderer/
36+
RequestHeader set X-Forwarded-Proto "http"
37+
38+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

conf/apache2/webwork3.dist.service

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=WeBWorK 3
3+
After=network.target
4+
5+
[Service]
6+
Type=forking
7+
User=www-data
8+
Group=www-data
9+
PIDFile=/var/run/webwork3/webwork3.pid
10+
PermissionsStartOnly=true
11+
ExecStartPre=-/bin/mkdir /var/run/webwork3
12+
ExecStartPre=/bin/chown -R www-data:www-data /var/run/webwork3
13+
# Change /path/to to the full path to the webwork3 directory.
14+
ExecStart=/usr/local/bin/hypnotoad /path/to/webwork3/bin/webwork3
15+
ExecReload=/usr/local/bin/hypnotoad /path/to/webwork3/bin/webwork3
16+
KillMode=process
17+
18+
[Install]
19+
WantedBy=multi-user.target
20+
21+
# vim: syntax=systemd

conf/webwork3.dist.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ opl_url: http:/localhost:3030
2626
cookie_samesite: "None"
2727
cookie_secure: true
2828
cookie_lifetime: 3600
29+
30+
# Production server configuration
31+
hypnotoad:
32+
listen:
33+
- http://*:3000
34+
accepts: 400
35+
workers: 10
36+
spare: 5
37+
clients: 100
38+
graceful_timeout: 45
39+
inactivity_timeout: 30
40+
keep_alive_timeout: 30
41+
requests: 5
42+
# Uncomment the next two lines for the apache2 production setup
43+
#pid_file: /var/run/webwork3/webwork3.pid
44+
#proxy: 1

0 commit comments

Comments
 (0)