-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
143 lines (137 loc) · 4.54 KB
/
Copy pathsetup.sh
File metadata and controls
143 lines (137 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
set -euo pipefail
if [[ $EUID -ne 0 ]]; then
echo "[INFO] Elevating privileges for setup"
sudo -v
exec sudo -E bash "$0" "$@"
fi
echo "Easy and Secure Apache2 Webserver Setup"
echo "[INFO] installing requirements"
export DEBIAN_FRONTEND=noninteractive
APT_INSTALL_FLAGS=(-y)
if [ "${APT_NO_INSTALL_RECOMMENDS:-0}" = "1" ]; then
APT_INSTALL_FLAGS+=(--no-install-recommends)
fi
sudo apt update
sudo apt-get -y upgrade
OS_ID=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
OS_ID=${OS_ID//\"/}
USE_EXTERNAL_REPOS=${USE_EXTERNAL_REPOS:-true}
echo "[INFO] Installing requirements"
sudo apt install ca-certificates software-properties-common certbot python3-certbot-apache "${APT_INSTALL_FLAGS[@]}"
case $OS_ID in
ubuntu)
echo "Ubuntu"
if [[ "$USE_EXTERNAL_REPOS" == "true" ]]; then
sudo add-apt-repository ppa:ondrej/php -y
else
echo "[INFO] External repositories disabled, skipping PPA."
fi
;;
debian)
echo "Debian"
if [[ "$USE_EXTERNAL_REPOS" == "true" ]]; then
sudo apt install ca-certificates apt-transport-https lsb-release gnupg -y
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/sury-php.gpg
echo "deb [signed-by=/etc/apt/keyrings/sury-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list > /dev/null
sudo apt update
else
echo "[INFO] External repositories disabled, skipping Sury packages."
fi
;;
*)
echo "Unknown distribution: $OS_ID"
;;
esac
sudo apt update
sudo apt install apache2 curl php php-apcu php-common php-curl php-gd php-gmp php-imagick php-intl php-json php-mbstring php-memcache php-mysql php-zip mariadb-server mariadb-client "${APT_INSTALL_FLAGS[@]}"
mapfile -t php_versions < <(
apt-cache search -n '^php[0-9]+\\.[0-9]+$' \
| awk '{print $1}' \
| sed 's/^php//' \
| sort -V \
| awk -F. '($1 > 8) || ($1 == 8 && $2 >= 1)'
)
if [ ${#php_versions[@]} -eq 0 ]; then
php_versions=(8.1 8.2 8.3 8.4)
fi
for version in "${php_versions[@]}"; do
if apt-cache show "php$version" >/dev/null 2>&1; then
sudo apt install "php$version" "php$version-fpm" "libapache2-mod-php$version" \
"php$version-apcu" "php$version-bcmath" "php$version-cli" "php$version-common" \
"php$version-curl" "php$version-gd" "php$version-gmp" "php$version-imagick" \
"php$version-intl" "php$version-mbstring" "php$version-memcache" \
"php$version-mysql" "php$version-opcache" "php$version-phpdbg" \
"php$version-readline" "php$version-xml" "php$version-zip" "${APT_INSTALL_FLAGS[@]}"
else
echo "[WARN] PHP $version is not available in this repository, skipping."
fi
done
echo "[INFO] enable required and recommended mods"
a2dissite 000-default
a2dissite default-ssl
apache_mods=(
access_compat
alias
auth_basic
authn_core
authn_file
authz_core
authz_host
authz_user
autoindex
brotli
deflate
dir
filter
headers
http2
macro
mime
mpm_prefork
negotiation
proxy
proxy_fcgi
proxy_fdpass
proxy_html
proxy_http
proxy_http2
proxy_wstunnel
reqtimeout
rewrite
setenvif
socache_shmcb
ssl
status
vhost_alias
xml2enc
)
for mod in "${apache_mods[@]}"; do
if [ -e "/etc/apache2/mods-available/${mod}.load" ] || a2query -m "$mod" >/dev/null 2>&1; then
a2enmod "$mod"
else
echo "[WARN] Apache module ${mod} is not available, skipping."
fi
done
for version in "${php_versions[@]}"; do
if [ -e "/etc/apache2/conf-available/php$version-fpm.conf" ]; then
a2enconf "php$version-fpm"
fi
done
echo "[INFO] Copy configuration files"
sudo cp sites/hosts.conf /etc/apache2/sites-available/hosts.conf
sudo cp sites/LE-template.conf /etc/apache2/sites-available/LE-template.conf
sudo cp conf/vHosts.conf /etc/apache2/conf-available/vHosts.conf
sudo cp conf/SSLvHosts.conf /etc/apache2/conf-available/SSLvHosts.conf
sudo cp conf/Proxys.conf /etc/apache2/conf-available/Proxys.conf
sudo cp conf/SSLProxys.conf /etc/apache2/conf-available/SSLProxys.conf
echo "[INFO] Enable config and vhosts-file"
a2ensite hosts.conf
a2enconf vHosts.conf
a2enconf SSLvHosts.conf
a2enconf SSLProxys.conf
a2enconf Proxys.conf
echo "[INFO] Restart apache2"
systemctl restart apache2
echo "[INFO] Installation successfully completed"