Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Jan 7, 2022
2 parents 7803679 + 1f971f6 commit 0e1a9c1
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 48 deletions.
50 changes: 2 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,5 @@ We are not responsible for any irresponsible use of our program.
- Leo Jiaxing Li
- Richard Junjie Shen (Logo)



## Config the Flask Application with Apache2

### Install and Enable the Apache 2 module 'mod_wsgi'

```
sudo apt update
sudo apt install libapache2-mod-wsgi-py3 -y
sudo a2enmod mod-wsgi
```

### Apache2 Configuration Example

To add a config:

```
sudo nano /etc/apache2/sites-available/ictrl.conf
```

ictrl.conf Content:

```
<VirtualHost *:80>
ServerName ictrl.ca
DocumentRoot /var/www/ictrl/client/build
WSGIDaemonProcess ictrl_srv user=ictrl threads=20
WSGIScriptAlias /api /var/www/ictrl/ictrl_srv.wsgi
<Directory /var/www/ictrl>
WSGIProcessGroup ictrl_srv
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/ictrl_error.log
CustomLog ${APACHE_LOG_DIR}/ictrl_custom.log combined
</VirtualHost>
```

### To Enable the Site Config

```
sudo a2ensite ictrl
```
## Docs
- [Deployment](https://github.com/junhaoliao/iCtrl/blob/main/docs/deployment.md)
105 changes: 105 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Deployment of iCtrl on a Ubuntu Server (22.04) with Apache2

### Clone the Repository into the /var/www directory
```Shell
# with appropriate permissions (e.g. logged-in as root / www-data)
# if logging-in as www-data gives the following message:
# "This account is currently not available."
# We can change the default shell of www-data to make it available:
# sudo chsh www-data
# enter a shell path such as "/bin/bash"

cd /var/www
git clone https://github.com/junhaoliao/iCtrl.git ictrl
```

### Add a user named "ictrl" to respect the permission of the other users on the same server
```Shell
sudo useradd ictrl
sudo usermod -a -G www-data ictrl
```

### Install Dependencies and build web page
```bash
cd /var/www/ictrl

# run as user ictrl
sudo su ictrl

# create a Python3 virtual environment
python3 -m pip install --user virtualenv
python3 -m virtualenv venv

# activate the virual environment
source venv/bin/activate

# install all backend depedencies
pip install -r requirements.txt

# install frontend dependencies
cd client
npm i
npm run build
```

### Install and Enable the Apache 2 module 'mod_wsgi'

```Shell
sudo apt update
sudo apt install libapache2-mod-wsgi-py3 -y

# enable the wsgi module
sudo a2enmod wsgi
# alternatively, use this on some other distributions
# sudo a2enmod mod-wsgi
```

### Apache2 Configuration Example

To add a config:

```Shell
sudo nano /etc/apache2/sites-available/ictrl.conf
```

ictrl.conf Content:

```ApacheConf
<VirtualHost *:80>
ServerName ictrl.ca
DocumentRoot /var/www/ictrl/client/build
WSGIDaemonProcess ictrl_srv user=ictrl threads=20
WSGIScriptAlias /api /var/www/ictrl/ictrl_srv.wsgi
<Directory /var/www/ictrl>
WSGIProcessGroup ictrl_srv
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/ictrl_error.log
CustomLog ${APACHE_LOG_DIR}/ictrl_custom.log combined
</VirtualHost>
```

### To Enable the Site Config

```Shell
sudo a2ensite ictrl
```

### Configure HTTPS / WSS
1. Generate An SSL Cert
Providers such as [Let's Encrypt](https://letsencrypt.org/) can be used.
2. Copy the certs to the site directory to avoid permission issues
```Shell
sudo cp /etc/letsencrypt/live/junhao.ca/fullchain.pem .
sudo cp /etc/letsencrypt/live/junhao.ca/privkey.pem .

sudo chown www-data:www-data fullchain.pem privkey.pem
```

### Initialization of the Database

0 comments on commit 0e1a9c1

Please sign in to comment.