Nextcloud is a popular open-source cloud storage platform that is used to host and manage files, contacts, calendars, and other data. In this article, we will guide you through the process of installing Nextcloud on a fresh installation of Ubuntu 20.04.

Before we begin, make sure that you have a fresh installation of Ubuntu 20.04 and that LAMP (Linux, Apache, MySQL, PHP) is installed on your system. You will also need to be logged in as a user with sudo privileges.

Install the required PHP extensions

The first step is to install the required PHP extensions for Nextcloud. To do this, run the following commands in the terminal:


sudo apt update
sudo apt install php-intl php-gd php-xml php-zip php-curl php-mbstring

This will install the necessary PHP extensions for Nextcloud.

Download Nextcloud

Next, we need to download the latest version of Nextcloud from the official website. To do this, run the following commands in the terminal:


wget <https://download.nextcloud.com/server/releases/latest.zip>
unzip latest.zip -d nextcloud

This will download the Nextcloud zip file and extract it to a new directory called "nextcloud".

Create a new MySQL database

After downloading Nextcloud, we need to create a new MySQL database for the application. To do this, log in to the MySQL shell using the following command:


mysql -u root -p

When prompted, enter the MySQL root password.

In the MySQL shell, run the following commands to create a new database called "nextcloud":


CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

Make sure to replace "nextclouduser" and "password" with the actual username and password that you want to use for the Nextcloud database user.

Copy Nextcloud files to the web root directory

After creating the database, we need to copy the Nextcloud files to the web root directory. To do this, run the following commands in the terminal:


sudo cp -r nextcloud/ /var/www/html/nextcloud
sudo chown -R www-data:www-data /var/www/html/nextcloud

This will copy the Nextcloud files to the web root directory and set the correct ownership permissions for the files.

Configure Apache

Next, we need to configure Apache to serve the Nextcloud website. To do this, create a new Apache virtual host file using the following command:


sudo nano /etc/apache2/sites-available/nextcloud.conf

In the file, add the following configuration:


<VirtualHost *:80>
  ServerName your-domain.com
  ServerAdmin admin@your-domain.com
  DocumentRoot /var/www/html/nextcloud

  <Directory /var/www/html/nextcloud>
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${