# Installing Nextcloud on Linux (Debian 10)

1. Log into the Debian device
2. Run the following commands in a terminal:
   # update repositories and install any available software updates
   sudo apt-get update
   sudo apt-get upgrade
   # install Apache HTTPD and MySQL
   sudo apt-get install apache2 mariadb-server mariadb-client
   # install PHP components
   sudo apt-get install php7.3 libapache2-mod-php7.3 php7.3-curl php7.3-intl php7.3-json php7.3-gd php7.3-mbstring php7.3-mysql php7.3-xml php7.3-zip
   # configure the MySQL database
   sudo su
   mysql_secure_installation
3. Press Enter to login as root
4. Type Y and press Enter to set a root password, type the password twice to confirm
5. Type Y and press Enter to remove anonymous users
6. Type Y and press Enter to disallow root login remotely
7. Type Y and press Enter to remove the test database
8. Type Y and press Enter to reload privilege tables
9. Run the following command to login into MySQL:
   mysql -u root -p
10. Authenticate with the root password set earlier
11. Run the following commands to create the Nextcloud database and database user
    NOTE: update 'password' with a secure password
    MariaDB [(none)]> CREATE DATABASE nextclouddb;
    MariaDB [(none)]> GRANT ALL ON nextclouddb.* to 'nextclouduser'@'localhost' IDENTIFIED BY 'N3xtCl0ud!';
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> EXIT;
    exit
12. Continue with the following commands to download and extract Nextcloud in the Apache webroot
    # download latest nextcloud version
    sudo wget https://download.nextcloud.com/server/releases/latest.zip
    # extract latest.zip
    sudo unzip latest.zip -d /var/www
    # set the owner of the new nextcloud directory to www-data
    sudo chown -R www-data:www-data /var/www/nextcloud
    # create a new nextcloud.conf file to configure the site
    sudo nano /etc/apache2/sites-available/nextcloud.conf
13. Paste the following configuration into nextcloud.conf

    Alias /nextcloud "/var/www/nextcloud/"
    <directory /var/www/html/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
    Dav off
    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud
    </directory>

14. Press CTRL+O, Enter, CTRL+X to write the changes to nextcloud.conf
15. Continue with the following commands to enable the site and restart Apache:
    # enable the Nextcloud site and required PHP modules
    sudo a2ensite nextcloud
    sudo a2enmod rewrite headers env dir mime dav
    # restart apache2 service for the changes to take effect
    sudo systemctl restart apache2
16. Open a web browser and navigate to http://DNSorIP/nextcloud
17. The Nextcloud setup screen should be displayed
18. Enter a username and password
19. Click the storage & database link to expand the section
20. Select MySQL and fill out the database connetion information as follows

    username: nextclouduser
    password: N3xtCl0ud!
    database name: nextclouddb
    database host: localhost

21. Click Finish Setup
22. After a few moments of setup Nextcloud will be up and running