Both sides previous revisionPrevious revisionNext revision | Previous revision |
servers:linux:nginx:friendica [2025/09/11 16:37] – Seems fine without test Sean Rhone | servers:linux:nginx:friendica [2025/10/17 01:56] (current) – [Etc] Sean Rhone |
---|
* [[information:realm_of_espionage|Realm of Espionage]] | * [[information:realm_of_espionage|Realm of Espionage]] |
* https://social.realmofespionage.xyz | * https://social.realmofespionage.xyz |
| |
| ===== Resources ===== |
| |
| * https://wiki.friendi.ca/docs/bbcode |
| |
===== Prerequisites ===== | ===== Prerequisites ===== |
* https://wiki.friendi.ca/docs/install#requirements | * https://wiki.friendi.ca/docs/install#requirements |
| |
sudo zypper install php-composer2 php8-curl php-gd php8-gmp php8-pdo php8-mbstring php8-intl php8-mysql php8-zip php8-openssl php8-posix | sudo zypper install php-composer2 php8-curl php-gd php8-gmp php8-pdo php8-mbstring php8-intl php8-mysql php8-zip php8-openssl php8-fileinfo php8-posix |
| |
====== Download Source ====== | ====== Download Source ====== |
| |
* https://github.com/friendica/friendica-addons/commits/develop/ | * https://github.com/friendica/friendica-addons/commits/develop/ |
* Required for ''composer install'' | * :!: Required for ''composer install'' even without any addons enabled |
| |
sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica-addons.git' '/srv/www/social/addon' && sudo chown -R 'wwwrun':'www' '/srv/www/social/addon' && sudo chmod -R '0755' '/srv/www/social/addon' | sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica-addons.git' '/srv/www/social/addon' && sudo chown -R 'wwwrun':'www' '/srv/www/social/addon' && sudo chmod -R '0755' '/srv/www/social/addon' |
GRANT ALL PRIVILEGES ON friendica.* to 'friendica'@'localhost'; | GRANT ALL PRIVILEGES ON friendica.* to 'friendica'@'localhost'; |
| |
FLUSH PRIVILEGES; | FLUSH PRIVILEGES;EXIT; |
| |
EXIT | |
| |
====== nginx + PHP-FPM Configuration ====== | ====== nginx + PHP-FPM Configuration ====== |
| |
nano '/srv/www/social/config/local.config.php' | nano '/srv/www/social/config/local.config.php' |
| |
| exit |
| |
====== Settings ====== | ====== Settings ====== |
==== Timer ==== | ==== Timer ==== |
| |
* Every 10 minutes | * Every 10 minutes (([[https://wiki.friendi.ca/docs/install#required_background_tasks|info]])) |
| |
sudo -e '/etc/systemd/system/social-d.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-d.timer' --now && sudo systemctl start 'social-d' && sudo systemctl status 'social-d' -l | sudo -e '/etc/systemd/system/social-d.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-d.timer' --now && sudo systemctl start 'social-d' && sudo systemctl status 'social-d' -l |
Type=oneshot | Type=oneshot |
| |
| WorkingDirectory=/srv/www/social |
Environment="COMPOSER_CACHE_DIR=/dev/null" | Environment="COMPOSER_CACHE_DIR=/dev/null" |
| |
| |
ExecStart='/usr/bin/composer' --working-dir='/srv/www/social' --no-cache install --no-dev | ExecStart='/usr/bin/composer' --working-dir='/srv/www/social' --no-cache install --no-dev |
| |
| ExecStart='/usr/bin/php' '/srv/www/social/bin/console.php' dbstructure update --force |
| ExecStart='/usr/bin/php' '/srv/www/social/bin/console.php' dbstructure drop --execute |
| ExecStart='/usr/bin/php' '/srv/www/social/bin/console.php' postupdate |
| ExecStart='/usr/bin/php' '/srv/www/social/bin/console.php' cache clear |
| ExecStart='/usr/bin/php' '/srv/www/social/bin/console.php' clearavatarcache |
| |
ExecStartPost='/usr/bin/sync' | ExecStartPost='/usr/bin/sync' |
# End</code> | # End</code> |
| |
===== Maintenance ===== | ===== Backup ===== |
| |
==== Service ==== | ==== Files ==== |
| |
sudo -e '/etc/systemd/system/social-m.service' | === Service === |
| |
| mkdir -p ~/'backups' && sudo -e '/etc/systemd/system/social-fb.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/social-fb.service' |
| |
<code> | <code> |
[Service] | [Service] |
User=nginx | |
Group=nginx | |
Type=oneshot | Type=oneshot |
ExecStart='/usr/bin/git' -C '/var/www/social' gc --aggressive --prune='all' | |
ExecStart='/usr/bin/git' -C '/var/www/social' fsck --full --strict | |
ExecStart='/usr/bin/git' -C '/var/www/social/addon' gc --aggressive --prune='all' | |
ExecStart='/usr/bin/git' -C '/var/www/social/addon' fsck --full --strict | |
ExecStartPost='/usr/bin/sync'</code> | |
| |
==== Timer ==== | ExecStart='/usr/bin/bash' -c '"/usr/bin/tar" -czf "/home/CHANGEME/backups/friendica-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" -C "/srv/www" "social"' |
| |
* ''01'' day of every month at ''03:20:00'' | ExecStartPost='/usr/bin/sync' |
| |
| # End</code> |
| |
| === Timer === |
| |
| * ''01'' day of every month at ''04:15:00'' |
| |
sudo -e '/etc/systemd/system/social-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-m.timer' --now && sudo systemctl start 'social-m' && sudo systemctl status 'social-up' -l | sudo -e '/etc/systemd/system/social-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-fb.timer' --now |
| |
<code> | <code> |
[Unit] | [Unit] |
Description=friendica Maintenance | Description=Friendica Files Backup |
After=network-online.target | |
Wants=network-online.target | |
| |
[Timer] | [Timer] |
OnCalendar=*-*-01 03:20:00 | OnCalendar=*-*-01 04:15:00 |
Persistent=true | Persistent=true |
| |
[Install] | [Install] |
WantedBy=timers.target</code> | WantedBy=timers.target |
| |
===== Backup ===== | # End</code> |
| |
==== Files ==== | sudo systemctl start 'social-fb' && sudo systemctl status 'social-fb' -l |
| |
| ==== Database ==== |
| |
| === Database Auth === |
| |
| sudo mkdir -p '/var/lib/mysql/auth' && sudo -e '/var/lib/mysql/auth/friendica' && sudo chown 'mysql':'mysql' '/var/lib/mysql/auth/friendica' && sudo chmod '0600' '/var/lib/mysql/auth/friendica' |
| |
| <code> |
| [mariadb-dump] |
| user=friendica |
| password=x |
| |
| # End</code> |
| |
=== Service === | === Service === |
| |
mkdir -p ~/'backups' && sudo -e '/etc/systemd/system/social-fb.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/social-fb.service' | mkdir -p ~/'backups' && sudo mkdir -p '/var/lib/mysql/tmp' && sudo -e '/etc/systemd/system/social-db.service' && sudo sed -i 's/'CHANGEME'/'$USER'/g' '/etc/systemd/system/social-db.service' |
| |
<code> | <code> |
[Service] | [Service] |
| Group=mysql |
Type=oneshot | Type=oneshot |
WorkingDirectory=/var/www | |
ExecStart='/usr/bin/bash' -c '"/usr/bin/tar" -czf "/home/CHANGEME/backups/friendica-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "social"' | ExecStart='/usr/bin/bash' -c '"/usr/bin/mariadb-dump" --defaults-extra-file="/var/lib/mysql/auth/friendica" --single-transaction --quick "friendica" -r "/home/CHANGEME/backups/friendica-database-auto-"$$(date +%%Y-%%m-%%d)".sql"' |
ExecStartPost='/usr/bin/sync'</code> | |
| ExecStartPost='/usr/bin/sync' |
| |
| # End</code> |
| |
=== Timer === | === Timer === |
| |
* ''01'' day of every month at ''03:35:00'' | * ''01'' day of every month at ''04:10:00'' |
| |
sudo -e '/etc/systemd/system/social-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-fb.timer' --now && sudo systemctl start 'social-fb' && sudo systemctl status 'social-fb' -l | sudo -e '/etc/systemd/system/social-db.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-db.timer' --now && sudo systemctl start 'social-db' && sudo systemctl status 'social-db' -l |
| |
<code> | <code> |
[Unit] | [Unit] |
Description=friendica Files Backup | Description=Friendica Database Backup |
| After=mariadb.service |
| |
[Timer] | [Timer] |
OnCalendar=*-*-01 03:35:00 | OnCalendar=*-*-01 04:10:00 |
Persistent=true | Persistent=true |
| |
[Install] | [Install] |
WantedBy=timers.target</code> | WantedBy=timers.target |
| |
==== Database ==== | # End</code> |
| |
=== Database Auth === | ===== Maintenance ===== |
| |
sudo mkdir -p '/var/lib/mysql/auth' && sudo -e '/var/lib/mysql/auth/friendica' && sudo chown -R 'mysql':'mysql' '/var/lib/mysql/auth/friendica' && sudo chmod '600' '/var/lib/mysql/auth/friendica' && sync | ==== Service ==== |
| |
<code> | sudo -e '/etc/systemd/system/social-m.service' |
[mariadb-dump] | |
user=friendica | |
password=x</code> | |
| |
=== Service === | |
| |
mkdir -p ~/'backups' && sudo mkdir -p '/var/lib/mysql/tmp' && sudo -e '/etc/systemd/system/social-db.service' && sudo sed -i 's/'CHANGEME'/'$USER'/g' '/etc/systemd/system/social-db.service' | |
| |
<code> | <code> |
[Service] | [Service] |
| User=wwwrun |
| Group=www |
Type=oneshot | Type=oneshot |
WorkingDirectory=/var/lib/mysql/tmp | |
ExecStartPre='/usr/bin/mariadb-dump' --defaults-extra-file='/var/lib/mysql/auth/friendica' --single-transaction 'friendica' -r '/var/lib/mysql/tmp/friendica.sql' | |
ExecStart='/usr/bin/gzip' -f '/var/lib/mysql/tmp/friendica.sql' | |
ExecStart='/usr/bin/bash' -c '"/usr/bin/mv" "/var/lib/mysql/tmp/friendica.sql.gz" "/home/CHANGEME/backups/friendica-database-auto-"$$(date +%%Y-%%m-%%d)".sql.gz"' | |
ExecStartPost='/usr/bin/sync'</code> | |
| |
=== Timer === | ExecStart='/usr/bin/git' -C '/srv/www/social' reset --hard |
| ExecStart='/usr/bin/git' -C '/srv/www/social' gc --aggressive --prune='all' |
| ExecStart='/usr/bin/git' -C '/srv/www/social' fsck --full --strict |
| |
* Every day at ''03:45:00'' | ExecStart='/usr/bin/git' -C '/srv/www/social/addon' reset --hard |
| ExecStart='/usr/bin/git' -C '/srv/www/social/addon' gc --aggressive --prune='all' |
| ExecStart='/usr/bin/git' -C '/srv/www/social/addon' fsck --full --strict |
| |
sudo -e '/etc/systemd/system/social-db.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-db.timer' --now && sudo systemctl start 'social-db' && sudo systemctl status 'social-db' -l | ExecStartPost='/usr/bin/sync' |
| |
| # End</code> |
| |
| ==== Timer ==== |
| |
| * ''01'' day of every month at ''04:30:00'' |
| |
| sudo -e '/etc/systemd/system/social-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-m.timer' --now |
| |
<code> | <code> |
[Unit] | [Unit] |
Description=friendica Database Backup | Description=Friendica Maintenance |
After=mariadb.service | After=network-online.target |
| Wants=network-online.target |
| |
[Timer] | [Timer] |
OnCalendar=*-*-* 03:45:00 | OnCalendar=*-*-01 04:30:00 |
Persistent=true | Persistent=true |
| |
[Install] | [Install] |
WantedBy=timers.target</code> | WantedBy=timers.target |
| |
====== Backup ====== | # End</code> |
| |
* Create backup archive on server and transfer to client computer | sudo systemctl start 'social-m' && sudo systemctl status 'social-m' -l |
| |
===== Server ===== | ====== Backup ====== |
| |
==== Stop Services ==== | ===== Files ===== |
| |
**** | **** |
| |
sudo systemctl stop nginx php-fpm | sudo tar -czf ~/'friendica-files-manual-'$(date +%Y-%m-%d)'.tar.gz' -C '/srv/www' 'social' |
| |
==== Backup Folder ==== | ===== Database ===== |
| |
**** | **** |
| |
cd '/var/www' && sudo tar -cvzf ~/'friendica-files-manual-'$(date +%Y-%m-%d)'.tar.gz' 'social' && cd ~ && sync | sudo mariadb-dump --single-transaction --quick 'friendica' -r ~/'friendica-database-manual-'$(date +%Y-%m-%d)'.sql' |
| |
==== Backup Database ==== | ===== scp ===== |
| |
**** | scp espionage724@192.168.1.152:~/'friendica-files-'*'.tar.gz' ~/'Downloads' |
| |
sudo mariadb-dump --defaults-extra-file='/var/lib/mysql/auth/friendica' --single-transaction 'friendica' -r ~/'friendica-database-manual-'$(date +%Y-%m-%d)'.sql' && sync | scp espionage724@192.168.1.152:~/'friendica-database-'*'.sql' ~/'Downloads' |
| |
==== Start Services ==== | ====== Restore ====== |
| |
**** | ===== scp ===== |
| |
sudo systemctl start nginx php-fpm | scp ~/'Downloads/friendica-files-'*'.tar.gz' espionage724@192.168.1.152:~ |
| |
===== Client ===== | scp ~/'Downloads/friendica'*'.sql' espionage724@192.168.1.152:~ |
| |
==== Transfer Files To Client ==== | ===== Stop nginx ===== |
| |
**** | **** |
| |
scp espionage724@192.168.1.152:~/'friendica-files-'*'.tar.gz' espionage724@192.168.1.152:~/'friendica-database-'*'.sql' ~/'Downloads' && sync | sudo systemctl stop 'nginx' |
| |
====== Restore ====== | ===== Remove Existing Files ===== |
| |
===== Client ===== | **** |
| |
==== Uncompress Database ==== | ls ~/'friendica-files-'*'.tar.gz' && sudo rm -Rf '/srv/www/social' |
| |
* This is only needed if restoring an **automated** database backup ((manual doesn't gzip)) | ===== Restore Files ===== |
| |
gunzip ~/'Downloads/friendica-database-'*'.sql.gz' | **** |
| |
==== Transfer Files To Server ==== | sudo tar -xzf ~/'friendica-files-'*'.tar.gz' -C '/srv/www' 'social' && sudo chown -R 'wwwrun':'www' '/srv/www/social' && sudo chmod -R '0755' '/srv/www/social' |
| |
**** | ===== Git Fix ===== |
| |
scp ~/'Downloads/friendica-files-'*'.tar.gz' ~/'Downloads/friendica-database-'*'.sql' espionage724@192.168.1.152:~ | * :!: Set email for ''user.email'' |
| * :!: Requires [[#etc|Etc]] commands afterwards ((https://social.realmofespionage.xyz doesn't redirect to single-profile URL and shows an error)) |
| |
==== Remove Files ==== | sudo su 'wwwrun' -s '/bin/bash' |
| |
**** | rm -Rf '/srv/www/social/.git' |
| |
rm -f ~/'Downloads/friendica-files-'*'.tar.gz' ~/'Downloads/friendica-database-'*'.sql' && sync | git -C '/srv/www/social' init --initial-branch='develop' |
| |
===== Server ===== | git -C '/srv/www/social' add '.' |
| |
==== Stop Services ==== | git -C '/srv/www/social' config 'user.email' 'espionage724@x' |
| |
**** | git -C '/srv/www/social' commit --message='x' |
| |
sudo systemctl stop nginx php-fpm | git -C '/srv/www/social' remote add 'origin' 'https://github.com/friendica/friendica.git' |
| |
==== Remove Previous Folder ==== | git -C '/srv/www/social' pull --depth '1' --recurse-submodules 'origin' 'develop' --rebase |
| |
**** | git -C '/srv/www/social' reset --hard 'origin/develop' |
| |
sudo rm -Rf '/var/www/social' | git -C '/srv/www/social' gc --aggressive --prune='all' |
| |
==== Restore Friendica Folder ==== | git -C '/srv/www/social' fsck --full --strict |
| |
**** | ==== Addons ==== |
| |
cd '/var/www' && sudo tar -xvzf ~/'friendica-files-'*'.tar.gz' 'social' && sudo semanage fcontext --add --type 'httpd_sys_rw_content_t' '/var/www/social(/.*)?' && sudo restorecon -F -I -R '/var/www/social' && sudo chown -R 'nginx':'nginx' '/var/www/social' && cd ~ && sync | * :!: Set email for ''user.email'' |
| |
==== Drop Previous Database ==== | rm -Rf '/srv/www/social/addon/.git' |
| |
sudo mariadb | git -C '/srv/www/social/addon' init --initial-branch='develop' |
| |
DROP DATABASE friendica; | git -C '/srv/www/social/addon' add '.' |
| |
FLUSH TABLES; | git -C '/srv/www/social/addon' config 'user.email' 'espionage724@x' |
| |
EXIT | git -C '/srv/www/social/addon' commit --message='x' |
| |
==== Re-create Databases ==== | git -C '/srv/www/social/addon' remote add 'origin' 'https://github.com/friendica/friendica-addons.git' |
| |
sudo mariadb | git -C '/srv/www/social/addon' pull --depth '1' --recurse-submodules 'origin' 'develop' --rebase |
| |
CREATE DATABASE friendica; | git -C '/srv/www/social/addon' reset --hard 'origin/develop' |
| |
EXIT | git -C '/srv/www/social/addon' gc --aggressive --prune='all' |
| |
==== Restore Database ==== | git -C '/srv/www/social/addon' fsck --full --strict |
| |
**** | exit |
| |
sudo mariadb 'friendica' < ~/'friendica-database-'*'.sql' && sync | ===== Database Connection ===== |
| |
==== Reapply Permissions ==== | sudo -e '/srv/www/social/config/local.config.php' && sudo chown -v 'wwwrun':'www' '/srv/www/social/config/local.config.php' |
| |
sudo mariadb | <code> |
| 'database' => [ |
| 'hostname' => 'localhost',</code> |
| |
GRANT ALL PRIVILEGES ON friendica.* to 'friendica'@'localhost' IDENTIFIED BY 'x'; | <code> |
| 'system' => [ |
| 'basepath' => '/srv/www/social',</code> |
| |
| ===== Restore Database ===== |
| |
| * [[#database|Initial set-up]] |
| |
FLUSH PRIVILEGES; | sudo mariadb --execute='DROP DATABASE friendica;' |
| |
EXIT | sudo mariadb --execute='CREATE DATABASE friendica;' |
| |
==== Start Services ==== | sudo mariadb 'friendica' < ~/'friendica'*'.sql' |
| |
| ===== Start nginx ===== |
| |
**** | **** |
| |
sudo systemctl start nginx php-fpm | sudo systemctl start 'nginx' |
| |
==== Remove Backups ==== | ===== Clean-up ===== |
| |
* Verify that Friendica works before running | **** |
| |
rm ~/'friendica-files-'*'.tar.gz' ~/'friendica-database-'*'.sql' && sync | rm -fv ~/'friendica-files-'*'.tar.gz' ~/'friendica'*'.sql' |
| |