From ec45717ccf312471f709341b33aeefa8aedd6dd3 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 6 Jul 2022 16:23:52 +0200 Subject: [PATCH] feat: replace apache2 with nginx + php-fpm BREAKING CHANGE: The `apache2` webserver has been replaced with `nginx` and `php-fpm`, be sure to uninstall `apache2` and clean related configuration files from your system before upgrading. --- docs/admin-manual/setup/upgrade.md | 2 +- docs/admin-manual/troubleshooting.md | 2 +- docs/admin-manual/uninstall.md | 12 ++--- docs/releases/unreleased.md | 15 +++--- install | 52 ++++++++++---------- installer/nginx/libretime.conf | 42 ++++++++++++++++ legacy/install/php-fpm/libretime-legacy.conf | 22 +++++++++ legacy/packages.ini | 15 ++++-- 8 files changed, 114 insertions(+), 48 deletions(-) create mode 100644 installer/nginx/libretime.conf create mode 100644 legacy/install/php-fpm/libretime-legacy.conf diff --git a/docs/admin-manual/setup/upgrade.md b/docs/admin-manual/setup/upgrade.md index 855288b93..4f49db8db 100644 --- a/docs/admin-manual/setup/upgrade.md +++ b/docs/admin-manual/setup/upgrade.md @@ -52,7 +52,7 @@ sudo systemctl restart libretime.target Verify that all the services are still running after the install process: ```bash -sudo systemctl --all --plain | egrep 'libretime|apache2' +sudo systemctl --all --plain | egrep 'libretime|nginx|php.*-fpm' ``` Verify for any error in the logs after the install process: diff --git a/docs/admin-manual/troubleshooting.md b/docs/admin-manual/troubleshooting.md index 538bd1fd0..ff9af6926 100644 --- a/docs/admin-manual/troubleshooting.md +++ b/docs/admin-manual/troubleshooting.md @@ -52,4 +52,4 @@ For some LibreTime services, you can set a higher log level using the `LIBRETIME sudo -u libretime libretime-analyzer --config /etc/libretime/config.yml --log-level debug ``` -The `/var/log/apache2/libretime.error.log` file contains logs from the web server. +The `/var/log/nginx/libretime.error.log` file contains logs from the web server. diff --git a/docs/admin-manual/uninstall.md b/docs/admin-manual/uninstall.md index 9f1656c98..e458464f2 100644 --- a/docs/admin-manual/uninstall.md +++ b/docs/admin-manual/uninstall.md @@ -50,18 +50,18 @@ sudo rm -f /{etc,usr/lib}/systemd/system/airtime* sudo rm -f /{etc,usr/lib}/systemd/system/libretime* ``` -Remove apache2 configuration files: +Remove nginx configuration files: ```bash -sudo rm -f /etc/apache2/sites-{available,enabled}/airtime* -sudo rm -f /etc/apache2/sites-{available,enabled}/libretime* +sudo rm -f /etc/nginx/sites-{available,enabled}/airtime* +sudo rm -f /etc/nginx/sites-{available,enabled}/libretime* ``` -Remove php configuration files: +Remove php-fpm configuration files: ```bash -sudo rm -f /etc/php/*/apache2/conf.d/airtime* -sudo rm -f /etc/php/*/apache2/conf.d/libretime* +sudo rm -f /etc/php/*/fpm/pool.d/airtime* +sudo rm -f /etc/php/*/fpm/pool.d/libretime* ``` Remove logrotate configuration files: diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index 5d00d7c84..f5a9206b3 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -44,7 +44,7 @@ sudo mv /etc/airtime /etc/libretime The configuration file format changed to `yml`. Please rewrite your [configuration file](../admin-manual/setup/configuration.md) using the [yaml format](https://yaml.org/). An example configuration file `installer/config.yml` is present in the sources. -### Apache and PHP configuration files +### Nginx, Apache and PHP :::caution @@ -52,16 +52,15 @@ Please run this **before the upgrade procedure**! ::: -The Apache configuration file has been updated and renamed, in addition the PHP configuration has been merged in the Apache configuration. The old configuration files must be removed from the system: +The `apache2` web server has been replaced with `nginx` and `php-fpm`, be sure to uninstall `apache2` and clean related configuration files: ```bash -# On Debian/Ubuntu systems -sudo rm -f /etc/apache2/sites-*/airtime* -sudo rm -f /etc/php/*/apache2/conf.d/airtime.ini +sudo rm -f /etc/apache2/sites-*/{airtime,libretime}* +sudo rm -f /etc/php/*/apache2/conf.d/{airtime,libretime}* -# On CentOS systems -sudo rm -f /etc/httpd/conf.d/airtime* -sudo rm -f /etc/php.d/airtime.ini +sudo apt purge apache2 'libapache2-mod-php*' + +sudo rm -f /var/lib/php/sessions/sess_* ``` ### Shared files path diff --git a/install b/install index ac5658a29..8b0d25993 100755 --- a/install +++ b/install @@ -652,39 +652,40 @@ else chown -R "$LIBRETIME_USER:$LIBRETIME_USER" "$LEGACY_WEB_ROOT" fi +PHP_VERSION="$(php-config --version | awk -F . '{ print $1 "." $2 }')" + +info "deploying libretime-legacy php-fpm config" +template_file "$SCRIPT_DIR/legacy/install/php-fpm/libretime-legacy.conf" "/etc/php/$PHP_VERSION/fpm/pool.d/libretime-legacy.conf" \ + sed \ + -e "s|@@DEFAULT_WEB_USER@@|${DEFAULT_WEB_USER}|g" \ + -e "s|@@USER@@|${LIBRETIME_USER}|g" + info "deploying libretime-legacy logrotate config" template_file "$SCRIPT_DIR/legacy/install/logrotate/libretime-legacy.conf" "/etc/logrotate.d/libretime-legacy" \ sed \ -e "s|@@LOG_DIR@@|${LOG_DIR}|g" \ -e "s|@@USER@@|${LIBRETIME_USER}|g" -# Install Apache +# Install Nginx ######################################################################################## -section "Apache" +section "Nginx" -info "disabling apache default site" -a2dissite 000-default +install_packages nginx -info "enabling apache modules" -a2enmod rewrite proxy proxy_http +info "disabling nginx default site" +rm -f "/etc/nginx/sites-enabled/default" -info "deploying libretime apache config" -listen_port_string="" -if [[ "$LIBRETIME_LISTEN_PORT" != "80" ]]; then - listen_port_string="Listen $LIBRETIME_LISTEN_PORT" -fi - -template_file "${SCRIPT_DIR}/installer/apache/libretime.conf" "/etc/apache2/sites-available/libretime.conf" \ +info "deploying libretime nginx config" +template_file "${SCRIPT_DIR}/installer/nginx/libretime.conf" "/etc/nginx/sites-available/libretime.conf" \ sed \ -e "s|@@LISTEN_PORT@@|${LIBRETIME_LISTEN_PORT}|g" \ - -e "s|@@LISTEN_PORT_STRING@@|${listen_port_string}|g" \ -e "s|@@LEGACY_WEB_ROOT@@|${LEGACY_WEB_ROOT}|g" -info "enabling libretime apache config" +info "enabling libretime nginx config" ln -s --force \ - "/etc/apache2/sites-available/libretime.conf" \ - "/etc/apache2/sites-enabled/libretime.conf" + "/etc/nginx/sites-available/libretime.conf" \ + "/etc/nginx/sites-enabled/libretime.conf" # Finalize ######################################################################################## @@ -704,17 +705,14 @@ install_service "libretime.target" "$SCRIPT_DIR/installer/systemd/libretime.targ systemctl daemon-reload -if apache2ctl configtest; then - service_restart_if_active apache2 -else - warning "invalid apache configuration! fix it before restarting apache2." -fi +service_restart_if_active "php$PHP_VERSION-fpm" +service_restart_if_active "nginx" -service_restart_if_active libretime-api -service_restart_if_active libretime-celery -service_restart_if_active libretime-analyzer -service_restart_if_active libretime-playout -service_restart_if_active libretime-liquidsoap +service_restart_if_active "libretime-api" +service_restart_if_active "libretime-celery" +service_restart_if_active "libretime-analyzer" +service_restart_if_active "libretime-playout" +service_restart_if_active "libretime-liquidsoap" # Instructions ######################################################################################## diff --git a/installer/nginx/libretime.conf b/installer/nginx/libretime.conf new file mode 100644 index 000000000..2813ec480 --- /dev/null +++ b/installer/nginx/libretime.conf @@ -0,0 +1,42 @@ +server { + listen @@LISTEN_PORT@@; + listen [::]:@@LISTEN_PORT@@; + + access_log /var/log/nginx/libretime.access.log; + error_log /var/log/nginx/libretime.error.log; + + root @@LEGACY_WEB_ROOT@@/public; + + index index.php index.html index.htm; + + client_max_body_size 512M; + client_body_timeout 300s; + + location ~ \.php$ { + fastcgi_buffers 64 4K; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + # try_files $uri =404; + try_files $fastcgi_script_name =404; + + include fastcgi_params; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + set $path_info $fastcgi_path_info; + fastcgi_param PATH_INFO $path_info; + include fastcgi_params; + + fastcgi_index index.php; + fastcgi_pass unix:/run/libretime-legacy.sock; + } + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ ^/(api/v2|api-auth) { + include proxy_params; + proxy_redirect off; + proxy_pass http://127.0.0.1:8081; + } +} diff --git a/legacy/install/php-fpm/libretime-legacy.conf b/legacy/install/php-fpm/libretime-legacy.conf new file mode 100644 index 000000000..75a299c98 --- /dev/null +++ b/legacy/install/php-fpm/libretime-legacy.conf @@ -0,0 +1,22 @@ +[libretime-legacy] +listen = /run/libretime-legacy.sock + +listen.owner = @@DEFAULT_WEB_USER@@ +listen.group = @@DEFAULT_WEB_USER@@ + +user = @@USER@@ +group = @@USER@@ + +pm = ondemand +pm.max_children = 30 +pm.process_idle_timeout = 60s +pm.max_requests = 500 + +php_admin_value[memory_limit] = 512M +php_admin_value[post_max_size] = 512M +php_admin_value[upload_max_filesize] = 512M +php_admin_value[upload_tmp_dir] = /tmp + +php_admin_value[request_order] = GPC +php_admin_value[session.gc_probability] = 0 +php_admin_value[session.auto_start] = 0 diff --git a/legacy/packages.ini b/legacy/packages.ini index 92256bded..bb71837c3 100644 --- a/legacy/packages.ini +++ b/legacy/packages.ini @@ -8,11 +8,16 @@ php-amqplib = buster, bullseye, bionic, focal [locale] gettext = buster, bullseye, bionic, focal -[apache] -apache2 = buster, bullseye, bionic, focal -libapache2-mod-php7.2 = bionic -libapache2-mod-php7.3 = buster -libapache2-mod-php7.4 = bullseye, focal +# [apache] +# apache2 = buster, bullseye, bionic, focal +# libapache2-mod-php7.2 = bionic +# libapache2-mod-php7.3 = buster +# libapache2-mod-php7.4 = bullseye, focal + +[php-fpm] +php7.2-fpm = bionic +php7.3-fpm = buster +php7.4-fpm = bullseye, focal # Bionic [php7.2]