Atualizar, configurar zona de horário e instalar pacotes básicos:
apt update -y && apt upgrade -y && apt install openssh-server sudo tar unzip bzip2 hostname perl chrony mc wget nginx firewalld mariadb-server gnupg gnupg2 fail2ban git certbot python3-certbot-nginx -y && sudo systemctl disable ssh.socket
Caso o servidor não for utilizar conexão ipv6, desabilitar o protocolo ipv6 no sistema operacional, editando o arquivo /etc/sysctl.conf:
vi /etc/sysctl.conf
Incluir o conteúdo:
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
Caso queira permitir o login ao servidor utilizando o usuário root, alterar a configuração em /etc/ssh/sshd_config:
vi /etc/ssh/sshd_config
Alterar o conteúdo, comentando a linha PermitRootLogin e StrictModes e inserindo a linha PermitRootLogin
#PermitRootLogin prohibit-password PermitRootLogin yes StrictModes yes
Reiniciar o SSH Server:
service sshd restart
Configurar o MySQL:
mysql_secure_installation
Depois acessar o MySQL e alterar a senha de root:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit;
firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port 3022/tcp --permanent
firewall-cmd --reload
O Fail2ban previne ataques ao SSH, bloqueando um endereço IP atacante no firewall. Criar o arquivo /etc/fail2ban/jail.local e inserir a configuração abaixo:
echo "[DEFAULT] bantime = 86400 findtime = 600 maxretry = 3 banaction = iptables-multiport [sshd] enabled = true" > /etc/fail2ban/jail.local
systemctl enable fail2ban systemctl start fail2ban
apt update apt remove apache2 apache2-data apache2-utils apt install php php-common php-fpm php-mysql php-gmp php-xml php-xmlrpc php-curl php-mbstring php-gd php-dev php-imap php-opcache php-readline php-soap php-zip php-intl php-cli php-bcmath -y systemctl enable php8.3-fpm.service systemctl restart php8.3-fpm.service
systemctl enable ssh.service systemctl start ssh.service systemctl enable chrony.service systemctl start chrony.service systemctl enable nginx.service systemctl start nginx.service systemctl enable mariadb.service systemctl start mariadb.service systemctl enable firewalld.service systemctl start firewalld.service systemctl enable php8.3-fpm.service systemctl start php8.3-fpm.service
Para renovar os certificados digitais automaticamente utilizando o agendamento pelo Cron no Linux, basta inserir no crontab, digitando o comando:
crontab -e
e adicionar a seguinte linha:
0 12 * * * /usr/bin/certbot renew --quiet
reiniciar o crond:
service cron restart
Criar um usuário phpmyadmin no MySQL:
mysql -u root -p CREATE DATABASE phpmyadmin; CREATE USER phpmyadmin@localhost IDENTIFIED BY 'senha'; GRANT ALL PRIVILEGES ON phpmyadmin.* TO phpmyadmin@localhost; FLUSH PRIVILEGES; exit
Utilizar a mesma senha do usuário phpmyadmin que foi criado, no instalador do phpMyAdmin.
Executar o comando:
apt install phpmyadmin -y
Na tela do instalador, selecionar não selecionar nenhuma opção de web service.
Depois editar o arquivo conf do NGINX, incluindo o acesso ao diretório do phpMyAdmin:
location /admindb {
index index.php;
alias /usr/share/phpmyadmin/;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
Caso queira desabilitar o DNS interno do Ubuntu 24.04 e utilizar um servidor de DNS externo do provedor ou datacenter.
systemctl disable systemd-resolved.service systemctl stop systemd-resolved.service cp /etc/resolv.conf /tmp/resolv.conf rm /etc/resolv.conf cp /tmp/resolv.conf /etc/resolv.conf chown root:root /etc/resolv.conf chmod 644 /etc/resolv.conf