-
Notifications
You must be signed in to change notification settings - Fork 105
/
setup
195 lines (148 loc) · 5.22 KB
/
setup
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
#!/bin/bash
#/
#--------------------------------------------------------------------------
# Larasail Initial Setup
#--------------------------------------------------------------------------
#
# This file will setup the server with Nginx, PHP, and Mysql.
#
#/
. /etc/.larasail/includes/colors
. /etc/.larasail/includes/format
PHP="8.2"
MYSQL_SERVICE="MySQL"
MYSQL_PACKAGE="mysql-server"
INSTALL_REDIS=0
if [ "$2" = "php83" ] || [ "$3" = "php83" ]; then
PHP="8.3"
elif [ "$2" = "php81" ] || [ "$3" = "php81" ]; then
PHP="8.1"
elif [ "$2" = "php80" ] || [ "$3" = "php80" ]; then
PHP="8.0"
elif [ "$2" = "php74" ] || [ "$3" = "php74" ]; then
PHP="7.4"
elif [ "$2" = "php73" ] || [ "$3" = "php73" ]; then
PHP="7.3"
elif [ "$2" = "php72" ] || [ "$3" = "php72" ]; then
PHP="7.2"
elif [ "$2" = "php71" ] || [ "$3" = "php71" ]; then
PHP="7.1"
fi
if [ "$2" = "mariadb" ] || [ "$3" = "mariadb" ]; then
MYSQL_SERVICE="MariaDB"
MYSQL_PACKAGE="mariadb-server"
fi
if [ "$2" = "redis" ] || [ "$3" = "redis" ]; then
INSTALL_REDIS=1
fi
setsail
CHECK_SWAP=$(swapon -s | wc -l)
if [ $CHECK_SWAP -lt 1 ] ; then
bar
cyan "| Adding swap file "
bar
# Create a swap file
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Making the swap file permanent
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
fi
bar
cyan "| Installing Nginx ";
bar
sudo apt-get update
sudo apt-get -y install nginx
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo systemctl restart nginx
bar
cyan "| Installing $MYSQL_SERVICE ";
bar
MYSQLPASS=$(openssl rand -base64 32)
MYSQLUSER='dbadmin'
sudo apt-get update
if [ ! -d /etc/.larasail/tmp ]; then
mkdir /etc/.larasail/tmp
fi
echo '[client]' > /home/larasail/.my.cnf
echo "user=${MYSQLUSER}" >> /home/larasail/.my.cnf
echo "password='${MYSQLPASS}'" >> /home/larasail/.my.cnf
chmod 600 /home/larasail/.my.cnf
export DEBIAN_FRONTEND=noninteractive
echo "mysql-server-5.7 mysql-server/root_password password $MYSQLPASS" | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password $MYSQLPASS" | sudo debconf-set-selections
echo "mysql-server mysql-server/root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
echo "mysql-server mysql-server/re-root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
echo "mysql-server-8.0 mysql-server/root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
echo "mysql-server-8.0 mysql-server/re-root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
if [ "$2" = "mariadb" ] || [ "$3" = "mariadb" ]; then
echo "mariadb-server-10.3 mysql-server/root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
echo "mariadb-server-10.3 mysql-server/re-root-pass password ${MYSQLPASS}"|sudo debconf-set-selections
fi
sudo apt-get install -y ${MYSQL_PACKAGE}
sudo service mysql start
sudo mysql -uroot -p${MYSQLPASS} -e "CREATE USER ${MYSQLUSER}@localhost IDENTIFIED BY '${MYSQLPASS}'; GRANT ALL PRIVILEGES ON *.* TO ${MYSQLUSER}@localhost WITH GRANT OPTION;"
# Get current client IP address
CLIENT_IP=$(echo $SSH_CLIENT | awk '{ print $1}')
# To enable 3306 ports in order to connect to database via Sequel Pro, run:
# sudo ufw allow from ${CLIENT_IP}/32 to any port 3306
bar
cyan "| Installing PHP $PHP and all necessary files";
bar
sudo apt-get update
sudo apt-get install -y language-pack-en-base
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get install -y unzip
sudo apt-get install -y php-cli
sudo apt-get install -y php$PHP-cli php$PHP-common php$PHP-mysql php$PHP-gd php$PHP-mysql php$PHP-curl php$PHP-mbstring php$PHP-xml php$PHP-zip php$PHP-fpm php$PHP-sqlite3 php$PHP-intl curl git
sudo rm /usr/bin/php
sudo ln -s /usr/bin/php$PHP /usr/bin/php
bar
cyan "| Updating Permissions "
bar
sudo chown -R larasail:larasail /var/www
bar
cyan "| Installing Composer ";
bar
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
bar
cyan "| Installing npm"
bar
curl -sL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs
bar
cyan "| Adding the Laravel Installer "
bar
sudo chown -R $USER:$USER ~/.composer/
composer global require "laravel/installer"
bar
cyan "| Installing certbot ";
bar
sudo apt-get install -y python3 python3-venv libaugeas0 python3-pip
#Remove certbot in case it is already installed from the repository/ppa to avoid conflict
sudo apt-get remove --purge certbot python3-certbot-nginx
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo rm -f /usr/bin/certbot
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
#Set up automatic certificate renewal
echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
if [ $INSTALL_REDIS -eq 1 ] ; then
bar
cyan "| Installing Redis"
bar
sudo apt -y install redis-server
fi
setsail
bar
cyan "| Happy Sailing! "
bar