cloud / nextcloud.sh
enemy7's picture
Create nextcloud.sh
c4fd5af
#!/bin/bash
# Update system packages
sudo apt update
sudo apt upgrade -y
# Install required packages
sudo apt install -y apache2 mariadb-server libapache2-mod-php7.4 php7.4-gd php7.4-json php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl php7.4-xml php7.4-zip php7.4-bz2 php7.4-common php7.4-cli php7.4-ldap php7.4-gmp
# Enable necessary Apache modules
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod env
sudo a2enmod dir
sudo a2enmod mime
# Create a database for Nextcloud
sudo mysql -u root -p <<EOF
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF
# Download and extract Nextcloud
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
tar -xjf latest.tar.bz2
sudo mv nextcloud /var/www/
sudo chown -R www-data:www-data /var/www/nextcloud
# Configure Apache virtual host
sudo tee /etc/apache2/sites-available/nextcloud.conf <<EOF
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/nextcloud
ServerName your_domain_or_ip_here
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<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>
</VirtualHost>
EOF
# Enable the Nextcloud virtual host
sudo a2ensite nextcloud.conf
# Restart Apache
sudo systemctl restart apache2
# Set up Nextcloud cron job
sudo -u www-data php /var/www/nextcloud/cron.php
# Clean up
rm latest.tar.bz2
echo "Nextcloud installation is complete. Access your Nextcloud instance by visiting http://your_domain_or_ip_here in your web browser."