Nextcloud is an open source software for creating and using file hosting services. It has a lot of extra Calendar, Sync and Contacts features, apart from their file hosting features. It is a great free alternative to some popular services such as Google Drive, Dropbox, Box, etc.
In order to run Nextcloud on your VPS, the following requirements have to be installed:
- MySQL or MariaDB
- PHP 7.0 +
- Apache 2.4 with mod_php module
In this tutorial, we will install the latest version of Nextcloud on one of our CentOS 7 VPSes with MariaDB, PHP and Apache. If you want to use an Ubuntu VPS, check our tutorial on how to install Nextcloud on Ubuntu 16.04
Already using ownCloud? Check our tutorial on how to migrate from ownCloud to Nextcloud or get a VPS from us and we’ll do it for you, free of charge!
Update the system
First of all login to your CentOS 7 VPS via SSH as user root:
ssh root@IP_Address
and make sure that it is fully up to date:
yum -y update
Install MariaDB server
Nextcloud requires an empty database, so we will install MariaDB server:
yum -y install mariadb mariadb-server
Once it is installed, start MariaDB and enable it to start on boot:
systemctl start mariadb systemctl enable mariadb
and run the mysql_secure_installation
post-installation script to finish the MariaDB set-up:
mysql_secure_installation 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
Once MariaDB is installed, login to the database server as user root, and create database and user for Nextcloud:
mysql -u root -p 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
Install Apache Web Server
Next, we will install Apache web server:
yum install httpd -y
start Apache and make it start on boot:
systemctl start httpd.service systemctl enable httpd.service
Install PHP 7
The default PHP version on CentOS 7 is PHP 5.4. In this tutorial, we will install PHP version 7.
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-php70
and install PHP 7 and several PHP modules required by Nextcloud by executing the following command:
yum -y install php php-mysql php-pecl-zip php-xml php-mbstring php-gd
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 Loaded Configuration File: /etc/php.ini
In our case, we have to make changes to the /etc/php.ini file. We will 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
and restart the web server:
systemctl restart httpd
Install Nextcloud
Go to Nextcloud’s official website and download the latest stable release of the application
wget https://download.nextcloud.com/server/releases/nextcloud-11.0.2.zip
unpack the downloaded zip archive to the document root directory on your server
unzip nextcloud-11.0.2.zip -d /var/www/html/
Set the Apache user to be owner of the Nextcloud files
chown -R apache:apache /var/www/html/nextcloud/
Finally, access Nextcloud at http://yourIP/nextcloud . 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:
Database user: nextclouduser Database password: YOURPASSWORD Database name: nextcloud host: localhost