-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.sh
218 lines (186 loc) · 7.88 KB
/
Install.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
#############################################################################################
#################################### VARIABLES ##############################################
#############################################################################################
# Set a random password for the database user and the Nextcloud admin user
DB_PASS=$(openssl rand -base64 12)
#############################################################################################
#################################### TESTS #################################################
#############################################################################################
# Check if the script is being executed with superuser privileges (root).
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as a superuser (sudo)."
exit
fi
# Check if the website is online
if ! wget --spider https://download.nextcloud.com/server/releases/latest.zip; then
echo "The website https://download.nextcloud.com is not online. Please check your internet connection."
exit 1
fi
#############################################################################################
#################################### LOG ####################################################
#############################################################################################
# Create a log file to record command outputs
LOG_FILE=/var/log/nextcloud_install.log
touch "$LOG_FILE"
exec > >(tee -a "$LOG_FILE")
exec 2>&1
#############################################################################################
#################################### STARTING INSTALLATION #################################
#############################################################################################
# Update the system.
apt-get update && apt-get -y full-upgrade
# Install PHP and necessary extensions
# Prompt the user to choose between Debian and Ubuntu
echo "Welcome to the PHP installer for Debian or Ubuntu!"
while true; do
read -p "Type '1' for Debian or '2' for Ubuntu to choose the desired distribution: " distro
case $distro in
1)
# Debian
echo "########## Installing PHP modules on Debian...##########"
apt-get install apt-transport-https lsb-release ca-certificates wget -y
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update
apt-get install unzip imagemagick php8.3 php8.3-{fpm,cli,curl,gd,mbstring,xml,zip,bz2,intl,bcmath,gmp,imagick,mysql} -y
break
;;
2)
# Ubuntu
echo "########## Installing PHP modules on Ubuntu...##########"
apt-get install software-properties-common -y
add-apt-repository ppa:ondrej/php -y
apt-get update
apt-get install unzip imagemagick php8.3 php8.3-{fpm,cli,curl,gd,mbstring,xml,zip,bz2,intl,bcmath,gmp,imagick,mysql} -y
break
;;
*)
echo "Invalid choice. Please type '1' or '2'."
;;
esac
done
# Install and configure the WebServer
# Prompt the user to choose between Apache and Nginx
echo "Welcome to the WebServer installer!"
while true; do
read -p "Type '1' for Apache or '2' for Nginx: " webserver
case $webserver in
1)
# Apache
echo "########## Installing and configuring Apache...##########"
# Install Apache
apt-get install apache2 apache2-utils -y
# Create the VirtualHost for Nextcloud
cd /etc/apache2/sites-available
curl -sSfL https://raw.githubusercontent.com/edsonsbj/Nextcloud/master/etc/apache/nextcloud.conf -o nextcloud.conf
# Perform Apache configurations
a2ensite nextcloud.conf
a2dissite 000-default.conf
a2enmod proxy_fcgi setenvif
a2enmod rewrite headers env dir mime setenvif ssl
systemctl restart apache2
break
;;
2)
# Nginx
echo "########## Installing and configuring Nginx...##########"
# Install Nginx
apt-get install nginx -y
# Create the VirtualHost for Nextcloud
cd /etc/nginx/sites-available
curl -sSfL https://raw.githubusercontent.com/edsonsbj/Nextcloud/master/etc/nginx/nextcloud.conf -o nextcloud
ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
sed -i 's/;clear_env = no/clear_env = no/g' /etc/php/8.3/fpm/pool.d/www.conf
sed -i 's/;cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /etc/php/8.3/fpm/php.ini
systemctl reload nginx
break
;;
*)
echo "Invalid choice. Please type '1' or '2'."
;;
esac
done
# Install MariaDB
apt-get install mariadb-server mariadb-client -y
# Install Redis
apt-get install redis-server php-redis -y
phpenmod redis
systemctl restart $webserver
# Configure PHP-FPM
sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/8.3/fpm/php.ini
sed -i 's/;date.timezone.*/date.timezone = America\/Sao_Paulo/' /etc/php/8.3/fpm/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 10240M/' /etc/php/8.3/fpm/php.ini
sed -i 's/post_max_size = .*/post_max_size = 10240M/' /etc/php/8.3/fpm/php.ini
# Restart and apply changes to WebServer and PHP
systemctl restart $webserver
systemctl restart php8.3-fpm
# Create the Database
mysql -e "CREATE DATABASE nextcloud;"
mysql -e "CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY '$DB_PASS';"
mysql -e "GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"
# Download and install Nextcloud
cd /var/www/
wget https://download.nextcloud.com/server/releases/latest.zip
unzip latest.zip
chown -R www-data:www-data /var/www/nextcloud
chmod -R 755 /var/www/nextcloud
mkdir -p /var/nextcloud_data
chown -R www-data:www-data /var/nextcloud_data
chmod -R 770 /var/nextcloud_data
# Configure Nextcloud
tee -a /var/www/nextcloud/config/autoconfig.php <<EOF
<?php
\$AUTOCONFIG = array(
'dbtype' => 'mysql',
'dbname' => 'nextcloud',
'dbuser' => 'nextcloud',
'dbpass' => '$DB_PASS',
'dbhost' => 'localhost',
'directory' => '/var/nextcloud_data',
);
EOF
tee -a /var/www/nextcloud/config/custom.config.php <<EOF
<?php
\$CONFIG = array (
'default_phone_region' => 'BR',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => 'localhost',
'port' => 6379,
),
'htaccess.RewriteBase' => '/',
'skeletondirectory' => '',
'enabledPreviewProviders' =>
array (
0 => 'OC\\Preview\\PNG',
1 => 'OC\\Preview\\JPEG',
2 => 'OC\\Preview\\GIF',
3 => 'OC\\Preview\\BMP',
4 => 'OC\\Preview\\XBitmap',
5 => 'OC\\Preview\\Movie',
6 => 'OC\\Preview\\PDF',
7 => 'OC\\Preview\\MP3',
8 => 'OC\\Preview\\TXT',
9 => 'OC\\Preview\\MarkDown',
10 => 'OC\\Preview\\Image',
11 => 'OC\\Preview\\HEIC',
12 => 'OC\\Preview\\TIFF',
),
'trashbin_retention_obligation' => 'auto,30',
'versions_retention_obligation' => 'auto,30',
);
EOF
#############################################################################################
############################### FINISHING THE INSTALLATION ##################################
#############################################################################################
# Add a task to the cron
(crontab -l 2>/dev/null; echo "*/5 * * * * sudo -u www-data php /var/www/nextcloud/cron.php") | crontab -
# Install ffmpeg to enable video thumbnails
apt-get install ffmpeg -y
echo "Nextcloud installation has been completed successfully!"