-
Notifications
You must be signed in to change notification settings - Fork 1
/
lamp.sh
135 lines (120 loc) · 5.35 KB
/
lamp.sh
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
#!/bin/bash
#
# Objetivo do script: instalar Apache2, PHP 7.4, MySQL e criar vHost de maneira automática.
# Feito para debian/ubuntu
#
# Lembrando que fiz isso para uso próprio e acelerar os deploys dos servidores que gerencio
# É um script simples e que só agiliza a implantação inicial.
# Fique a vontade para baixar, melhorar e contribuir com o código.
#
# Desenvolvido por Felipe Barreto
###############################################################################################
# Qual timezone usar?
echo "Qual timezone você deseja definir? (Padrão: America/Sao_Paulo)"
read -p "Informe o timezone: " timezone
echo "---"
# Versão do php (Ex: 7.3, 7.4, 8.0, 8.1)
echo "Qual versão do PHP deseja instalar? Disponíveis: 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 e 8.3"
read -p "Informe a versão do PHP: " PHP
echo "---"
# Versão do php (Ex: 7.3, 7.4, 8.0, 8.1)
read -p "Deseja instalar o MySQL? Informe S ou N " MYSQL
echo "---"
# Configurar vhost
echo "Configurar um vHost agora? "
read -p "Informe com S ou N: " VH
echo "---"
if [[ $VH == "S" ]]; then
read -p "Qual vai ser o domínio do site? (Sem www ou https://) " DOMINIO
echo "---"
read -p "Qual o nome do BD? (Ex: nomedosite)" PREFIXOBD
echo "---"
fi
##############################################################################################
##############################################################################################
##############################################################################################
# Debug? (# = não)
# set -x
# Gerador de numero aleatório
int=$(shuf -i 10-100 -n 1)
# Gerador de senha aleatória para o BD
password_db=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c34)
# Start
clear
echo "Iniciando o processo...."
timedatectl set-timezone $timezone > /dev/null 2>&1
apt-get --yes update > /dev/null 2>&1
# Instalando Apache e habilitando módulos
if [ -d "/etc/apache2" ]; then
echo "APACHE: Já existe uma instalação. Pulando esta etapa...";
sleep 2;
else
echo "APACHE: Iniciando instalação"
apt-get --yes install apache2 libapache2-mod-security2 > /dev/null 2>&1
echo "APACHE: Habilitando módulos..."
a2enmod rewrite > /dev/null 2>&1 && a2enmod deflate > /dev/null 2>&1
a2enmod expires > /dev/null 2>&1 && a2enmod http2 > /dev/null 2>&1
a2enmod proxy > /dev/null 2>&1 && a2enmod proxy_fcgi > /dev/null 2>&1
a2enmod ssl > /dev/null 2>&1 && a2enmod reqtimeout > /dev/null 2>&1
a2enmod headers > /dev/null 2>&1
systemctl restart apache2 > /dev/null 2>&1
ufw allow "Apache Full" > /dev/null 2>&1
echo "APACHE + SSL: Instalando certbot para apache..."
apt-get --yes install python3-certbot-apache > /dev/null 2>&1
fi
wget https://github.com/fabwebbr/fw_autoinstall/raw/main/arquivos/index.html -O /var/www/html/index.html
wget https://github.com/fabwebbr/fw_autoinstall/raw/main/arquivos/logo.png -O /var/www/html/logo.png
# Instalando php 7.4
sudo add-apt-repository ppa:ondrej/php --yes
sudo apt update > /dev/null 2>&1
if [ -d "/etc/php/${PHP}" ]; then
echo "PHP: A instalação do php ${PHP} já existe. Pulando esta etapa..."
apt --quiet --yes install php${PHP}-cli php${PHP}-fpm php${PHP}-mysql php${PHP}-zip php${PHP}-gd php${PHP}-mbstring php${PHP}-curl php${PHP}-xml php${PHP}-bcmath php${PHP}-imagick php${PHP}-intl php${PHP}-soap > /dev/null 2>&1
else
echo "PHP: Iniciando instalação do php ${PHP}..."
apt install php${PHP} -y > /dev/null 2>&1
apt --quiet --yes install php${PHP}-cli php${PHP}-fpm php${PHP}-mysql php${PHP}-zip php${PHP}-gd php${PHP}-mbstring php${PHP}-curl php${PHP}-xml php${PHP}-bcmath php${PHP}-imagick php${PHP}-intl php${PHP}-soap > /dev/null 2>&1
a2enconf php${PHP}-fpm > /dev/null 2>&1
echo "PHP: php${PHP}-fpm foi instalado e está pronto para uso com Apache2"
fi
# Instalando Mysql e configurando acesso
if [[ $MYSQL == "S" ]]; then
echo "MYSQL: Instalando MySQL..."
apt-get --yes --quiet install mysql-server
/usr/bin/mysql -e "CREATE DATABASE $PREFIXOBD";
/usr/bin/mysql -e "CREATE USER $PREFIXOBD@localhost IDENTIFIED BY \"$password_db\""
/usr/bin/mysql -e "GRANT ALL PRIVILEGES ON $PREFIXOBD.* TO $PREFIXOBD@localhost"
/usr/bin/mysql -e "FLUSH PRIVILEGES"
echo "Nome BD: $PREFIXOBD" >> /root/acessos-mysql.txt
echo "Nome Usuário: $PREFIXOBD" >> /root/acessos-mysql.txt
echo "Senha BD: $password_db" >> /root/acessos-mysql.txt
fi
if [[ $VH == "S" ]]; then
wget https://github.com/fabwebbr/fw_autoinstall/raw/main/modelo-vhost-apache-1.txt -O /tmp/modelo-vhost.txt
cp /tmp/modelo-vhost.txt /etc/apache2/sites-available/$DOMINIO.conf
/usr/bin/sed -i "s/NOMEDOMINIO/$DOMINIO/g" /etc/apache2/sites-available/$DOMINIO.conf
/usr/bin/sed -i "s/VPHP/$PHP/g" /etc/apache2/sites-available/$DOMINIO.conf
/usr/sbin/a2ensite $DOMINIO.conf
fi
clear
echo "-----------------------------------------------------------------------------------------------------------------"
echo "| A instalação do apache, php e mysql foram concluídas. "
echo "| Detalhes: "
echo "| "
if [[ $VH == "S" ]]; then
echo "| Sobre o Site: "
echo "| Pasta do site criado: /var/www/{$DOMINIO}"
echo "| Arquivo vHost: /etc/apache/sites-available/$DOMINIO"
echo "| "
fi
if [[ $MYSQL == "S" ]]; then
echo "| "
echo "| Sobre o MySQL: "
echo "| Nome BD: $PREFIXOBD"
echo "| Nome Usuário: $PREFIXOBD"
echo "| Senha BD: $password_db"
fi
echo "| "
echo "| Boa sorte :)"
echo "-----------------------------------------------------------------------------------------------------------------"
exit;