Let’s check out how to install NextCloud on Ubuntu 20.04 Focal Fossa.
Before we start out, ensure you have the following requirements:
An instance of Ubuntu 20.04
A regular user in the system configured with sudo privileges.
Step 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
Step 2: Install additional PHP modules
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
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
First, set the memory limit from the default value to 512M as shown in the screenshot below.
memory_limit = 512M
Also, set your timezone. For instance America/Denver
Now, restart the Apache webserver for the changes to be applied:
$ sudo systemctl restart apache2
It would also be prudent to confirm that the webserver is up and running as shown.
$ sudo systemctl status apache2
Step 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. So, access the MariaDB database engine as shown:
$ sudo mysql -u root -p
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';
Save the changes to the database engine
And finally exit.
The database is now configured. We are then going to download and configure NextCloud.
Step 4: Download and configure NextCloud
NextCloud provides various installation methods such as running NextCloud as a virtual machine, or as a docker image. 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
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/
Thereafter, set the directory permissions to www-data user and group as shown.
$ sudo chown -R www-data:www-data /var/www/html/nextcloud
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
Perfect! Let’s proceed and define a configuration file for NextCloud.
Step 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. So, proceed and create a nextcloud.conf configuration file as follows.
$ sudo vim /etc/apache2/sites-available/nextcloud.conf
Add the lines shown below. 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.
Save and exit the virtual host config file. Then enable it as follows.
$ sudo a2ensite nextcloud.conf
Additionally, enable the Apache webserver modules that will be required later on.
$ sudo a2ensite rewrite headers dir mime env setenvif ssl
Lastly, reload the Apache webserver.
$ sudo systemctl reload apache2
Step 5: 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.
You will be required to provide your login and database details as demonstrated in the snippets below.
The 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.
You can now upload your files and collaborate with your team members on NextCloud.