# Linux NextCloud

Nextcloud 10 , install on Debian 7

Welcome to my Nextcloud installation guide. We will setup Apache2, MariaDb and Nextcloud 10 on a Debian 7 System. I found a lot of manuals to install NextCloud on Ubuntu, sadly I couldn't find a good one for Debian. As it turned out, the process is pretty much the same.

I assume you already have set up a Debian server. We start with the database.

Database

Install

Here you can find a good Manual for the basic installation.

Config

We have to create a new database user and a new database

mysql -u root -p
CREATE DATABASE nextcloud;
CREATE USER nextcloud@localhost IDENTIFIED BY 'myNextCloudPassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO nextcloud@localhost;
EXIT

We need to change the BINLOG_FORMAT of your DBS. If we don't change it will run into this error during the nextcloud setup

open the maria db config file

nano /etc/mysql/my.cnf

Start looking for [mysqld]
Paste the code BINLOG_FORMAT = MIXED at the end of [mysqld]

binlog_format = mixed

Restart MariaDB

service mysql restart

Apache

Install
apt-get install apache2

Install the needed modules

apt-get install libapache2-mod-php5 php5-gd php5-json php5-mysql

As I want to integrate NextCloud with our Active Directory , I have to add one more

apt-get install php5-ldap 

We can add several packages to improve the performance

apt-get install php5-curl php5-intl php5-mcrypt
Config

On my system will only run Nextcloud. I want to make Nextcloud the default webpage. The page should be accessible with localhost. With Apache, it's pretty easy to configure.

Open the default host config file

nano /etc/apache2/sites-available/default.conf

You can easily erase everything and paste this code

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/nextcloud

        <Directory "/var/www/html/nextcloud">
                Options Indexes FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

This basically tells Apache to listen on Port 80 and show the webpage located in /var/www/nextcloud

Enable Apache modules

a2enmod rewrite headers env dir mime

Nextcloud

Install

Download the nextcloud installation files, move it to the www folder

cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.1.tar.bz2
tar -vxjf nextcloud-10.0.1.tar.bz2
mv nextcloud /var/www/
Permissions

We are not ready to start the setup.
Apache needs the permission to write to the Nextcloud config directory.
Permissions needed
Nextcloud provides a script to easily change all the permissions.
Let's create a script file

nano /tmp/changeNextcloudPermissions.sh

and paste this code

#!/bin/bash
ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'

printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater

printf "chmod Files and Directories\n"
find ${ocpath} -type f -print0 | xargs -0 chmod 0640
find ${ocpath} -type d -print0 | xargs -0 chmod 0750

printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chmod +x ${ocpath}/occ

printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
 then
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
 then
  chmod 0644 ${ocpath}/data/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

If you create the file you can not execute it right away. We need to add permissions for execution

chmod +x /tmp/changeNextcloudPermissions.sh

run the script

cd /tmp
./changeNextcloudPermissions.sh

Restart Apache to apply the changes

service apache2 reload

The permissions have changed. Now Apache has enough permissions. The setup dialog appears

Setup

Enter the needed credentials. That's it, have fun with your NextCloud.

Nextcloud 10, HTTPS
Icinga2, Upgrade failed

Share it

Written by

Martin Schmidli

Welcome! My focus these days is mainly on Modern Workplace, based on Microsoft 365 solutions. Feel free to reach out if you have any questions!

Comments