-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
173 lines (147 loc) · 4.99 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
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
#!/usr/bin/env bash
# author: Ferrariic <[email protected]>
# Please report issues on the issues page of this repository.
# THIS SCRIPT CAN BE USED TO SET UP A DEVELOPMENT ENVIRONMENT ON UBUNTU 22.04
### SYSTEM VARIABLES
ip=$(hostname -I | cut -f1 -d' ')
###
echo "This script will install the following"
echo "* Nginx"
echo "* Mysql & Open it to the world on port 3306"
echo "* Php"
echo "* Docker"
echo "* Docker-Compose"
echo "* Phpmyadmin & Open it to the world on http://$ip/phpmyadmin "
echo "* Redis & Open it to the world on port 6379"
echo "--------------------------------"
echo "Mysql 'root' password:"
read rootpassword
echo "Mysql 'username':"
read username
echo "Mysql '$username' password:"
read userpassword
echo "Redis password:"
read redispassword
echo "Are the following values correct? (Y/n)"
echo "Mysql : root@localhost : $rootpassword"
echo "Mysql : '$username'@'%' : $userpassword"
echo "Redis : $rootpassword"
read response
if [ $response == 'n' ]
then
echo "Exiting installation"
exit
else
echo "Installing packages..."
fi
echo "INSTALLING NGINX"
sudo apt update
sudo apt install nginx
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 22 #ssh
sudo ufw allow 80 # http
sudo ufw allow 443 # https
sudo ufw allow 5500 # NeverScapeAlone main
sudo ufw allow 5501 # NeverScapeAlone development
sudo ufw allow 3306 # Mysql
sudo ufw allow 6379 # Redis
echo y | sudo ufw enable
sudo ufw reload
echo "INSTALLING MYSQL"
echo Y | sudo apt install mysql-server
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$rootpassword';"
sudo mysql -e "FLUSH PRIVILEGES;"
echo "INSTALLING PHP"
sudo apt install php-fpm php-mysql
sudo bash -c 'cat << EOF > /etc/nginx/sites-available/site
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name site;
location / {
try_files \$uri \$uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF'
sudo ln -s /etc/nginx/sites-available/site /etc/nginx/sites-enabled/
sudo unlink /etc/nginx/sites-enabled/default
sudo systemctl reload nginx
echo "INSTALLING DOCKER"
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
echo y | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo service docker start
sudo docker run hello-world
echo "INSTALLING DOCKER-COMPOSE"
sudo apt install docker-compose
echo "OPENING MYSQL TO THE WORLD"
sudo sed -i 's/bind-address = 127.0.0.1/bind-address = $ip/' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo service mysql restart
sudo mysql -u root -p$rootpassword -e "CREATE USER '$username'@'%' IDENTIFIED BY '$userpassword';"
sudo mysql -u root -p$rootpassword -e "GRANT ALL PRIVILEGES ON *.* TO '$username'@'%';"
sudo mysql -u root -p$rootpassword -e "FLUSH PRIVILEGES;"
sudo systemctl restart nginx
echo "INSTALLING PHPMYADMIN"
sudo apt install phpmyadmin
sudo bash -c 'cat << EOF > /etc/nginx/snippets/phpmyadmin.conf
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files \$uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
EOF'
sudo bash -c 'cat << EOF > /etc/nginx/sites-available/site
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name site;
include snippets/phpmyadmin.conf;
location / {
try_files \$uri \$uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF'
sudo service nginx restart
echo "INSTALLING REDIS"
sudo apt update
sudo apt install redis-server
sudo sed -i 's/supervised no/supervised systemd/' /etc/redis/redis.conf
sudo sed -i 's/bind 127.0.0.1 ::1/bind 0.0.0.0/' /etc/redis/redis.conf
sudo sed -i 's/# requirepass foobared/requirepass $redispassword/' /etc/redis/redis.conf
sudo systemctl restart redis.service