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.
This commit is contained in:
jo 2022-07-06 16:23:52 +02:00 committed by Kyle Robbertze
parent 2f205544c2
commit ec45717ccf
8 changed files with 114 additions and 48 deletions

View File

@ -52,7 +52,7 @@ sudo systemctl restart libretime.target
Verify that all the services are still running after the install process: Verify that all the services are still running after the install process:
```bash ```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: Verify for any error in the logs after the install process:

View File

@ -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 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.

View File

@ -50,18 +50,18 @@ sudo rm -f /{etc,usr/lib}/systemd/system/airtime*
sudo rm -f /{etc,usr/lib}/systemd/system/libretime* sudo rm -f /{etc,usr/lib}/systemd/system/libretime*
``` ```
Remove apache2 configuration files: Remove nginx configuration files:
```bash ```bash
sudo rm -f /etc/apache2/sites-{available,enabled}/airtime* sudo rm -f /etc/nginx/sites-{available,enabled}/airtime*
sudo rm -f /etc/apache2/sites-{available,enabled}/libretime* sudo rm -f /etc/nginx/sites-{available,enabled}/libretime*
``` ```
Remove php configuration files: Remove php-fpm configuration files:
```bash ```bash
sudo rm -f /etc/php/*/apache2/conf.d/airtime* sudo rm -f /etc/php/*/fpm/pool.d/airtime*
sudo rm -f /etc/php/*/apache2/conf.d/libretime* sudo rm -f /etc/php/*/fpm/pool.d/libretime*
``` ```
Remove logrotate configuration files: Remove logrotate configuration files:

View File

@ -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. 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 :::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 ```bash
# On Debian/Ubuntu systems sudo rm -f /etc/apache2/sites-*/{airtime,libretime}*
sudo rm -f /etc/apache2/sites-*/airtime* sudo rm -f /etc/php/*/apache2/conf.d/{airtime,libretime}*
sudo rm -f /etc/php/*/apache2/conf.d/airtime.ini
# On CentOS systems sudo apt purge apache2 'libapache2-mod-php*'
sudo rm -f /etc/httpd/conf.d/airtime*
sudo rm -f /etc/php.d/airtime.ini sudo rm -f /var/lib/php/sessions/sess_*
``` ```
### Shared files path ### Shared files path

52
install
View File

@ -652,39 +652,40 @@ else
chown -R "$LIBRETIME_USER:$LIBRETIME_USER" "$LEGACY_WEB_ROOT" chown -R "$LIBRETIME_USER:$LIBRETIME_USER" "$LEGACY_WEB_ROOT"
fi 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" info "deploying libretime-legacy logrotate config"
template_file "$SCRIPT_DIR/legacy/install/logrotate/libretime-legacy.conf" "/etc/logrotate.d/libretime-legacy" \ template_file "$SCRIPT_DIR/legacy/install/logrotate/libretime-legacy.conf" "/etc/logrotate.d/libretime-legacy" \
sed \ sed \
-e "s|@@LOG_DIR@@|${LOG_DIR}|g" \ -e "s|@@LOG_DIR@@|${LOG_DIR}|g" \
-e "s|@@USER@@|${LIBRETIME_USER}|g" -e "s|@@USER@@|${LIBRETIME_USER}|g"
# Install Apache # Install Nginx
######################################################################################## ########################################################################################
section "Apache" section "Nginx"
info "disabling apache default site" install_packages nginx
a2dissite 000-default
info "enabling apache modules" info "disabling nginx default site"
a2enmod rewrite proxy proxy_http rm -f "/etc/nginx/sites-enabled/default"
info "deploying libretime apache config" info "deploying libretime nginx config"
listen_port_string="" template_file "${SCRIPT_DIR}/installer/nginx/libretime.conf" "/etc/nginx/sites-available/libretime.conf" \
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" \
sed \ sed \
-e "s|@@LISTEN_PORT@@|${LIBRETIME_LISTEN_PORT}|g" \ -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" -e "s|@@LEGACY_WEB_ROOT@@|${LEGACY_WEB_ROOT}|g"
info "enabling libretime apache config" info "enabling libretime nginx config"
ln -s --force \ ln -s --force \
"/etc/apache2/sites-available/libretime.conf" \ "/etc/nginx/sites-available/libretime.conf" \
"/etc/apache2/sites-enabled/libretime.conf" "/etc/nginx/sites-enabled/libretime.conf"
# Finalize # Finalize
######################################################################################## ########################################################################################
@ -704,17 +705,14 @@ install_service "libretime.target" "$SCRIPT_DIR/installer/systemd/libretime.targ
systemctl daemon-reload systemctl daemon-reload
if apache2ctl configtest; then service_restart_if_active "php$PHP_VERSION-fpm"
service_restart_if_active apache2 service_restart_if_active "nginx"
else
warning "invalid apache configuration! fix it before restarting apache2."
fi
service_restart_if_active libretime-api service_restart_if_active "libretime-api"
service_restart_if_active libretime-celery service_restart_if_active "libretime-celery"
service_restart_if_active libretime-analyzer service_restart_if_active "libretime-analyzer"
service_restart_if_active libretime-playout service_restart_if_active "libretime-playout"
service_restart_if_active libretime-liquidsoap service_restart_if_active "libretime-liquidsoap"
# Instructions # Instructions
######################################################################################## ########################################################################################

View File

@ -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;
}
}

View File

@ -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

View File

@ -8,11 +8,16 @@ php-amqplib = buster, bullseye, bionic, focal
[locale] [locale]
gettext = buster, bullseye, bionic, focal gettext = buster, bullseye, bionic, focal
[apache] # [apache]
apache2 = buster, bullseye, bionic, focal # apache2 = buster, bullseye, bionic, focal
libapache2-mod-php7.2 = bionic # libapache2-mod-php7.2 = bionic
libapache2-mod-php7.3 = buster # libapache2-mod-php7.3 = buster
libapache2-mod-php7.4 = bullseye, focal # libapache2-mod-php7.4 = bullseye, focal
[php-fpm]
php7.2-fpm = bionic
php7.3-fpm = buster
php7.4-fpm = bullseye, focal
# Bionic # Bionic
[php7.2] [php7.2]