August 8, 2022

Install NextCloud From Command Line


Overview

There are various methods for setting up Nextcloud on Linux. Here, we will describe, how to Install NextCloud from command line On Ubuntu 22.04. We used to perform the entire Nextcloud installation manually. Preparing the server environment for installation comes first, secondly the web interface is used to complete the setup. We can now install Nextcloud completely using the command line. Many sysadmins like this method since it is very convenient for automatic install with any automation systems.

In this guide, we’ll demonstrate how to install NextCloud from the command line on Ubuntu 22.04. What will we do? In essence, we will run a few commands to finish the nextcloud initial setups rather than using the web-based setup.


The steps we are going to follow:


1. Install PHP and MySQL packages
2. Configure MySQL Server
3. Run the Nextcloud Setup From the Command Line.


1. Install Packages

1. Update and Upgrade the Ubuntu Packages

# apt update && apt upgrade


2. install Apache and MySQL Server

# apt install apache2 mariadb-server 


3. Install PHP and other Dependencies and Restart Apache

# apt install libapache2-mod-php php-bz2 php-gd php-mysql php-curl php-mbstring php-imagick php-zip php-ctype php-curl php-dom php-json php-posix php-bcmath php-xml php-intl php-gmp zip unzip wget


4. Enable required Apache modules and restart Apache:

# a2enmod rewrite dir mime env headers
# systemctl restart apache2


2. Configure MySQL Server


1. Login to MySQL Prompt, Just type

# mysql


2. Create MySQL Database and User for Nextcloud and Provide Permissions.

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'passw@rd';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
quit;


3. Download and Install Nextcloud

Now download the latest Nextcloud archive file, Go to the Nextcloud Download Page. Or you can download from this direct link: https://download.nextcloud.com/server/releases/latest.zip


1. Download and unzip at the web root (/var/www/html) folder

# cd /var/www/html
# wget https://download.nextcloud.com/server/releases/latest.zip
# unzip latest.zip


2. Move all nextcloud content to the web root (/var/www/html) folder

# cd /var/www/html/nextcloud
# mv * .* ../


3. Remove empty nextcloud directory

# rmdir /var/www/html/nextcloud


4. Change the ownership of the nextcloud content directory to the HTTP user.

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

5. Run the nextcloud installation CLI commands.

# cd /var/www/html
# sudo -u www-data php occ  maintenance:install --database \
"mysql" --database-name "nextcloud"  --database-user "nextcloud" --database-pass \
"passw@rd" --admin-user "admin" --admin-pass "admin123"

If everything goes well the command will output “Nextcloud was successfully installed”.

6. nextcloud allowed access only from localhost, it could through error “Access through untrusted domain”. we need to allow accessing nextcloud by using our ip or domain name.

# vi /var/www/html/config/config.php

<?php
$CONFIG = array (
  'passwordsalt' => 'VAXFa5LsahAWHK/CMPHC3QkTsnqK80',
  'secret' => 'ZWTuZMLpKVizET85i/NkcwYCPUQyjB/6ZjEYGdVgJeDhNXzR',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'nc.mailserverguru.com', // we added this line
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',

  .....
:x

Now save the file and restart apache2

# systemctl restart apache2

Now, Go to the Browser and type http:// [ ip or fqdn ] of the server, as the configuration is completed command line, the Login page will appear.

install nextcloud from command line



Thanks !!



Add comment

Your email address will not be published.