Skip to content

Instantly share code, notes, and snippets.

@mfcodeworks
Last active November 8, 2018 05:19
Show Gist options
  • Save mfcodeworks/f2931d2b405bd5d87a2db3f5e3a94d6b to your computer and use it in GitHub Desktop.
Save mfcodeworks/f2931d2b405bd5d87a2db3f5e3a94d6b to your computer and use it in GitHub Desktop.
Install Nextcloud server for Debian/Ubuntu
#!/bin/bash
read -p $'What should the new nextcloud mysql user account be called?\n' mysql_nextcloud_user
read -sp $'What would you like the new nextcloud MySQL password to be?\n' mysql_nextcloud_pass
read -p "What is the domain for the Nextcloud server? [Example: cloud.mydomain.com]\n" nextcloud_server_name
read -sp $'What is the current MySQL password? (If no password is entered MySQL will prompt for password)\n' mysql_curr_pass
sudo mysql -u root -p$mysql_curr_pass -e "CREATE DATABASE IF NOT EXISTS nextcloud; USE nextcloud; CREATE USER IF NOT EXISTS '"$mysql_nextcloud_user"'@'localhost' IDENTIFIED BY '"$mysql_nextcloud_pass"'; GRANT ALL ON nextcloud.* TO '"$mysql_nextcloud_user"'@'localhost' IDENTIFIED BY '"$mysql_nextcloud_pass"' WITH GRANT OPTION; FLUSH PRIVILEGES;"
sudo apt install zip unzip -y
mkdir temp
cd temp
wget https://download.nextcloud.com/server/releases/nextcloud-14.0.3.zip
unzip nextcloud-14.0.3.zip
sudo mv nextcloud /var/www
cd ..
sudo rm -rf temp
sudo chown -R www-data:www-data /var/www/nextcloud/
sudo chmod -R 755 /var/www/nextcloud/
sudo mkdir /opt/nextcloud
sudo chown -R www-data:www-data /opt/nextcloud
sudo chmod -R 755 /opt/nextcloud
sudo bash -c "cat > /etc/apache2/sites-available/nextcloud.conf << 'EOL'
<VirtualHost *:80>
DocumentRoot /var/www/nextcloud
ServerName "$nextcloud_server_name"
<Directory /var/www/nextcloud>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOL"
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl restart apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment