-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
70 lines (55 loc) · 1.53 KB
/
setup.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
#!/bin/bash
# Request user input
echo "Please enter your domain (example.com):"
read DOMAIN
echo "Please enter your desired MariaDB database name:"
read DATABASE
echo "Please enter your desired MariaDB username:"
read USER
echo "Please enter your desired MariaDB password:"
read PASSWORD
# Update system packages
sudo apt update
sudo apt upgrade -y
# Install Nginx
sudo apt install nginx -y
# Install MariaDB
sudo apt install mariadb-server -y
# Install PHP and its modules
sudo apt install php-fpm php-mysql -y
# Create Nginx server block file
sudo bash -c 'cat > /etc/nginx/sites-available/${DOMAIN} <<EOF
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name ${DOMAIN};
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF'
# Enable the site
sudo ln -s /etc/nginx/sites-available/${DOMAIN} /etc/nginx/sites-enabled/
# Test Nginx config
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
# Setup MariaDB database
sudo mysql -u root <<EOF
CREATE DATABASE ${DATABASE};
CREATE USER '${USER}'@'localhost' IDENTIFIED BY '${PASSWORD}';
GRANT ALL PRIVILEGES ON ${DATABASE}.* TO '${USER}'@'localhost';
FLUSH PRIVILEGES;
EOF
# Install Certbot for Let's Encrypt
sudo apt install certbot python3-certbot-nginx -y
# Obtain and install SSL certificates
sudo certbot --nginx -d ${DOMAIN}