Nextcloud - treverehrfurth/old-scripts GitHub Wiki
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
- Go to Control Panel > Programs > Turn Windows Feature On or Off
-
Download Ubuntu 18.04 LTS from the Microsoft Store
-
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
-
Download and install Nextcloud Server by visiting the official download page.
-
Right click on the Download button and copy the link address.
-
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
-
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
-
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/
-
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
-
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
-
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
-
Go to http://localhost/nextcloud or http:///nextcloud.
-
Enter username and password for account and the database server and password we used earlier. server and server.
- Open Windows Defender Firewall with Advanced Security
- Go to Inbound Rules
- Select Port
- Do TCP and for Specific Local Ports put 80 and hit Next
- Select **Allow the connection and hit next
- Hit Next again
- Name it like Port 80 TCP and click Finish
- Repeate for another port 80 with UDP in step 4
- Then repeat both TCP and UDP for the Outbound Rules in Step 1 10 Then repeat all of these rules with port 443
- Now port forward your router with 80 and 443 for TCP and UDP
-
Port forward TCP and UDP for ports 80 and 443
-
Edit config to add all trusted domains
C:\Users\<pcname>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html\nextcloud\config
- 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
-
Click the icon at the top right and select "Apps".
-
Enable
External storage support
. Type in your admin password to confirm. -
Click the icon at the top right and select "Settings".
-
Click "External storages" under "Administration".
-
For each folder you want to add, set the following:
-
Folder name: your preference.
-
External storage:
local
. -
Authentication: your preference (default is
None
). -
Configuration:
/mnt/c/TreCloud
(make sure this path already exists; you could even share your entire/mnt/c/
path). -
Available for: your preference (default is blank - for all users).
-
Press the checkmark to save.
-
-
To allow sharing of external storage files and folder, select the elipses (3 dots) on the external storage page and select Enable Sharing
- Run Ubuntu
- Open task manager
- Open Ubuntu process
- Right click .exe and Open File Location
- Send to desktop
- Open file explorer, type shell:startup and press enter
- Drag into folder
-
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
-
Create Apache2 startup script. In Ubuntu.
echo "service apache2 start" >> ~/.local/bin/start_apache2.sh chmod +x ~/.local/bin/start_apache2.sh
-
Enable sudo privelages
sudo visudo
-
Make sure this is under
#User privilege specification
root ALL=(ALL:ALL) ALL
-
Make sure this is under
#Members of the admin group may gain root privileges
%admin ALL=(ALL:ALL) ALL
-
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
-
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
-
Create task to start at windows login
-
Open Task Scheduler
-
Click Create Task...
-
Name the task Start Mysql
-
Under the Triggers tab click New...
-
In the Begin the task dropdown, select At log on
-
Select Any user
-
Under the Actions tab click New...
-
Pick Start a program for the action type then enter this for the program to run
C:\(PC_Name)\System32\bash.exe
- 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"
- Repeat for apache2
-
-
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/
-
Make sure MySQL and Apache2 are stopped. Close out of Ubuntu.
-
Edit 2 lines in config
Location
C:\Users\<pcname>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\var\www\html\nextcloud\config
-
Edit
nextcloud
in these two files to whatever you want.'datadirectory' => '/var/www/html/nextcloud/data',
'overwrite.cli.url' => 'http://localhost/nextcloud',
-
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
- Open Ubuntu and start MySQL and then Apache2, then use websitename.com/newname