How to Install and Configure Nextcloud with Apache on CentOS 7

By 

Updated on

3 min read

Install and Configure Nextcloud 14 on CentOS 7

Nextcloud is an open-source, self-hosted file share and collaboration platform, similar to Dropbox. It comes bundled with media player, calendar and contact management.

Nextcloud is extensible via apps and has desktop and mobile clients for all major platforms.

This tutorial will walk you through the process of installing and configuring Nextcloud with Apache on a CentOS 7 system.

Prerequisites

Before starting with the tutorial, make sure you are logged in as a user with sudo privileges .

Step 1: Creating MySQL Database

NextCloud can use SQLite, PostgreSQL or MySQL database to store all its data.

In this tutorial we will use MySQL as the database of choice.

If you already don’t have MySQL or MariaDB installed on your CentOS server you can install by following one of the instructions below:

Start by logging to the MySQL shell by typing the following command:

Terminal
sudo mysql

Run the following SQL statements to create a database named nextcloud, user named nextclouduser and to grant the necessary privileges to the user:

Terminal
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'change-with-strong-password';
FLUSH PRIVILEGES;
EXIT;

Step 2: Installing PHP and Apache

Nextcloud is a PHP application. CentOS 7 ships with PHP 5.4 which is not supported by Nextcloud.

We will install PHP 7.2 from the Remi repository. The commands below will enable EPEL and Remi repositories:

Terminal
sudo yum install epel-release yum-utils
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php72

Once the repositories are enabled install Apache PHP 7.2 and all required PHP extensions with the following command:

Terminal
sudo yum install httpd php php-gd php-json php-mysql php-curl php-mbstring php-intl php-mcrypt php-imagick php-xml php-zip

Step 3: Configuring firewall

If you are running Firewall on your CentOS server, you’ll need to open HTTP (80) and HTTPS (443) ports.

You can do that by running the following commands:

Terminal
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Step 4: Downloading Nextcloud

Download the latest version of Nextcloud from the Nextcloud download page with wget :

Terminal
wget -P /tmp https://download.nextcloud.com/server/releases/nextcloud-15.0.0.zip
Info
At the time of writing this article, the latest version of Nextcloud is version 15.0.0.

Once the download is complete, extract the archive to the /var/www directory:

Terminal
sudo unzip /tmp/nextcloud-15.0.0.zip  -d /var/www

Set the correct ownership so that the Apache web server can have full access to the Nextcloud’s files and directories:

output
sudo chown -R apache: /var/www/nextcloud

Step 5: Configure Apache

Open your text editor and create the following Apache configuration file.

Terminal
sudo nano /etc/httpd/conf.d/nextcloud.conf
/etc/httpd/conf.d/nextcloud.confapache
Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/nextcloud
 SetEnv HTTP_HOME /var/www/nextcloud

</Directory>

Activate the changes by restarting Apache service:

Terminal
sudo systemctl restart httpd

Step 6: Installing Nextcloud

Now that Nextcloud is downloaded and all necessary services are configured open you browser and start the Nextcloud installation by visiting your server’s domain name or IP address followed by /nextcloud :

url
http://domain_name_or_ip_address/nextcloud

You will be presented with the Nextcloud setup page.

Install Nextcloud CentOS

Enter your desired admin username and password and the MySQL user and database details you previously created.

Click on the Finish setup button and once the installation process is completed you will be redirected to the Nextcloud dashboard logged in as admin user.

Nextcloud dashboard

Conclusion

You have learned how to install and configure Nextcloud on your CentOS 7 machine. If you have a domain name associated with your Nextcloud server, you can follow this guide and secure your Apache with Let’s Encrypt .

To find more information about how to manage your Nextcloud instance visit the Nextcloud documentation page.

If you have any questions, please leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page