A lot of use cloud services. Cloud services can be used to sync between devices, but is also good for cooperation with colleagues. Most of us use clouds own by others, such as Google drive, Box or Dropbox. I for myself prefer to handle the cloud myself. In my opinion it should be easy to set up a server on an old computer and run your own cloud. I do that, I use a server program called Nextcloud, which I like very much. But I must say, as an amateur, it has not always been easy. There are manuals, one of the best of course is Nextclouds own. But the problem is the manuals are not always easy and that Nextcloud by it self is not enough. You also need to set up apache, mysql/mariadb and php (also called LAMP — Linux, Apache, Mysql, PHP). If you use an OS using SELinux you also need to handle this. You should also, for security, fix SSL-certificate. Unfortunately, I have not found a tutorial with all these collected together. Quite often tutorials on the internet require that you understand for example Apache.
In this article I will show you how to set up Nextcloud on CentOS 7. The Nextcloud version used is 16. Things may change between versions. Further, this is in no way a complete tutorial. But it will make you up an going. I would also recommend anyone finding this to not only using this article, but also look at Nextclouds manual for administrators.
The first thing you need is of course a computer that can be used as a server. An old laptop will most likely be enough, but you can also build one if you want to. Then you have to install CentOS on that computer. This article is not about installing CentOS — but it is really easy. You can download CentOS here. Then you burn it on a USB-stick. There are several ways to do this, but if you use a Linux distro with gnome you can use the disk application (use the restore image function).
All the commands here require that you are root. To become root you open the terminal and write
Enter your password and you should be root.
The first thing you need to do after installing CentOS is to update the system. CentOS use yum as package manager. If you use the -y flag you don’t need to confirm the update. If you want to confirm just skip the -y flag.
yum -y update
To be able to install LAMP you need the yum-utils packages (see more about it here). For me the yum-utils packages was already installed on the system. But to be on the safe side try to install the packages:
Install the ‘yum-utils’ package on your server to use ‘yum-config-manager’.
sudo yum -y install yum-utils
In this article I will show how to use wget to fetch Nextcloud from internet. Wget is not installed on the system, so you have to install it. I also installed Nano, a text editor. But if you know how to use vi and feel comfortable with that text editor, you of course do not need install nano.
yum -y install nano wget
I use mariadb instead of MySQL. MariaDB is a community developed fork of MySQL. But you can use either one. The commands used here are the same. The first thing we need to do is to install MariaDB.
yum -y install mariadb mariadb-server
After installing MariaDB you have to start it and enable it. MariaDB works as a service, and to start means just that. To enable MariaDB ensures that the service starts when the computer starts. This is handled by systemd.
systemctl start mariadb.service systemctl enable mariadb.service
To make settings and secure the mysql-data base you need to run the mysql-secure-installation. In the terminal run:
… use the following set up:
Enter current password for root (enter for none): ENTER Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
After you have done this you can log into MariaDB and create database and user:
mysql -u root -p
You will be prompted to enter your password (which you create when running mysqlsecureinstallation)
In MariaDB you create database and user. Change user to whatever (admin for example):
MariaDB [(none)]> CREATE DATABASE nextcloud; MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'YOURPASSWORD'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> \q
Next you have to install the Apache Web Server. In the terminal:
yum install httpd -y
You have to configure a virtual host. Create a new file (here using nano) with the following set up. In the terminal:
The following set up works fine.
<VirtualHost *:80> DocumentRoot /var/www/html/ ServerName your.server.com <Directory "/var/www/html/"> Require all granted AllowOverride All Options FollowSymLinks MultiViews </Directory> </VirtualHost>
Start and enable Apache.
systemctl start httpd.service systemctl enable httpd.service
Install PHP 7 — be shure to install at least php7.3. To do that you need to install the epel-release repository.
yum install epel-release
Install Remi and EPEL repository packages:
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Enable Remi PHP 7 repo:
yum-config-manager --enable remi-php73
Install PHP and several PHP modules required by Nextcloud by executing the following command:
yum -y install php php73-php-fpm php-mysql php-pecl-zip php-xml php-mbstring php-gd
It is a good practice to check what version is running:
Next, open the PHP configuration file and increase the upload file size. You can find the location of the PHP configuration file by executing the following command:
php --ini |grep Loaded
This is what i saw form the command:
Loaded Configuration File: /etc/php.ini
Thus, we have to make changes to the /etc/php.ini file. Here we increase the default upload limit to 100 MB. You can set the values according to your needs. Run the following commands:
sed -i "s/post_max_size = 8M/post_max_size = 100M/" /etc/php.ini sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/" /etc/php.ini
Create a file called info.php within the var/www/html directory with the following content:
<?php phpinfo(); ?>
Restart the web server:
systemctl restart httpd
Install Nextcloud 16
Go to Nextcloud’s official website and download the latest stable release of the application
Unpack the downloaded zip archive to the document root directory on your server
unzip nextcloud-16.0.3.zip -d /var/www/html/
Create data in the nextcloud directory
Set the Apache user to be owner of the Nextcloud files
chown -R apache:apache /var/www/html/*
Settings in selinux
chcon -t httpd_sys_rw_content_t /var/www/html/nextcloud/ -R
Selinux can be totally disabled — but it is not necessary. To disable selinux change enabled to disabled in /etc/selinux/config.
nano /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. *SELINUX=disabled* # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
Finally, access Nextcloud at http://yourip/nextcloud (to see your ip-adress run ip addr in the terminal). The installation wizard will check if all requirements and if everything is OK, you will be prompted to create your admin user and select storage and database. Select MySQL/MariaDB as database and enter the details for the database we created earlier in this post:
User: nextclouduser Database password: YOURPASSWORD Database name: nextcloud host: localhost