In this guide, we’ll demonstrate how to install NextCloud from Command line on Ubuntu 22.04. Rather than using the web-based setup, We will run a few commands to finish the initial configurations. So, we will not perform the entire installation manually.
There are various method of Nextcloud Installation. Command line Installation is the easiest. First, we will prepare the server environment for regular nextcloud setup. Secondly, instead of the web based setup, we will completely install and configure Nextcloud on Ubuntu 22.04 using the command line.
Nextcloud CLI installation method is very useful because we can perform full automatic installation with any automation system. Below, we mentioned the steps for the Nextcloud Command line Installation.
Step1: Install PHP, Apache and MariaDB Server
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
Step2: Configure MariaDB 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;
Step3: Download and Prepare Nextcloud Package
Now download the latest Nextcloud archive file, Go to the Nextcloud Download Page. Or you can download from this direct link.
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
Step4: Run the Nextcloud installation CLI Command
This CLI command will take all the installation parameters like the database and admin credentials to run the installation and configure on the background.
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”.
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.
with the Nextcloud Login page shows up, our Nextcloud Installation from command line is successfully completed 🤗
If you want to learn more about Nextcloud, you can visit this YouTube Playlist
Now It’s Your Turn
I hope this guide will help you to Install NextCloud From Command Line. I have tried to show you every step in detail.
If you face any issue or have any drought on any stage, please let me know on the comment section below 👇
Thanks !! ❤️