-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·303 lines (225 loc) · 6.83 KB
/
install
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
# LAMP Stack - NG :: Linux Apache2 MariaDB PHP
# -----------------------------------------------
# license: MIT
# Author: Béba Godfried A. <[email protected]>
# -----------------------------------------------
# Bash
red='\033[0;31m'
green='\033[0;32m'
warning='\033[0;33m'
reset='\033[0m' # No Color
# env
httpd='httpd'
w3_server='httpd'
db_server='mariadb-server'
w3_htdocs='/var/www/html/'
lamppctl="$(pwd)/bin/lampp"
# packages manager
if ( command -v apt-get >> /dev/null );then
pkg='apt'
elif ( command -v yum >> /dev/null );then
pkg='yum'
elif ( command -v pamac >> /dev/null );then
pkg='pamac'
w3_server='apache'
db_server='mariadb'
w3_htdocs='/srv/http'
elif ( command -v zypper >> /dev/null );then
pkg='zypper'
else
echo 'Exit(1)::Unsupported package'
exit 1
fi
# function
function cls() {
clear
}
function wait() {
echo
read -rp 'Press (enter) to continue '
}
function head() {
echo -e "${green}LAMP Stack - NG :: Linux Apache2 MariaDB PHP${reset}"
echo -e "$(uname -a)"
echo ''
}
function get_phpmyadmin() {
# head
function pma_install() {
cd "$w3_htdocs" || echo "${red}Something went wrong! please try again${reset}"
sudo wget 'https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip'
sudo unzip -o 'phpMyAdmin-5.2.1-all-languages.zip'
sudo rm 'phpMyAdmin-5.2.1-all-languages.zip'
sudo mv -f 'phpMyAdmin-5.2.1-all-languages' 'phpmyadmin'
sudo chown root:root phpmyadmin/
sudo chmod 755 phpmyadmin/
}
# main
read -rp "$(echo -e "${warning}# => Get phpMyAdmin ? [y/N] ${reset}")" pma
if [ "$pma" == "y" ];then
pma_install
elif [ "$pma" == "yes" ];then
pma_install
elif [ "$pma" == "Y" ];then
pma_install
else
echo 'skipped ...'
fi
}
# start
cls && head
echo -e "Web server : ${green}$w3_server${reset}"
echo -e "MySQL server : ${green}$db_server${reset}"
echo -e "Documents root: ${green}$w3_htdocs${reset}"
wait
sudo $pkg update
# Step 1: Web Server
cls && head
echo -e "${green}Installing Packages:${reset}"
echo '===================='
echo -e "${warning}# => Apache Web Server...${reset}"
sudo $pkg install $w3_server
# - Start and enable apache server
# - mod_rewrite on Debian-based Systems
if ( command -v a2enmod >> /dev/null );then
sudo a2enmod rewrite
fi
# - mod_rewrite on RHEL-based Systems
if ( command -v httpd >> /dev/null );then
# unlock `httpd.conf`
sudo chmod 777 /etc/httpd/conf/httpd.conf
# write `httpd.conf`
sudo cp conf.d/httpd.conf /etc/httpd/conf/httpd.conf
# lock `httpd.conf`
sudo chmod 644 /etc/httpd/conf/httpd.conf
fi
sudo systemctl start $httpd
sudo systemctl enable $httpd
# Step 2: Database Server
echo ''
echo -e "${warning}# => MariaDB Database Server ...${reset}"
sudo $pkg install $db_server
# - Start and enable mariadb server
sudo systemctl start mariadb
sudo systemctl enable mariadb
# Step 3: PHP and dependencies
echo ''
echo -e "${warning}# => PHP & modules dependencies...${reset}"
sudo $pkg install php php-common php-mysqlnd php-pdo
if [ $w3_server == 'apache' ]; then
sudo $pkg install php-$w3_server
fi
echo ''
sudo $pkg install php-json php-xsl php-gd php-fpm php-cgi php-snmp httpd-tools mod_ssl
echo ''
sudo $pkg install php-mysqli
echo ''
sudo $pkg install git composer
# Step 4: Get phpMyAdmin GitHub Repository
echo ''
get_phpmyadmin
# pause
wait
cls && head
# Step 5: Config Firewall Rules
echo -e "${green}Configuring Firewall:${reset}"
echo '====================='
# - Check if `'firewall-cmd'`/ufw firewalling exist
if ( command -v firewall-cmd >> /dev/null );then
sudo systemctl start firewalld
sudo systemctl enable firewalld
# shellcheck disable=SC2091
if ( ! "firewall-cmd" --list-services | grep -q "https" ); then
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
else
echo -e "${green} ALREADY_ENABLED ${reset}"
fi
# - reload firewall to apply changes
sudo systemctl reload firewalld
elif ( command -v ufw >> /dev/null );then
sudo systemctl start ufw
sudo systemctl enable ufw
# shellcheck disable=SC2091
if ( ! ufw services list | grep -q "https" ); then
sudo ufw allow http
sudo ufw allow https
else
echo -e "${green} ALREADY_ENABLED ${reset}"
fi
# - reload firewall to apply changes
sudo systemctl reload ufw
else
sudo $pkg install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
# shellcheck disable=SC2091
if ( ! "firewall-cmd" --list-services | grep -q "https" ); then
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
else
echo -e "${green} ALREADY_ENABLED ${reset}"
fi
# - reload firewall to apply changes
sudo systemctl reload firewalld
fi
if ( command -v setsebool >> /dev/null ); then
# --- allow httpd to unified
sudo setsebool -P httpd_unified 1
# --- allow httpd to read user content
sudo setsebool -P httpd_read_user_content 1
# --- allow httpd to can network connect
sudo setsebool -P httpd_can_network_connect 1
# --- restart $httpd service to load firewall rules
sudo setsebool -P httpd_graceful_shutdown 1
# --- allow httpd to can network relay
sudo setsebool -P httpd_can_network_relay 1
# --- allow nis to enabled
sudo setsebool -P nis_enabled 1
fi
sudo systemctl restart $httpd
wait
clear
# Step 7: Secure MySQL Installation
echo -e "${green}MySQL Configurations:${reset}"
echo '====================='
sudo mysql_secure_installation
# sudo mysql -h '' -u root -p < my.sql
# then restart $httpd service to load new configuration
echo ''
sudo systemctl restart $httpd
# Step 8: File && Permissions
# - Document_root is `$w3_htdocs`
# - Enable write permissions on `document_root`
sudo chmod -R 777 $w3_htdocs
# Step 9: SSL - activated by lampp-ng rules
### Relax access to `/var/www/html` from `$HOME/` folder
ln -s "$w3_htdocs" "$HOME/www"
if [ -e "$HOME/www/html" ];then
rm "$HOME/www/html"
fi
# ---------------------------------------------------
cls
echo ''
echo "All done! If you've completed all of the above steps, your LAMPP-NG"
echo 'installation should now be functional.'
echo ''
echo -e "${green}Thanks for using LAMPP-NG!${reset}"
sudo cp "$lamppctl" /bin
sudo chmod 755 /bin/lampp
# kde folder icon
echo "[Desktop Entry]" >> "$HOME/www/.directory"
echo "Icon=folder_html" >> "$HOME/www/.directory"
echo "<?php phpinfo() ?>" > "$HOME/www/info.php"
if [ "$(id -u)" == 0 ]; then
echo "Your server information's here: https://localhost/info.php"
else
echo "Opening your server informations."
xdg-open https://localhost/info.php
fi
lampp --new-index
wait
lampp --help
# Option: add a personal host
# eof