Skip to content

Commit fcdbe63

Browse files
authored
Merge pull request #600 from tr-electronic-edv/ubuntu24
Instructions for production install to Ubuntu24.04
2 parents f558040 + ddcc911 commit fcdbe63

4 files changed

Lines changed: 254 additions & 1 deletion

File tree

INSTALL/INSTALL.ubuntu2204.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ With this configuration:
7676
## 1.4. Install PHP and dependencies (It's recommended to install php8 or php8.1 and all the modules of the version)
7777

7878
```bash
79-
sudo apt-get install -y php8.1 php8.1-cli php8.1-common hp8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath php8.1-intl php8.1-imagic
79+
sudo apt-get install -y php8.1 php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath php8.1-intl php8.1-imagick
8080
```
8181

8282
## 1.5 Apply PHP configuration settings in your php.ini

INSTALL/INSTALL.ubuntu2404.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
Installation on Ubuntu 24.04
2+
============================
3+
4+
# 1. Dependencies
5+
6+
Install some utilities, database, webserver
7+
```bash
8+
sudo apt update
9+
sudo apt-get install -y zip unzip git gettext curl jq mariadb-client mariadb-server apache2
10+
```
11+
12+
Install PHP and its dependencies (the default php version in Ubuntu 24.04 is php8.3):
13+
```bash
14+
sudo apt-get install -y php php-cli php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath php-intl php-imagick
15+
```
16+
17+
# 2. Monarc files
18+
19+
Run the [install_latest_fo_release.sh](../scripts/install_latest_fo_release.sh) script with `sudo`
20+
to download the latest Monarc release and unpack it into `/var/lib/monarc/`.
21+
22+
> The script is built to be used in the CI/CD pipelines and will fail with a clear error if the release is not reachable or the deploy directory already exits.
23+
24+
# 3. Webserver
25+
26+
Enable required Apache modules:
27+
28+
```bash
29+
sudo a2dismod status
30+
sudo a2enmod ssl
31+
sudo a2enmod rewrite
32+
sudo a2enmod headers
33+
```
34+
35+
Modify the default virtual host:
36+
37+
```bash
38+
sudo nano /etc/apache2/sites-enabled/000-default.conf
39+
```
40+
41+
Use this configuration as an example:
42+
43+
```conf
44+
<VirtualHost _default_:80>
45+
ServerAdmin admin@example.com
46+
ServerName monarc.local
47+
DocumentRoot /var/lib/monarc/fo/public
48+
49+
<Directory /var/lib/monarc/fo/public>
50+
DirectoryIndex index.php
51+
AllowOverride All
52+
Require all granted
53+
54+
# increase the default php limits
55+
# better here then in the global php.ini as the webserver could run other projects
56+
php_value upload_max_filesize 200M
57+
php_value post_max_size 50M
58+
php_value max_execution_time 100
59+
php_value max_input_time 223
60+
php_value memory_limit 512M
61+
# Error logs settings for production:
62+
php_value error_reporting E_ALL
63+
php_flag log_errors On
64+
# for development, set to "On"
65+
php_flag display_errors Off
66+
67+
</Directory>
68+
69+
<IfModule mod_headers.c>
70+
Header always set X-Content-Type-Options nosniff
71+
Header always set X-XSS-Protection "1; mode=block"
72+
Header always set X-Robots-Tag none
73+
Header always set X-Frame-Options SAMEORIGIN
74+
</IfModule>
75+
76+
SetEnv APP_ENV "production"
77+
</VirtualHost>
78+
```
79+
80+
Check the configuration and apply changes:
81+
82+
```bash
83+
apachectl configtest
84+
sudo apachectl restart
85+
```
86+
87+
88+
# 4. Database
89+
90+
Secure the MariaDB installation and set a strong root password.
91+
92+
```bash
93+
sudo mysql_secure_installation
94+
```
95+
96+
## 4.1 Create a database user
97+
98+
Start MariaDB as root:
99+
100+
```bash
101+
sudo mysql
102+
```
103+
104+
Create a new user for MONARC (please use more secured password):
105+
106+
```sql
107+
CREATE USER 'monarc'@'%' IDENTIFIED BY 'password';
108+
GRANT ALL PRIVILEGES ON monarc_cli.* TO 'monarc'@'%';
109+
GRANT ALL PRIVILEGES ON monarc_common.* TO 'monarc'@'%';
110+
FLUSH PRIVILEGES;
111+
```
112+
113+
## 4.2 Create 2 databases
114+
115+
In your MariaDB interpreter:
116+
117+
```sql
118+
CREATE DATABASE monarc_cli DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
119+
CREATE DATABASE monarc_common DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
120+
```
121+
122+
* monarc_common contains models and data created by CASES;
123+
* monarc_cli contains all client risk analyses. Each analysis is based on CASES model of monarc_common.
124+
125+
## 4.3 Initialize the database
126+
127+
```bash
128+
cd /var/lib/monarc/fo
129+
mysql -u monarc -ppassword monarc_common < db-bootstrap/monarc_structure.sql
130+
mysql -u monarc -ppassword monarc_common < db-bootstrap/monarc_data.sql
131+
```
132+
133+
## 4.4 Connect Monarc App to the database
134+
135+
Create and edit the configuration file:
136+
137+
```bash
138+
sudo cp ./config/autoload/local.php.dist ./config/autoload/local.php
139+
sudo nano ./config/autoload/local.php
140+
```
141+
142+
Configure the database connection (use the secured password set on the DB user creation step):
143+
144+
```php
145+
return [
146+
'doctrine' => [
147+
'connection' => [
148+
'orm_default' => [
149+
'params' => [
150+
'host' => 'localhost',
151+
'user' => 'monarc',
152+
'password' => 'password',
153+
'dbname' => 'monarc_common',
154+
],
155+
],
156+
'orm_cli' => [
157+
'params' => [
158+
'host' => 'localhost',
159+
'user' => 'monarc',
160+
'password' => 'password',
161+
'dbname' => 'monarc_cli',
162+
],
163+
],
164+
],
165+
],
166+
];
167+
```
168+
169+
## 4.5 Migrate the MONARC DB
170+
171+
```bash
172+
bash ./scripts/upgrade-db.sh
173+
```
174+
175+
## 4.6 Create initial user
176+
177+
```bash
178+
php ./vendor/robmorgan/phinx/bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php
179+
```
180+
181+
The username is *admin@admin.localhost* and the password is *admin*.
182+
183+
184+
# 5. Statistics for Global Dashboard
185+
186+
If you would like to use the global dashboard stats feature, you need to
187+
configure a Stats Service instance on your server.
188+
189+
The architecture, installation instructions and GitHub project can be found here:
190+
191+
- https://www.monarc.lu/documentation/stats-service/master/architecture.html
192+
- https://www.monarc.lu/documentation/stats-service/master/installation.html
193+
- https://github.com/monarc-project/stats-service
194+
195+
The Virtual Machine installation script could be used to detail more steps in case of additional configuration necessity:
196+
https://github.com/monarc-project/monarc-packer/blob/ubuntu-22.04/scripts/bootstrap.sh
197+
198+
The communication of access to the StatsService is performed on each instance of
199+
FrontOffice (clients).

INSTALL/UPDATE.ubuntu.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ curl -sL $MONARCFO_RELEASE_URL -o /var/lib/monarc/releases/`basename $MONARCFO_R
1919
mkdir /var/lib/monarc/releases/`basename $MONARCFO_RELEASE_URL | sed 's/.tar.gz//'`
2020
# Unarchive the release:
2121
tar -xzf /var/lib/monarc/releases/`basename $MONARCFO_RELEASE_URL` -C /var/lib/monarc/releases/`basename $MONARCFO_RELEASE_URL | sed 's/.tar.gz//'`
22+
# Copy existing configuration to the new release.
23+
cp "$PATH_TO_MONARC/config/autoload/local.php" \
24+
"/var/lib/monarc/releases/`basename $MONARCFO_RELEASE_URL | sed 's/.tar.gz//'`/config/autoload/local.php"
2225
# Update the release symlink:
2326
ln -sfn /var/lib/monarc/releases/`basename $MONARCFO_RELEASE_URL | sed 's/.tar.gz//'` $PATH_TO_MONARC
2427
# Migrate the DB:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
BASEDIR="/var/lib/monarc"
5+
RELEASES="$BASEDIR/releases"
6+
APP_LINK="$BASEDIR/fo"
7+
DATA_DIR="$BASEDIR/fo-data"
8+
9+
function error() { echo "Error: $1" > /dev/stderr; exit 1; }
10+
11+
# ensure no existing release is present
12+
if [ -f "$APP_LINK/config/autoload/local.php" ]; then
13+
echo "Existing Monarc installation found! Run the UPDATE script instead:";
14+
echo " https://github.com/monarc-project/MonarcAppFO/blob/master/INSTALL/UPDATE.ubuntu.md";
15+
error "Aborting installation.";
16+
fi
17+
18+
# Ensure base directories exist
19+
mkdir -p "$RELEASES" "$DATA_DIR"/{cache,DoctrineORMModule/Proxy,LazyServices/Proxy,import/files}
20+
21+
# Get latest version
22+
VERSION=$(curl -s https://api.github.com/repos/monarc-project/MonarcAppFO/releases/latest | jq -r '.tag_name')
23+
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
24+
error "Failed to resolve app release version"
25+
fi
26+
RELEASE_NAME="MonarcAppFO-${VERSION}"
27+
ARCHIVE_URL="https://github.com/monarc-project/MonarcAppFO/releases/download/${VERSION}/${RELEASE_NAME}.tar.gz"
28+
29+
# Extraction target
30+
TARGET_DIR="$RELEASES/$RELEASE_NAME"
31+
test -d "$TARGET_DIR" && error "$TARGET_DIR already exists!"
32+
mkdir -p "$TARGET_DIR"
33+
34+
echo "Downloading the latest Monarc version $VERSION"
35+
# --strip-components=1 prevents the "folder inside a folder" issue
36+
curl -L "$ARCHIVE_URL" | tar -xzf - -C "$TARGET_DIR" --strip-components=1
37+
38+
# if data folder exist in release - remove it to allow symlink
39+
rm -rf "$TARGET_DIR/data"
40+
# Link data folder into release folder
41+
ln -sfn "$DATA_DIR" "$TARGET_DIR/data"
42+
43+
# Link the release into the app folder
44+
ln -sfn "$TARGET_DIR" "$APP_LINK"
45+
46+
# change owner
47+
chown -R www-data:www-data /var/lib/monarc
48+
49+
echo "Monarc version $VERSION files was installed successfully!"
50+
echo "No database or web-server configuration changes were made."
51+
echo "Follow the installation instruction for the next steps."

0 commit comments

Comments
 (0)