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.
This commit is contained in:
Jonas L 2022-04-25 12:46:30 +02:00 committed by GitHub
parent 7865683f53
commit 95a7411c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 186 deletions

View File

@ -18,6 +18,20 @@ The LibreTime project wants to thank the following contributors for authoring PR
## :arrow_up: Upgrading ## :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 ## :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. 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.

100
install
View File

@ -887,19 +887,19 @@ fi
if [ "$in_place" = "t" ]; then if [ "$in_place" = "t" ]; then
verbose "\n * Setting current Airtime directory as web root..." verbose "\n * Setting current Airtime directory as web root..."
web_root=${AIRTIMEROOT}/legacy/public web_root=${AIRTIMEROOT}/legacy
elif [ -n "$web_root" ]; then elif [ -n "$web_root" ]; then
verbose "\n * Creating Apache web root directory..." verbose "\n * Creating Apache web root directory..."
cp -R ${AIRTIMEROOT}/legacy ${web_root} cp -R ${AIRTIMEROOT}/legacy ${web_root}
cp ${AIRTIMEROOT}/VERSION ${web_root} cp ${AIRTIMEROOT}/VERSION ${web_root}
web_root=${web_root}/legacy/public/ web_root=${web_root}/legacy
else else
verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..." verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..."
web_root="/usr/share/airtime/php" web_root="/usr/share/airtime/php"
mkdir -p ${web_root} mkdir -p ${web_root}
cp -R ${AIRTIMEROOT}/legacy ${web_root} cp -R ${AIRTIMEROOT}/legacy ${web_root}
cp ${AIRTIMEROOT}/VERSION ${web_root} cp ${AIRTIMEROOT}/VERSION ${web_root}
web_root=${web_root}/legacy/public/ web_root=${web_root}/legacy
fi fi
verbose "...Done" verbose "...Done"
@ -907,69 +907,32 @@ if [ "$apache" = "t" ]; then
loud "\n-----------------------------------------------------" loud "\n-----------------------------------------------------"
loud " * Configuring Apache * " loud " * Configuring Apache * "
loud "-----------------------------------------------------" 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 if $is_ubuntu_dist || $is_debian_dist; then
# Parse: Server version: Apache/2.2.22 (Ubuntu) -> 2 apache_site_dir="/etc/apache2/sites-available"
apache_major_version=$($apache_bin -v | awk -F'[ /.]+' 'NR == 1 { print $4 }') elif $is_centos_dist; then
set -e apache_site_dir="/etc/httpd/conf.d"
if [[ "$apache_major_version" -ge 2 ]]; then
airtimeconfigfile="airtime.conf"
oldconfigfile="airtime-vhost.conf"
else
airtimeconfigfile="airtime"
oldconfigfile="airtime-vhost"
fi fi
# If we're upgrading (installing over an existing Airtime install) and we've been told to apache_site_conf="${apache_site_dir}/libretime.conf"
# 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) if [[ "$upgrade" == "t" || ! -f "$apache_site_conf" ]]; then
# will fail verbose "\n * Creating Apache config for LibreTime..."
if [[ "$upgrade" == "t" || ! -f "${apache_sitedir}${airtimeconfigfile}" ]]; then
verbose "\n * Creating Apache config for Airtime..."
listen_port="" listen_port=""
if [ "$web_port" != "80" ]; then if [ "$web_port" != "80" ]; then
listen_port="Listen ${web_port}" listen_port="Listen ${web_port}"
fi 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 \ sed \
-e "s@WEB_PORT_LISTEN@${listen_port}@g" \ -e "s|@@LISTEN_PORT_STRING@@|${listen_port}|g" \
-e "s@WEB_PORT@${web_port}@g" \ -e "s|@@LISTEN_PORT@@|${web_port}|g" \
-e "s@WEB_ROOT@${web_root}@g" \ -e "s|@@LEGACY_WEB_ROOT@@|${web_root}|g" \
${apache_template_file} > ${apache_sitedir}${airtimeconfigfile} "${SCRIPT_DIR}/installer/apache/libretime.conf" > "$apache_site_conf"
# The a2ensite/a2dissite utilities are not available on CentOS # The a2ensite/a2dissite utilities are not available on CentOS
if [[ -x /usr/sbin/a2ensite ]]; then if [[ -x /usr/sbin/a2ensite ]]; then
loudCmd "a2dissite 000-default" loudCmd "a2dissite 000-default"
# If Airtime was previously installed with apt, the vhost file name is different, loudCmd "a2ensite libretime"
# so we need to specifically disable it.
if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then
loudCmd "a2dissite airtime-vhost"
fi
loudCmd "a2ensite airtime"
fi fi
else else
verbose "\nApache config for Airtime already exists, skipping" verbose "\nApache config for Airtime already exists, skipping"
@ -1096,32 +1059,6 @@ loudCmd "chmod -R 775 /var/log/libretime"
loud "\n-----------------------------------------------------" loud "\n-----------------------------------------------------"
loud " * Configuring PHP in Apache * " loud " * Configuring PHP in Apache * "
loud "-----------------------------------------------------" 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 # Enable Apache modules
if $is_debian_bullseye || $is_ubuntu_focal; then if $is_debian_bullseye || $is_ubuntu_focal; then
@ -1241,8 +1178,13 @@ if [ "$selinux" = "t" ]; then
verbose "...Done" verbose "...Done"
fi fi
if apachectl configtest; then
verbose "\n * Reloading apache..." verbose "\n * Reloading apache..."
systemInitCommand restart ${apache_service} 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 # NOTE: ip command works on all supported platforms
if $is_centos_dist; then if $is_centos_dist; then
IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+') IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+')

View File

@ -1,48 +0,0 @@
WEB_PORT_LISTEN
<VirtualHost *:WEB_PORT>
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/
<Directory WEB_ROOT>
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
</Directory>
<Directory /usr/share/airtime/api>
Require all granted
</Directory>
</VirtualHost>

View File

@ -1,50 +0,0 @@
WEB_PORT_LISTEN
<VirtualHost *:WEB_PORT>
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/
<Directory WEB_ROOT>
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
</Directory>
<Directory /usr/share/airtime/api>
Require all granted
</Directory>
</VirtualHost>

View File

@ -0,0 +1,45 @@
@@LISTEN_PORT_STRING@@
<VirtualHost *:@@LISTEN_PORT@@>
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
<Directory @@LEGACY_WEB_ROOT@@/public>
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
</Directory>
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/
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View File

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