Both sides previous revisionPrevious revisionNext revision | Previous revision |
servers:nginx:friendica [2023/09/01 18:00] – Sean Rhone | servers:nginx:friendica [2024/02/01 08:29] (current) – Sean Rhone |
---|
===== Prerequisites ===== | ===== Prerequisites ===== |
| |
* [[distros:opensuse_tumbleweed_server|openSUSE Tumbleweed]] | * [[distros:fedora_server|Fedora Server]] |
* [[servers:mariadb|MariaDB]] | * [[servers:mariadb|MariaDB]] |
* [[servers:nginx_php_php-fpm|nginx + PHP + PHP-FPM]] | * [[servers:nginx_php_php-fpm|nginx + PHP + PHP-FPM]] |
====== Dependencies ====== | ====== Dependencies ====== |
| |
**** | * https://friendi.ca/resources/requirements/ |
| |
sudo zypper install php8-posix php8-gmp | sudo dnf install php-gd php-pdo php-mbstring php-mysqlnd php-xml php-pecl-zip php-process php-gmp php-pecl-xdebug3 |
| |
====== Download Source ====== | ====== Download Source ====== |
**** | **** |
| |
sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica.git' '/srv/www/social' && sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica-addons.git' '/srv/www/social/addon' && sudo chown -R 'nginx':'nginx' '/srv/www/social' && sync | sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica.git' '/var/www/social' && sudo git clone --branch 'develop' --depth '1' --recurse-submodules 'https://github.com/friendica/friendica-addons.git' '/var/www/social/addon' && 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' && sync |
| |
====== PHP Dependencies ====== | ====== PHP Dependencies ====== |
| |
| * [[https://github.com/friendica/friendica/blob/develop/doc/Install.md|Install.md]] when mentioning the ''develop'' branch doesn't include ''--no-dev'', so presumably those packages are needed? |
| |
sudo su 'nginx' -s '/bin/bash' | sudo su 'nginx' -s '/bin/bash' |
| |
cd '/srv/www/social' && COMPOSER_CACHE_DIR='/dev/null' '/srv/www/social/bin/composer.phar' install --no-dev && sync | cd '/var/www/social' && COMPOSER_CACHE_DIR='/dev/null' php '/var/www/social/bin/composer.phar' install && sync |
| |
====== Database ====== | ====== Database ====== |
| |
sudo mysql | sudo mariadb |
| |
CREATE DATABASE friendica; | CREATE DATABASE friendica; |
===== PHP-FPM Socket ===== | ===== PHP-FPM Socket ===== |
| |
sudo -e '/etc/php8/fpm/php-fpm.d/social.conf' && sudo systemctl restart 'php-fpm' | sudo -e '/etc/php-fpm.d/social.conf' && sudo systemctl restart 'php-fpm' |
| |
<code> | <code> |
| |
; Socket | ; Socket |
listen = 127.0.0.1:9005 | listen = /run/php-fpm/social.sock |
listen.acl_users = nginx | listen.acl_users = nginx |
listen.allowed_clients = 127.0.0.1 | listen.allowed_clients = 127.0.0.1 |
pm.process_idle_timeout = 30 | pm.process_idle_timeout = 30 |
| |
; openSUSE TW php.ini Defaults | ; Fedora php.ini Defaults |
php_value[session.save_path] = /var/lib/php8/sessions | php_value[session.save_handler] = "files" |
| php_value[session.save_path] = "/var/lib/php/session" |
| |
; General | ; General |
php_value[upload_max_filesize] = "10M" | php_value[upload_max_filesize] = "10M" |
php_value[max_file_uploads] = "100" | php_value[max_file_uploads] = "100" |
| php_value[register_argc_argv] = "On" |
| php_value[upload_tmp_dir] = "/tmp" |
| |
; End</code> | ; End</code> |
location ~ \.(php|phar)(/.*)?$ { | location ~ \.(php|phar)(/.*)?$ { |
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$; | fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$; |
| |
fastcgi_intercept_errors on; | fastcgi_intercept_errors on; |
fastcgi_index index.php; | fastcgi_index index.php; |
include fastcgi_params; | include fastcgi_params; |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
fastcgi_param PATH_INFO $fastcgi_path_info; | fastcgi_param PATH_INFO $fastcgi_path_info; |
fastcgi_pass 127.0.0.1:9005; | fastcgi_pass unix:/run/php-fpm/social.sock; |
| }</code> |
| |
| ==== Test ==== |
| |
| <code> |
| # PHP-FPM |
| location ~* \.php$ { |
| # fastcgi_intercept_errors on; |
| # fastcgi_param PATH_INFO $fastcgi_path_info; |
| fastcgi_pass unix:/run/php-fpm/social.sock; |
| fastcgi_buffers 8 16k; |
| fastcgi_buffer_size 32k; |
| fastcgi_connect_timeout 60; |
| fastcgi_send_timeout 300; |
| fastcgi_read_timeout 300; |
| fastcgi_split_path_info ^(.+?\.php)(/.*)$; |
| try_files $uri =404; |
| fastcgi_index index.php; |
| include fastcgi_params; |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
}</code> | }</code> |
| |
===== Server Block ===== | ===== Server Block ===== |
| |
| * 2023/09/12: CSPs disabled; TODO: Re-figure out CSPs |
| |
sudo -e '/etc/nginx/vhosts.d/social.conf' && sudo systemctl reload 'nginx' && sync | sudo -e '/etc/nginx/vhosts.d/social.conf' && sudo systemctl reload 'nginx' && sync |
listen '443' 'ssl' 'http2'; | listen '443' 'ssl' 'http2'; |
server_name 'social.realmofespionage.xyz'; | server_name 'social.realmofespionage.xyz'; |
root '/srv/www/social'; | root '/var/www/social'; |
index 'index.php'; | index 'index.php'; |
| |
client_max_body_size '10M'; | client_max_body_size '10M'; |
| |
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' blob:" always; | # add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' blob:" always; |
| |
# access_log /var/log/nginx/social-access.log; | # access_log /var/log/nginx/social-access.log; |
====== Initial Setup ====== | ====== Initial Setup ====== |
| |
| ===== Initialize ===== |
| |
sudo cp --force '/srv/www/social/config/local-sample.config.php' '/srv/www/social/config/local.config.php' && sudo -e '/srv/www/social/config/local.config.php' && sudo chown 'nginx':'nginx' '/srv/www/social/config/local-sample.config.php' && sync | * :!: Change ''dbpass'', and ''admin'' to email |
| |
| sudo su 'nginx' -s '/bin/bash' |
| |
| cd '/var/www/social/' && '/var/www/social/bin/console' autoinstall --dbhost 'localhost' --dbport '3365' --dbuser 'friendica' --dbdata 'friendica' --url 'https://social.realmofespionage.xyz' --dbpass 'x' --admin 'x' |
| |
===== Website ===== | ===== Website ===== |
| |
* https://social.realmofespionage.xyz | * https://social.realmofespionage.xyz |
| * :!: Be sure the email matches what was used on the above command |
| |
| ===== User ===== |
| |
| * :!: ''x'' is the **nickname** chosen at website registration, lower-case |
| |
| sudo su 'nginx' -s '/bin/bash' |
| |
| cd '/var/www/social/' && '/var/www/social/bin/console' user password x |
| |
| ====== Settings ====== |
| |
| ===== frio Theme ===== |
| |
| * Navigation bar background color: ''3d8bff'' |
| * Navigation bar icon color: ''ffffff'' |
| * Link color: ''3d8bff'' |
| * Set the background color: ''dedede'' |
| * Login page background color: ''484848'' |
| |
| * Copy or paste schemestring: |
| |
| <code>{"nav_bg":"#3d8bff","nav_icon_color":"#ffffff","link_color":"#3d8bff","background_color":"#dedede","background_image":"","contentbg_transp":"100","login_bg_image":"","login_bg_color":"#484848"}</code> |
| |
====== Services ====== | ====== Services ====== |
Group=nginx | Group=nginx |
Type=oneshot | Type=oneshot |
WorkingDirectory=/srv/www/social | WorkingDirectory=/var/www/social |
ExecStart='/usr/bin/php' '/srv/www/social/bin/worker.php' | ExecStart='/usr/bin/php' '/var/www/social/bin/worker.php' |
ExecStartPost='/usr/bin/sync'</code> | ExecStartPost='/usr/bin/sync'</code> |
| |
* Every 5 minutes | * Every 5 minutes |
| |
sudo -e '/etc/systemd/system/social-d.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-d.timer' --now | 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 |
| |
<code> | <code> |
Group=nginx | Group=nginx |
Type=oneshot | Type=oneshot |
WorkingDirectory=/srv/www/social | WorkingDirectory=/var/www/social |
Environment="COMPOSER_CACHE_DIR=/dev/null" | Environment="COMPOSER_CACHE_DIR=/dev/null" |
ExecStart='/usr/bin/git' -C '/srv/www/social' pull origin 'develop' | ExecStart='/usr/bin/git' -C '/var/www/social' pull origin 'develop' |
ExecStart='/usr/bin/git' -C '/srv/www/social/addon' pull origin 'develop' | ExecStart='/usr/bin/git' -C '/var/www/social/addon' pull origin 'develop' |
ExecStart='/srv/www/social/bin/composer.phar' install --no-dev | ExecStart='/usr/bin/php' '/var/www/social/bin/composer.phar' install |
ExecStartPost='/usr/bin/sync'</code> | ExecStartPost='/usr/bin/sync'</code> |
| |
==== Timer ==== | ==== Timer ==== |
| |
* Every day at ''02:00:00'' | * Every day at ''03:00:00'' |
| |
sudo -e '/etc/systemd/system/social-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-up.timer' --now && sudo systemctl start 'social-up' && sudo systemctl status 'social-up' -l | sudo -e '/etc/systemd/system/social-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-up.timer' --now && sudo systemctl start 'social-up' && sudo systemctl status 'social-up' -l |
| |
[Timer] | [Timer] |
OnCalendar=*-*-* 02:00:00 | OnCalendar=*-*-* 03:00:00 |
Persistent=true | Persistent=true |
| |
Group=nginx | Group=nginx |
Type=oneshot | Type=oneshot |
ExecStart='/usr/bin/git' -C '/srv/www/social' gc --aggressive --prune='all' | ExecStart='/usr/bin/git' -C '/var/www/social' gc --aggressive --prune='all' |
ExecStart='/usr/bin/git' -C '/srv/www/social' fsck --full --strict | ExecStart='/usr/bin/git' -C '/var/www/social' fsck --full --strict |
ExecStart='/usr/bin/git' -C '/srv/www/social/addon' gc --aggressive --prune='all' | ExecStart='/usr/bin/git' -C '/var/www/social/addon' gc --aggressive --prune='all' |
ExecStart='/usr/bin/git' -C '/srv/www/social/addon' fsck --full --strict | ExecStart='/usr/bin/git' -C '/var/www/social/addon' fsck --full --strict |
ExecStartPost='/usr/bin/sync'</code> | ExecStartPost='/usr/bin/sync'</code> |
| |
==== Timer ==== | ==== Timer ==== |
| |
* ''01'' day of every month at ''02:20:00'' | * ''01'' day of every month at ''03:20:00'' |
| |
sudo -e '/etc/systemd/system/social-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-m.timer' --now | 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 |
| |
<code> | <code> |
| |
[Timer] | [Timer] |
OnCalendar=*-*-01 02:20:00 | OnCalendar=*-*-01 03:20:00 |
Persistent=true | Persistent=true |
| |
[Service] | [Service] |
Type=oneshot | Type=oneshot |
WorkingDirectory=/srv/www | 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/tar" -czf "/home/CHANGEME/backups/friendica-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "social"' |
ExecStartPost='/usr/bin/sync'</code> | ExecStartPost='/usr/bin/sync'</code> |
=== Timer === | === Timer === |
| |
* ''01'' day of every month at ''02:50:00'' | * ''01'' day of every month at ''03:35: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-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'social-fb.timer' --now && sudo systemctl start 'social-fb' && sudo systemctl status 'social-fb' -l |
| |
[Timer] | [Timer] |
OnCalendar=*-*-01 02:50:00 | OnCalendar=*-*-01 03:35:00 |
Persistent=true | Persistent=true |
| |
| |
<code> | <code> |
[mysqldump] | [mariadb-dump] |
user=friendica | user=friendica |
password=x</code> | password=x</code> |
Type=oneshot | Type=oneshot |
WorkingDirectory=/var/lib/mysql/tmp | WorkingDirectory=/var/lib/mysql/tmp |
ExecStartPre='/usr/bin/mysqldump' --defaults-extra-file='/var/lib/mysql/auth/friendica' --single-transaction 'friendica' -r '/var/lib/mysql/tmp/friendica.sql' | 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/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"' | 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"' |
=== Timer === | === Timer === |
| |
* Every day at ''02:15:00'' | * Every day at ''03:45:00'' |
| |
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 | 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 |
| |
[Timer] | [Timer] |
OnCalendar=*-*-* 02:15:00 | OnCalendar=*-*-* 03:45:00 |
Persistent=true | Persistent=true |
| |
**** | **** |
| |
cd '/srv/www' && sudo tar -cvzf ~/'friendica-files-manual-'$(date +%Y-%m-%d)'.tar.gz' 'social' && cd ~ && sync | cd '/var/www' && sudo tar -cvzf ~/'friendica-files-manual-'$(date +%Y-%m-%d)'.tar.gz' 'social' && cd ~ && sync |
| |
==== Backup Database ==== | ==== Backup Database ==== |
**** | **** |
| |
sudo mysqldump --defaults-extra-file='/var/lib/mysql/auth/friendica' --single-transaction 'friendica' -r ~/'friendica-database-manual-'$(date +%Y-%m-%d)'.sql' && sync | sudo mariadb-dump --defaults-extra-file='/var/lib/mysql/auth/friendica' --single-transaction 'friendica' -r ~/'friendica-database-manual-'$(date +%Y-%m-%d)'.sql' && sync |
| |
==== Start Services ==== | ==== Start Services ==== |
**** | **** |
| |
sudo rm -Rf '/srv/www/social' | sudo rm -Rf '/var/www/social' |
| |
==== Restore friendica Folder ==== | ==== Restore Friendica Folder ==== |
| |
**** | **** |
| |
cd '/srv/www' && sudo tar -xvzf ~/'friendica-files-'*'.tar.gz' 'social' && sudo chown -R 'nginx':'nginx' '/srv/www/social' && cd ~ && sync | 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 |
| |
==== Drop Previous Database ==== | ==== Drop Previous Database ==== |
| |
sudo mysql | sudo mariadb |
| |
DROP DATABASE friendica; | DROP DATABASE friendica; |
==== Re-create Databases ==== | ==== Re-create Databases ==== |
| |
sudo mysql | sudo mariadb |
| |
CREATE DATABASE friendica; | CREATE DATABASE friendica; |
**** | **** |
| |
sudo mysql 'friendica' < ~/'friendica-database-'*'.sql' && sync | sudo mariadb 'friendica' < ~/'friendica-database-'*'.sql' && sync |
| |
==== Reapply Permissions ==== | ==== Reapply Permissions ==== |
| |
sudo mysql | sudo mariadb |
| |
GRANT ALL PRIVILEGES ON friendica.* to 'friendica'@'localhost' IDENTIFIED BY 'x'; | GRANT ALL PRIVILEGES ON friendica.* to 'friendica'@'localhost' IDENTIFIED BY 'x'; |
==== Remove Backups ==== | ==== Remove Backups ==== |
| |
* Verify that friendica works before running | * Verify that Friendica works before running |
| |
rm ~/'friendica-files-'*'.tar.gz' ~/'friendica-database-'*'.sql' && sync | rm ~/'friendica-files-'*'.tar.gz' ~/'friendica-database-'*'.sql' && sync |
| |