I have a NAS running OMV which also hosts the PLEX media server, which serves all my media needs, but when it comes to documents and software which I always download a lot, it is always a cumbersome process to manage them all. I download lots of datasheets and software for different projects which I tend to store to avoid the repetitive download of the same items. So I thought of trying out som one premise file hosting solutions like OwnCloud and NextCloud. I checked both and settled with Next Cloud. I installed it to a spare Raspberry Pi laying around, so this post is all about setting up NextCloud in Raspberry Pi.
NextCloud requires an apache web server and a database to work along with some PHP modules. It supports SQLite, MySQL, and PostgresSQL. Over here I am going to use MySQL. You can use any database of your choice but yes SQLite is not recommended for production use or any scenario where you are thinking of using with a large number of files.
So we will strat with installation of Apache, PHP, MySQl.
sudo apt-get update && sudo apt-get upgrade sudo apt-get install apache2
If apache got installed sucessfully, you can browse the IP(http://<pi_ip_address>/
) of the Pi and can see a page like this,
Now lets install PHP and MySQL.
sudo apt-get install php libapache2-mod-php mariadb-server mariadb-client php-mysql
After installation of MySQL is done, we need to seup a password for mysql root user, for that type in sudo mysql_secure_installation
.
After PHP and MYSQL are installed, we need to install some of the PHP modules, NExtCloud is dependent on. but before that check the version of the PHP installed by typing php --version
If the version is not 7.3, the following command has to be changed based on the version it returned, just replace 7.3 with the other one.
sudo apt-get install php7.3-curl php7.3-dom php7.3-gd php7.3-mbstring php7.3-zip php7.3-bz2 php7.3-intl php7.3-ldap php7.3-smbclient php7.3-imap php7.3-ftp php7.3-gmp php7.3-imagick
Now lets restart apche sudo systemctl restart apache2
Set the proper permissiins to /var/www
folder using the following commands,
sudo chown www-data:www-data -R /var/www/ #sudo chgrp -R www-data /var/www/ sudo chmod -R 755 /var/www/ sudo chmod g+s /var/www/ sudo chmod g+w /var/www/
Now create a file phpinfo.php
inside html folder with the following content,
sudo nano /var/www/html/phpinfo.php
<?php echo phpinfo(); ?>
When you navigate to http://<pi_ip_address>/phpinfo.php
you wuill see a page like the below one,
Over here you can check if the dependent modules are available or not.
Apache Web server configuration for NextCloud:-
Create a new apache configuration file for NextCloud,
sudo nano /etc/apache2/sites-available/nextcloud.conf
Add the following contents to the file,
Alias /nextcloud "/var/www/nextcloud/" <Directory /var/www/nextcloud/> Require all granted AllowOverride All Options FollowSymLinks MultiViews <IfModule mod_dav.c> Dav off </IfModule> </Directory>
Now load the conf file and also apache,
sudo a2ensite nextcloud.conf sudo systemctl restart apache2
Additionally you need to enable the following apache configs, just run the following commands
sudo a2enmod rewrite sudo a2enmod headers sudo a2enmod env sudo a2enmod dir sudo a2enmod mime
Now we are all ready to install nextCloud.
Create a new folder nextcloud
inside /var/www/
.
mkdir /var/www/nextcloud/
Download setup-nextcloud.php
file from https://nextcloud.com/install/#instructions-server
web-installer section. Copy the file link and replace in the following command.
sudo wget -P /var/www/nextcloud/ <file_link> sudo chmod 777 -R /var/www/nextcloud/
Ex. sudo wget -P /var/www/nextcloud/ https://download.nextcloud.com/server/installer/setup-nextcloud.php
After the file is downloaded, naviage to http://<ip_address_of_pi>/nextcloud/setup-nextcloud.php
, which will bring up the following interface.
Click on Next. Replace nextcloud with ‘.‘ in the input field and hit Next, now the installation will begin which may take some time. After the installation is done, you will see a screen like,
Click Next, the following page will open up, In here create the admin credentials for Nextcloud (Don’t Forget) and also select the database to be used, If you want to use SQLite it’s simple, in case of MySQL you need to provide DB connection details, You can create a user for Nextcloud in MySQL, but I will go with root one as my installation is going to have this database only,
In case you are having an issue with root user creds for MySQL, use the following commands,
$ sudo mysql -u root mysql> USE mysql; mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> exit; $ sudo systemctl restart mysql
So that’s all, you will be navigated to a welcome screen.
Now enjoy your file hosting system !!



Developer, Tinkere, a proud Dad.. love to spend my available time playing with Tech!!