How to Install Nextcloud on Ubuntu?

Nextcloud is an open-source and secure PHP-based content collaboration platform for file sharing and synchronization. Users can share the number of files and folders from their local computers and synchronize with the Nextcloud server.

Before we proceed to install Nextcloud, your Ubuntu system should have installed the LAMP stack (Linux, Apache, MySQL/ MariaDB, PHP). 

Following are the steps to install Nextcloud on Ubuntu.

Install Apache

  1. Run the command (given below) to install the Apache server on Ubuntu – 

# sudo apt update

# sudo apt install apache2

2. Start and enable the Apache service on boot after installing Apache.

# sudo systemctl start apache2.service

# sudo systemctl enable apache2.service

You should be able to access the default Apache page with the server IP address now.

Install MariaDB
MariaDB is an open-source database server. 

  1. Please execute the command given below to install MariaDB – 

# sudo apt-get install mariadb-server mariadb-client

2. Start and enable the MariaDB service on boot after installing MariaDB.

# sudo systemctl start mariadb.service

# sudo systemctl enable mariadb.service

Now, we will configure MariaDB once it is installed.

3. Run the below-mentioned command to secure MariaDB – 

# sudo mysql_secure_installation

Enter current password for root (enter for none): Press Enter

Set root password? [Y/n]: Y

New password: Enter the password

Re-enter new password: Repeat password

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

4. Restart MariaDB server.

# sudo systemctl restart mariadb.service


Install PHP

  1. To install PHP 7.2, run this command – 

# sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip

2. After installing PHP 7.2, execute the command given below to open the default config file of PHP for Apache – 

# sudo nano /etc/php/7.2/apache2/php.ini

3. Please make the following changes in your php.ini file.

file_uploads = On

allow_url_fopen = On

short_open_tag = On

memory_limit = 256M

upload_max_filesize = 100M

max_execution_time = 360

date.timezone = America/Chicago

 4. Restart the Apache service again.

# sudo systemctl restart apache2.service

 5. We will verify all the installed features by adding a PHP info page to your code.

# sudo nano /var/www/html/phpinfo.php

 6. Enter this code on the phpinfo.php page – 

php phpinfo( ); ?

 7. Save your file and open the phpinfo page with ipaddress/phpinfo.php in your browser.

Create Nextcloud Database

1. First, create a Blank Database, then log in to the MariaDB Database.

# sudo mysql -u root -p

 2. Create a database named nextcloud_db;

# CREATE DATABASE nextcloud_db;

3. Create a user for the database nextcloud_db.

CREATE USER 'nextcloud_user'@'localhost' IDENTIFIED BY 'your_password';

4. Grant All privileges for the nextcloud_user to the nextcloud_db database.

#GRANT ALL ON nextcloud_db.* TO 'nextcloud_user'@'localhost' IDENTIFIED BY 'user_password' WITH GRANT OPTION;

5. Save the changes with the below command.

# FLUSH PRIVILEGES;

# EXIT;


Download Nextcloud Latest Release

1. Before installing Nextcloud, we will need to install curl and composer on the server through the command given below – 

# sudo apt install curl git

# curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

2. Download the Nextcloud from GitHub using the below-mentioned command. We will download it on the Apache root directory.

# cd /var/www/html

# sudo git clone --branch stable13 https://github.com/nextcloud/server.git nextcloud

# cd /var/www/html/nextcloud

# sudo composer install

# sudo git submodule update –init

3. Set permission for the folder as below – 

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

# sudo chmod -R 755 /var/www/html/nextcloud/


Configure Apache Service

1. Now, we will need to configure Apache for Nextcloud. First, create a file called nextcloud.conf and add the content mentioned below –

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

ServerAdmin [email protected]

     DocumentRoot /var/www/html/nextcloud/

     ServerName yourdomain.com

     ServerAlias yourdomain.com

     Alias /nextcloud "/var/www/html/nextcloud/"

     Options +FollowSymlinks

     AllowOverride All

     Require all granted

           Dav off

           SetEnv HOME /var/www/html/nextcloud

           SetEnv HTTP_HOME /var/www/html/nextcloud

           ErrorLog ${APACHE_LOG_DIR}/error.log

           CustomLog ${APACHE_LOG_DIR}/access.log combined

2. Save and exit from the file.

3. Enable Nextcloud and rewrite Module.

4. As we have configured the virtual host, we will need to enable it with the command mentioned below – 

sudo a2ensite nextcloud.conf

sudo a2enmod rewrite

sudo a2enmod headers

sudo a2enmod env

sudo a2enmod dir

sudo a2enmod mime

5. Finally, restart the Apache.

# sudo systemctl restart apache2.service

Our setup is complete now. 

Let us check by accessing your domain name in a browser that you have added in nextcloud.conf.

1. Set Nextcloud username, password, data folder, DB username, and DB name. 

2. Finally, click on the Finish button.

 

Here it is! 

We will now have Nextcloud Dashboard, as shown in the image below –

The Nextcloud installation is now complete!

 


Was this answer helpful?

« Back

chat