From 95a7411c0cd95da0133c4c940079ffc7cd05012d Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 25 Apr 2022 12:46:30 +0200 Subject: [PATCH] feat: improve apache configuration (#1784) - merge php config in apache config - remove deprecated php config - remove old apache config - use dedicated log files for libretime vhost - change template variables format BREAKING: The apache configuration file has been updated and renamed. You must remove the old configuration files `/etc/apache2/sites-available/airtime*` file from the system. BREAKING: The php configuration file has been merged in the apache configuration. You need to remove the `/etc/php/*/apache2/conf.d/airtime.ini` file from the system. --- docs/releases/unreleased.md | 14 ++++ install | 104 +++++++---------------------- installer/apache/airtime-vhost | 48 ------------- installer/apache/airtime-vhost-2.4 | 50 -------------- installer/apache/libretime.conf | 45 +++++++++++++ installer/php/airtime.ini | 7 -- 6 files changed, 82 insertions(+), 186 deletions(-) delete mode 100644 installer/apache/airtime-vhost delete mode 100644 installer/apache/airtime-vhost-2.4 create mode 100644 installer/apache/libretime.conf delete mode 100644 installer/php/airtime.ini diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index 1148f5269..a53773a8b 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -18,6 +18,20 @@ The LibreTime project wants to thank the following contributors for authoring PR ## :arrow_up: Upgrading +### Apache and PHP configuration files + +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 **before the upgrade procedure**: + +```bash +# On Debian/Ubuntu systems +sudo rm -f /etc/apache2/sites-*/airtime* +sudo rm -f /etc/php/*/apache2/conf.d/airtime.ini + +# On CentOS systems +sudo rm -f /etc/httpd/conf.d/airtime* +sudo rm -f /etc/php.d/airtime.ini +``` + ## :warning: Known issues The following issues may need a workaround for the time being. Please search the [issues](https://github.com/libretime/libretime/issues) before reporting problems not listed below. diff --git a/install b/install index a1d4f489a..66d6da29c 100755 --- a/install +++ b/install @@ -887,19 +887,19 @@ fi if [ "$in_place" = "t" ]; then verbose "\n * Setting current Airtime directory as web root..." - web_root=${AIRTIMEROOT}/legacy/public + web_root=${AIRTIMEROOT}/legacy elif [ -n "$web_root" ]; then verbose "\n * Creating Apache web root directory..." cp -R ${AIRTIMEROOT}/legacy ${web_root} cp ${AIRTIMEROOT}/VERSION ${web_root} - web_root=${web_root}/legacy/public/ + web_root=${web_root}/legacy else verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..." web_root="/usr/share/airtime/php" mkdir -p ${web_root} cp -R ${AIRTIMEROOT}/legacy ${web_root} cp ${AIRTIMEROOT}/VERSION ${web_root} - web_root=${web_root}/legacy/public/ + web_root=${web_root}/legacy fi verbose "...Done" @@ -907,69 +907,32 @@ if [ "$apache" = "t" ]; then loud "\n-----------------------------------------------------" loud " * Configuring Apache * " loud "-----------------------------------------------------" - # Detect Apache root folder, e.g. /etc/apache2 or /etc/httpd - eval "$($apache_bin -V | awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }')" - apache_conf="${HTTPD_ROOT}/${SERVER_CONFIG_FILE}" - verbose "Detected Apache root folder is: ${HTTPD_ROOT}" - if [[ ! -e $apache_conf ]]; then - echo -e "ERROR: Apache binary \"$apache_bin\" points to a non-existent file \"$apache_conf\"" - exit 1 - fi - verbose "Detected Apache primary .conf file is: ${apache_conf}" - if [[ -d ${HTTPD_ROOT}/sites-available ]]; then # debian & ubuntu - apache_sitedir="${HTTPD_ROOT}/sites-available/" - elif [[ -d ${HTTPD_ROOT}/conf.d ]]; then # centos - apache_sitedir="${HTTPD_ROOT}/conf.d/" - else - echo -e "ERROR: unknown location of Apache sites-available or virtual host directory!" >&2 - exit 1 - fi - verbose "Detected Apache sites configuration folder: ${apache_sitedir}" - set +e - # Parse: Server version: Apache/2.2.22 (Ubuntu) -> 2 - apache_major_version=$($apache_bin -v | awk -F'[ /.]+' 'NR == 1 { print $4 }') - set -e - - if [[ "$apache_major_version" -ge 2 ]]; then - airtimeconfigfile="airtime.conf" - oldconfigfile="airtime-vhost.conf" - else - airtimeconfigfile="airtime" - oldconfigfile="airtime-vhost" + if $is_ubuntu_dist || $is_debian_dist; then + apache_site_dir="/etc/apache2/sites-available" + elif $is_centos_dist; then + apache_site_dir="/etc/httpd/conf.d" fi - # If we're upgrading (installing over an existing Airtime install) and we've been told to - # install apache, we should overwrite any existing configuration. If we don't do this, doing - # an in-place installation over an old Airtime install (which installs to /usr/share by default) - # will fail - if [[ "$upgrade" == "t" || ! -f "${apache_sitedir}${airtimeconfigfile}" ]]; then - verbose "\n * Creating Apache config for Airtime..." + apache_site_conf="${apache_site_dir}/libretime.conf" + + if [[ "$upgrade" == "t" || ! -f "$apache_site_conf" ]]; then + verbose "\n * Creating Apache config for LibreTime..." listen_port="" if [ "$web_port" != "80" ]; then listen_port="Listen ${web_port}" fi - apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4 - if [[ "$apache_major_version" -eq 1 ]]; then - # fall back to apache 1 config - apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost - fi sed \ - -e "s@WEB_PORT_LISTEN@${listen_port}@g" \ - -e "s@WEB_PORT@${web_port}@g" \ - -e "s@WEB_ROOT@${web_root}@g" \ - ${apache_template_file} > ${apache_sitedir}${airtimeconfigfile} + -e "s|@@LISTEN_PORT_STRING@@|${listen_port}|g" \ + -e "s|@@LISTEN_PORT@@|${web_port}|g" \ + -e "s|@@LEGACY_WEB_ROOT@@|${web_root}|g" \ + "${SCRIPT_DIR}/installer/apache/libretime.conf" > "$apache_site_conf" # The a2ensite/a2dissite utilities are not available on CentOS if [[ -x /usr/sbin/a2ensite ]]; then loudCmd "a2dissite 000-default" - # If Airtime was previously installed with apt, the vhost file name is different, - # so we need to specifically disable it. - if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then - loudCmd "a2dissite airtime-vhost" - fi - loudCmd "a2ensite airtime" + loudCmd "a2ensite libretime" fi else verbose "\nApache config for Airtime already exists, skipping" @@ -1096,32 +1059,6 @@ loudCmd "chmod -R 775 /var/log/libretime" loud "\n-----------------------------------------------------" loud " * Configuring PHP in Apache * " loud "-----------------------------------------------------" -# Test common locations for php conf directory -php_conf_dirs=( - "/etc/php/7.4/apache2/conf.d" # Debian Bullseye, Ubuntu Focal - "/etc/php/7.3/apache2/conf.d" # Debian Buster - "/etc/php/7.2/apache2/conf.d" # Ubuntu Bionic - "/etc/php/7.0/apache2/conf.d" # Ubuntu Xenial - "/etc/php5/apache2/conf.d" # Debian Stretch, Debian Jessie, Ubuntu Trusty - "/etc/php.d" # CentOS 7 -) - -for php_conf in "${php_conf_dirs[@]}"; do - [[ -d $php_conf ]] && break -done -if [[ -d $php_conf ]]; then - libretime_phpini="${php_conf}/airtime.ini" -else - echo -e "ERROR: PHP Apache configuration folder does not exist or is in an unknown location!" >&2 - exit 1 -fi -verbose "Detected php conf directory at: $php_conf" -if [ ! -f "${libretime_phpini}" ]; then - verbose "\n * Creating LibreTime PHP config for Apache..." - cp ${SCRIPT_DIR}/installer/php/airtime.ini ${libretime_phpini} -else - verbose "\nAirtime PHP config for Apache already exists, skipping" -fi # Enable Apache modules if $is_debian_bullseye || $is_ubuntu_focal; then @@ -1241,8 +1178,13 @@ if [ "$selinux" = "t" ]; then verbose "...Done" fi -verbose "\n * Reloading apache..." -systemInitCommand restart ${apache_service} +if apachectl configtest; then + verbose "\n * Reloading apache..." + systemInitCommand restart ${apache_service} +else + verbose "\n * Apache configuration is invalid! Please fix it before reloading apache..." +fi + # NOTE: ip command works on all supported platforms if $is_centos_dist; then IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+') diff --git a/installer/apache/airtime-vhost b/installer/apache/airtime-vhost deleted file mode 100644 index aa2fe5efa..000000000 --- a/installer/apache/airtime-vhost +++ /dev/null @@ -1,48 +0,0 @@ -WEB_PORT_LISTEN - - - ServerAdmin foo@bar.org - DocumentRoot WEB_ROOT - php_admin_value upload_tmp_dir /tmp - php_value post_max_size 500M - php_value upload_max_filesize 500M - php_value request_order "GPC" - php_value session.gc_probability 0 - php_value session.auto_start 0 - - AddOutputFilterByType DEFLATE text/plain - AddOutputFilterByType DEFLATE text/html - AddOutputFilterByType DEFLATE text/xml - AddOutputFilterByType DEFLATE text/css - AddOutputFilterByType DEFLATE application/xml - AddOutputFilterByType DEFLATE application/xhtml+xml - AddOutputFilterByType DEFLATE application/rss+xml - AddOutputFilterByType DEFLATE application/javascript - AddOutputFilterByType DEFLATE application/x-javascript - AddOutputFilterByType DEFLATE application/json - - ProxyPreserveHost On - ProxyPass /api/v2/ http://localhost:8081/api/v2/ - ProxyPassReverse /api/v2/ http://localhost:8081/api/v2/ - ProxyPass /api-auth/ http://localhost:8081/api-auth/ - ProxyPassReverse /api-auth/ http://localhost:8081/api-auth/ - Alias /api/static /usr/share/airtime/api/ - - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} -s [OR] - RewriteCond %{REQUEST_FILENAME} -l [OR] - RewriteCond %{REQUEST_FILENAME} -d - RewriteRule ^.*$ - [NC,L] - RewriteRule ^.*$ index.php [NC,L] - Order allow,deny - Allow from all - - Require all granted - - - - Require all granted - - - diff --git a/installer/apache/airtime-vhost-2.4 b/installer/apache/airtime-vhost-2.4 deleted file mode 100644 index 511fa57f3..000000000 --- a/installer/apache/airtime-vhost-2.4 +++ /dev/null @@ -1,50 +0,0 @@ -WEB_PORT_LISTEN - - - ServerAdmin foo@bar.org - DocumentRoot WEB_ROOT - php_admin_value upload_tmp_dir /tmp - php_value post_max_size 500M - php_value upload_max_filesize 500M - php_value request_order "GPC" - php_value session.gc_probability 0 - php_value session.auto_start 0 - - AddOutputFilterByType DEFLATE text/plain - AddOutputFilterByType DEFLATE text/html - AddOutputFilterByType DEFLATE text/xml - AddOutputFilterByType DEFLATE text/css - AddOutputFilterByType DEFLATE application/xml - AddOutputFilterByType DEFLATE application/xhtml+xml - AddOutputFilterByType DEFLATE application/rss+xml - AddOutputFilterByType DEFLATE application/javascript - AddOutputFilterByType DEFLATE application/x-javascript - AddOutputFilterByType DEFLATE application/json - - ProxyPreserveHost On - ProxyPass /api/v2/ http://localhost:8081/api/v2/ - ProxyPassReverse /api/v2/ http://localhost:8081/api/v2/ - ProxyPass /api-auth/ http://localhost:8081/api-auth/ - ProxyPassReverse /api-auth/ http://localhost:8081/api-auth/ - Alias /api/static /usr/share/airtime/api/ - - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} -s [OR] - RewriteCond %{REQUEST_FILENAME} -l [OR] - RewriteCond %{REQUEST_FILENAME} -d - RewriteRule ^.*$ - [NC,L] - RewriteRule ^.*$ index.php [NC,L] - - DirectoryIndex index.php - AllowOverride all - Order allow,deny - Allow from all - - Require all granted - - - - Require all granted - - diff --git a/installer/apache/libretime.conf b/installer/apache/libretime.conf new file mode 100644 index 000000000..8a2e10d5c --- /dev/null +++ b/installer/apache/libretime.conf @@ -0,0 +1,45 @@ +@@LISTEN_PORT_STRING@@ + + + ServerAdmin webmaster@localhost + DocumentRoot @@LEGACY_WEB_ROOT@@/public + + ErrorLog ${APACHE_LOG_DIR}/libretime.error.log + CustomLog ${APACHE_LOG_DIR}/libretime.access.log combined + + AddOutputFilterByType DEFLATE text/plain text/html text/css application/javascript application/json + + 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 + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} -s [OR] + RewriteCond %{REQUEST_FILENAME} -l [OR] + RewriteCond %{REQUEST_FILENAME} -d + RewriteRule ^.*$ - [NC,L] + RewriteRule ^.*$ index.php [NC,L] + + DirectoryIndex index.php + AllowOverride all + Order allow,deny + Allow from all + + Require all granted + + + ProxyPreserveHost On + ProxyPass /api/v2/ http://localhost:8081/api/v2/ + ProxyPassReverse /api/v2/ http://localhost:8081/api/v2/ + ProxyPass /api-auth/ http://localhost:8081/api-auth/ + ProxyPassReverse /api-auth/ http://localhost:8081/api-auth/ + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/installer/php/airtime.ini b/installer/php/airtime.ini deleted file mode 100644 index c75cf0025..000000000 --- a/installer/php/airtime.ini +++ /dev/null @@ -1,7 +0,0 @@ -[PHP] -memory_limit = 512M -magic_quotes_gpc = Off -file_uploads = On -upload_tmp_dir = /tmp -apc.write_lock = 1 -apc.slam_defense = 0