Nextcloud - treverehrfurth/old-scripts GitHub Wiki

  1. Introduction
  2. Install WSL, Apache, and MySQL
    1. Domain
    2. Install
  3. Install Nextcloud
  4. Configure
    1. Initial Configure
    2. Port Forward and Firewall
    3. Remote Access
    4. Default Files
    5. Adding Storage
    6. Start Ubuntu on Windows Login
    7. Automate MySQL and Apache2 Startups
    8. OneDrive Workaround
    9. Custom URL

1. Introduction

Nextcloud is a free, open-source, self-hosted file sharing solution, that functions similarly to Dropbox.

Note: This tutorial will show how to install Nextcloud on Windows as well as Linux

2. Install WSL, Apache, and MySQL

  1. Go to Control Panel > Programs > Turn Windows Feature On or Off

  1. Download Ubuntu 18.04 LTS from the Microsoft Store

  2. Run the following commands to install Apache along with MySQL and PHP 7.2

    sudo apt-get update
    sudo apt-get install apache2
    sudo apt-get install mysql-server
    sudo apt-get install php7.2 apache2 mysql-server libapache2-mod-php7.2
    sudo apt-get install php7.2-gd php7.2-json php7.2-mysql php7.2-curl php7.2-mbstring
    sudo apt-get install php7.2-intl php-imagick php7.2-xml php7.2-zip php7.2-dom
    

3. Install Nextcloud

  1. Download and install Nextcloud Server by visiting the official download page.

  2. Right click on the Download button and copy the link address.

  3. Go back to Ubuntu (WSL) and type wget then space, then right click to past the link. It will look something like this

    wget https://download.nextcloud.com/server/releases/nextcloud-15.0.5.zip
    
  4. Extract Nextcloud server files

    sudo apt install unzip
    ls
    unzip nextcloud-15.0.5.zip
    

    Note: your version might be different, make sure what you are entering is for the version you have

  5. Copy Nexctloud files to Apache web directory

    sudo mv nextcloud /var/www/html/nextcloud/
    sudo mkdir /var/www/html/nextcloud/data/
    sudo chown -R www-data:www-data /var/www/html/nextcloud/
    sudo chmod -R 755 /var/www/html/nextcloud/
    
  6. Create a new configuration file called nextcloud.conf

    sudo nano /etc/apache2/sites-available/nextcloud.conf
    

    i. Add the following lines in the configuration file

    <VirtualHost *:80>
    
    DocumentRoot /var/www/html/nextcloud/
    
    Alias /nextcloud "/var/www/html/nextcloud/"
    
    <Directory /var/www/html/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
    <IfModule mod_dav.c>
    Dav off
    </IfModule>
    SetEnv HOME /var/www/html/nextcloud
    SetEnv HTTP_HOME /var/www/html/nextcloud
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    

    Note: To save and exit the files press CTRL+O and then CTRL+X and then ENTER

    ii. Enable the newly created site

    sudo service apache2 reload
    sudo a2ensite nextcloud.conf
    
  7. Enable the following modules for proper Nextcloud operations

    sudo a2enmod rewrite
    sudo a2enmod headers
    sudo a2enmod env
    sudo a2enmod dir
    sudo a2enmod setenvif
    sudo a2enmod mime
    

    Restart apache to make the installed modules effective

    sudo service apache2 stop
    sudo service apache2 start
    
  8. Create MySQL/MariaDB database for Nextcloud

    sudo service mysql start
    sudo mysql
    create database nextdb;
    GRANT ALL ON nextdb.* to 'server'@'localhost' IDENTIFIED BY 'server';
    FLUSH PRIVILEGES;
    exit
    

4. Configure

1. Initial Configure

  1. Go to http://localhost/nextcloud or http:///nextcloud.

  2. Enter username and password for account and the database server and password we used earlier. server and server.

2. Port Forward and Firewall

  1. Open Windows Defender Firewall with Advanced Security
  2. Go to Inbound Rules
  3. Select Port
  4. Do TCP and for Specific Local Ports put 80 and hit Next
  5. Select **Allow the connection and hit next
  6. Hit Next again
  7. Name it like Port 80 TCP and click Finish
  8. Repeate for another port 80 with UDP in step 4
  9. Then repeat both TCP and UDP for the Outbound Rules in Step 1 10 Then repeat all of these rules with port 443
  10. Now port forward your router with 80 and 443 for TCP and UDP

3. Remote Access

  1. Port forward TCP and UDP for ports 80 and 443

  2. Edit config to add all trusted domains

C:\Users\<pcname>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html\nextcloud\config

4. Default Files

  1. Files in this folder (or similar) will propagate on new users accounts. Change as desired.
C:\Users\<pcname>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html\nextcloud\core\skeleton

5. Adding Storage

  1. Click the icon at the top right and select "Apps".

  2. Enable External storage support. Type in your admin password to confirm.

  3. Click the icon at the top right and select "Settings".

  4. Click "External storages" under "Administration".

  5. For each folder you want to add, set the following:

    1. Folder name: your preference.

    2. External storage: local.

    3. Authentication: your preference (default is None).

    4. Configuration: /mnt/c/TreCloud (make sure this path already exists; you could even share your entire /mnt/c/ path).

    5. Available for: your preference (default is blank - for all users).

    6. Press the checkmark to save.

  6. To allow sharing of external storage files and folder, select the elipses (3 dots) on the external storage page and select Enable Sharing

6. Start Ubuntu on Windows Login

  1. Run Ubuntu
  2. Open task manager
  3. Open Ubuntu process
  4. Right click .exe and Open File Location

  1. Send to desktop

  1. Open file explorer, type shell:startup and press enter
  2. Drag into folder

7. Automate MySQL and Apache2 Startups

  1. Create MySQL startup script. In Ubuntu.

    mkdir -p ~/.local/bin/
    echo "service mysql start" >> ~/.local/bin/start_mysql.sh
    chmod +x ~/.local/bin/start_mysql.sh
    
  2. Create Apache2 startup script. In Ubuntu.

    echo "service apache2 start" >> ~/.local/bin/start_apache2.sh
    chmod +x ~/.local/bin/start_apache2.sh
    
  3. Enable sudo privelages

    sudo visudo
    
  4. Make sure this is under #User privilege specification

    root     ALL=(ALL:ALL) ALL
    
  5. Make sure this is under #Members of the admin group may gain root privileges

    %admin ALL=(ALL:ALL) ALL
    
  6. Make sure this is under #Allow members of group sudo to execute any command

    %sudo ALL=(ALL:ALL) ALL
    (server_name) ALL=(ALL) NOPASSWD:ALL
    
  7. Make sure this is under #Includedir /etc/sudoers.d

    (server_name) ALL=(root) NOPASSWD: /home/(server_name)/.local/bin/start_mysql.sh
    (server_name) ALL=(root) NOPASSWD: /home/(server_name)/.local/bin/start_apache2.sh
    

  8. Create task to start at windows login

    1. Open Task Scheduler

    2. Click Create Task...

    3. Name the task Start Mysql

    4. Under the Triggers tab click New...

    5. In the Begin the task dropdown, select At log on

    6. Select Any user

    7. Under the Actions tab click New...

    8. Pick Start a program for the action type then enter this for the program to run

    C:\(PC_Name)\System32\bash.exe
    
    1. Finally, as the last and most important step, at Add arguments set this argument string to run the command with
    -c "sudo ~/.local/bin/start_mysql.sh"
    
    1. Repeat for apache2

8. OneDrive Workaround

  1. For configuration location, find where your OneDrive folder is stored, most likely here _Note: My Windows 10 machine is called 'Server'

    /mnt/c/Users/Server/OneDrive/
    

9. Custom URL

  1. Make sure MySQL and Apache2 are stopped. Close out of Ubuntu.

  2. Edit 2 lines in config

    Location

C:\Users\<pcname>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html\nextcloud\config
  1. Edit nextcloud in these two files to whatever you want.

    'datadirectory' => '/var/www/html/nextcloud/data',

    'overwrite.cli.url' => 'http://localhost/nextcloud',

  2. Go to Nextcloud home folder and change the name of it to same name as above.

    Location

C:\Users\Server\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html
  1. Open Ubuntu and start MySQL and then Apache2, then use websitename.com/newname
⚠️ **GitHub.com Fallback** ⚠️