×


Install NextCloud on Ubuntu 20.04 with Apache - Step by Step Process ?

Nextcloud is a cross-platform and opensource file hosting/storage platform that allows you to store, edit and share your files as well as manage other utilities such as calendars, notes, maps, and TODOs just to mention a few. NextCloud provides reliable self-hosted cloud services and comes off as a good substitute for platforms such as Box and DropBox.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related NextCloud queries on Ubuntu Linux Systems.
In this context, we shall look into how to install NextCloud on Ubuntu 20.04 Focal Fossa.

How to install NextCloud on Ubuntu?

Before proceeding with this installation task, ensure you have a regular user in the system configured with sudo privileges or use the root user account for your Server.
Then follow the steps given below.

1. Install LAMP server

Nextcloud is predominantly written in PHP and is accessed on the frontend from a browser. The first step dictates that we install the LAMP server before jumping into anything else.
LAMP is an acronym that includes Apache, which is a web server, MySQL or MariaDB database engines, and PHP scripting language.
To install the LAMP stack we shall run the command shown.

$ sudo apt install apache2 libapache2-mod-php php mariadb-server


2. Install additional PHP modules

i. Additional PHP modules are mandatory for Nextcloud installation to proceed.
They are quite a number, so invoke the command shown:

$ sudo apt install php-gd php-mysql php-curl php-json php-gmp php-bcmath php-xml php-mbstring php-intl php-imagick php-zip bzip2

ii. We need to make a few tweaks to the php.ini file which contains the PHP settings or configurations.

$ sudo vim /etc/php/7.4/apache2/php.ini

iii. First, set the memory limit from the default value to 512M as shown in the screenshot below.

memory_limit = 512M

iv. Also, set your timezone. For instance Oceania/Sydney
v. Now, restart the Apache webserver for the changes to be applied:

$ sudo systemctl restart apache2

vi. It would also be prudent to confirm that the webserver is up and running as shown.

$ sudo systemctl status apache2


3. Create a database for NextCloud

It's crucial to create a database for Nextcloud’s files and other data that will be saved post-installation.
i. So, access the MariaDB database engine as shown:

$ sudo mysql -u root -p

ii. Next, proceed and create the database and database user and assign the required privileges as provided in the commands below:

CREATE DATABASE nextcloud_db;
GRANT ALL ON nextcloud_db.* to 'nextcloud_user'@'localhost' IDENTIFIED BY 'userpassword';

iii. Save the changes to the database engine

FLUSH PRIVILEGES;

iv. And finally exit.

EXIT

The database is now configured. We are then going to download and configure NextCloud.

4. Download and configure NextCloud

NextCloud provides various installation methods such as running NextCloud as a virtual machine, or as a docker image.
i. However, we are going to install NextCloud manually.
We are going to grab the latest NextCloud zip file from NextCloud's official site.
At this point, the latest version in NextCloud 21.0.1

$ wget https://download.nextcloud.com/server/releases/nextcloud-21.0.1.zip

ii. Once the NextCloud zip file is complete, unzip the file in the /var/www/html path.

$ sudo unzip nextcloud-21.0.1.zip -d /var/www/html/

iii. Thereafter, set the directory permissions to www-data user and group as shown.

$ sudo chown -R www-data:www-data /var/www/html/nextcloud

iv. Once that is done, consider setting up the permissions as shown to give the read and execute permissions to the global users.

$ sudo chmod -R 775 /var/www/html/nextcloud

Now, Let's proceed and define a configuration file for NextCloud.

5. Create a configuration file for NextCloud

Next, we are going to define a configuration file that acts as a virtual host file for NextCloud.
i. So, proceed and create a nextcloud.conf configuration file as follows.

$ sudo vim /etc/apache2/sites-available/nextcloud.conf

For the ServerName attribute, provide the FQDN of your server or IP address if you don't have a domain name pointing to your IP.
ii. Add the lines shown below:

Alias /nextcloud "/var/www/html/nextcloud/"
<Directory /var/www/html/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
      <IfModule mod_dav.c>
        Dav off
      </IfModule>     

     SetEnv HOME /var/www/html/nextcloud
    SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>

iii. Save and exit the virtual host config file. Then enable it as follows:

$ sudo a2ensite nextcloud.conf

iv. Additionally, enable the Apache webserver modules that will be required later on:

$ sudo a2ensite rewrite headers dir mime env setenvif ssl

v. Lastly, reload the Apache webserver:

$ sudo systemctl reload apache2


6. Complete the NextCloud setup

At this point, we have concluded all the configurations.
To wind up on the NextCloud setup, open your browser and head to the URL indicated:

http://server-IP/nextcloud

You will be required to provide your login and database details.
Then finally hit the 'Finish setup' button.
You will be given a walk-through of the preliminary steps that you need to take
And finally, the NextCloud dashboard will be displayed.

[Need urgent assistance in configuring NextCloud on Ubuntu Server ? We can help you. ]


Conclusion

This article covers how to Install NextCloud on Ubuntu 20.04 with Apache (LAMP Stack). You can now upload your files and collaborate with your team members on NextCloud. This way you have full control of your data.
Nextcloud, a fork of ownCloud, is a file sharing server that permits you to store your personal content, like documents and pictures, in a centralized location, much like Dropbox.
The difference with Nextcloud is that all of its features are open-source.
It also returns the control and security of your sensitive data back to you, thus eliminating the use of a third-party cloud hosting service.

To install Nextcloud on Ubuntu:

1. To download the Nextcloud snap package and install it on the system, type:

$ sudo snap install nextcloud

2. The Nextcloud package will be downloaded and installed on your server. You can confirm that the installation process was successful by listing the changes associated with the snap:

$ snap changes nextcloud