-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlamp_install.sh
More file actions
222 lines (204 loc) · 4.96 KB
/
Copy pathlamp_install.sh
File metadata and controls
222 lines (204 loc) · 4.96 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
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
#!/usr/bin/env bash
#######################################
# Script name : lamp_install.sh
# Description : Install a LAMP stack.
# Args : option -i; -u; -h
# Author : Phenates
# Date : 2024-04
# Version : 0.1
#######################################
#######################################
# Variables:
#######################################
# Config:
PURPOSE="LAMP stack installation script"
APACHE_PACKAGES="apache2 libapache2-mod-php"
PHP_PACKAGES="php php-common php-cli php-mysql php-xml php-xmlrpc php-curl php-json php-gd php-imagick php-dev php-imap php-mbstring php-opcache php-soap php-zip php-intl"
MYSQL_REPOSITOTY="https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb"
MYSQL_PACKAGE="mysql-server"
MARIADB_PACKAGES="mariadb-server"
# Text format
RESET="\e[0m"
NOCOLOR='\033[0m'
BLUE='\033[0;34m'
RED='\033[0;31m'
GREEN="\033[32;40m"
WHITE_ON_BLUE="\e[104;37m"
#######################################
# Show script usage.
# Arguments: Options (h,i,r)
# Outputs: None
#######################################
usage() {
echo "Usage: $(basename "$0") [OPTIONS]"
echo "Purpose: $PURPOSE"
echo "Options:"
echo " -h, --help: Display usage"
echo " -i, --install: Script installation"
echo " -u, --uninstall: Script uninstallation"
}
#######################################
# Print info
# Arguments: string
#######################################
info() {
echo -e "${BLUE}$1 ${RESET}"
}
#######################################
# Packages update & upgrade
# Arguments: None
# Outputs: None
#######################################
package_upgrade() {
info "\n>>> Packages Update & Upgrade"
sudo apt update && sudo apt upgrade -y
return 0
}
#######################################
# Apache install
# Arguments: None
# Outputs: None
#######################################
apache_install() {
info "\n>>> Apache2 installation."
info "--> Installed packages: $APACHE_PACKAGES"
info "--> Continue ? [y/n] "
read -r
case $REPLY in
[yY])
# shellcheck disable=SC2086
sudo apt install $APACHE_PACKAGES
info "\n--> Enable Apache2"
sudo systemctl enable apache2
# sudo a2enmod rewrite
info "\n--> Restart Apache2"
sudo systemctl restart apache2
info "\n--> Status Apache2"
sudo systemctl status apache2
;;
[nN])
info "--> Aborded"
return 1
;;
esac
return 0
}
#######################################
# PHP install
# Arguments: None
# Outputs: None
#######################################
php_install() {
info "\n>>> PHP installation."
info "--> Installed packages: $PHP_PACKAGES"
info "--> Continue ? [y/n] "
read -r
case $REPLY in
[yY])
# shellcheck disable=SC2086
sudo apt install -y $PHP_PACKAGES
info "\n--> Version PHP"
sudo php --version
;;
[nN])
info "--> Aborded"
return 1
;;
esac
return 0
}
#######################################
# SQL DB install
# Arguments: None
# Outputs: None
#######################################
sql_install() {
info "\n>>> SQL Database installation."
info "--> Choice: MariaDB [1] / MySQL [2] ? "
read -r
case $REPLY in
[1])
info "--> MaraiDB installation:"
sudo apt install -y $MARIADB_PACKAGES
;;
[2])
info "--> MySQL installation:"
info "--> Download & install MySQL APT repository from $MYSQL_REPOSITOTY"
wget -O /tmp/mysql-apt-config.deb $MYSQL_REPOSITOTY
sudo apt install -y /tmp/mysql-apt-config.deb
sudo apt update -y
info "\n--> Install $MYSQL_PACKAGE"
sudo apt install -y $MYSQL_PACKAGE
info "\n--> MySQL version:"
mysql -v
info "\n--> MySQL status:"
sudo systemctl status mysql
;;
[A])
info "--> Aborded"
return 1
;;
esac
info "\n--> Run mysql_secure_installation ? [y/n] "
read -r
case $REPLY in
[yY])
sudo mysql_secure_installation
;;
[nN])
info "--> Aborded"
return 1
;;
esac
return 0
}
#######################################
# LAMP remove
# Arguments: None
# Outputs: None
#######################################
lamp_uninstall() {
info "\n>>> LAMP Uninstallation."
info "--> Packages: $APACHE_PACKAGES $PHP_PACKAGES $MYSQL_PACKAGE $MARIADB_PACKAGES, will be removed."
info "--> Continue ? [y/n] "
read -r
case $REPLY in
[yY]) ;;
[nN])
info "--> Action canceled"
return 1
;;
esac
sudo apt remove -y $APACHE_PACKAGES $PHP_PACKAGES $MYSQL_PACKAGE $MARIADB_PACKAGES
sudo apt autoremove
return 0
}
#######################################
# Main function.
# Arguments: None
# Outputs: None
#######################################
main() {
info "\n\n############################################"
info "######## $(basename "$0") started ##########"
case "$1" in
-i | --install)
package_upgrade
apache_install
php_install
sql_install
;;
-u | --uninstall)
lamp_uninstall
;;
-h | --help)
usage
;;
*)
usage
;;
esac
info "\n######## $(basename "$0") finished ##########"
info "############################################\n\n"
}
main "$*"