# How to Install Nextcloud on Ubuntu 

https://www.hostcarts.qa/knowledgebase/article/how-to-install-nextcloud-on-ubuntu

1. **Update Your Server**

sudo apt update && sudo apt upgrade -y

1. **Install Apache, MariaDB & PHP (Required Modules)**

Official docs recommend installing all required PHP extensions.

sudo apt install apache2 mariadb-server libapache2-mod-php \

php-gd php-mysql php-curl php-mbstring php-intl php-gmp \

php-xml php-imagick php-zip php-bz2 php-fpm php-cli -y

Enable Apache modules:

sudo a2enmod rewrite headers env dir mime ssl

sudo systemctl restart apache2

1. **Create the Nextcloud Database**

Enter MariaDB:

sudo mysql

Run:

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'StrongPassword';

CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';

FLUSH PRIVILEGES;

QUIT;

**(These steps match official documentation.) [Nextcloud](https://docs.nextcloud.com/server/stable/admin_manual/installation/example_ubuntu.html)**

1. **Download Nextcloud**

Get the latest version:

cd /tmp

wget https://download.nextcloud.com/server/releases/latest.tar.bz2

tar -xjf latest.tar.bz2

Move it to the web directory:

sudo mv nextcloud /var/www/

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

sudo chmod -R 755 /var/www/nextcloud

1. **Create Apache Virtual Host**

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

Paste:

<VirtualHost *:80>

ServerName cloud.example.com

DocumentRoot /var/www/nextcloud/

<Directory /var/www/nextcloud/>

Require all granted

AllowOverride All

Options FollowSymLinks MultiViews

</Directory>

ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log

CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined

</VirtualHost>

Enable site:

sudo a2ensite nextcloud.conf

sudo systemctl reload apache2

1. **Enable HTTPS (Let’s Encrypt SSL)**

sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d cloud.example.com

1. **Configure Cron (Recommended by Nextcloud)**

sudo -u www-data crontab -e

Add:

*/5 * * * * php -f /var/www/nextcloud/cron.php

1. **(Optional but Recommended) Enable Redis Caching**

Redis improves performance significantly.
This is recommended in modern Nextcloud guides. [YouStable](https://www.youstable.com/blog/install-nextcloud-on-ubuntu)

Install Redis:

sudo apt install redis-server php-redis -y

sudo systemctl enable redis-server --now

Edit config:

sudo nano /var/www/nextcloud/config/config.php

Add:

'memcache.local' => '\\OC\\Memcache\\APCu',

'memcache.locking' => '\\OC\\Memcache\\Redis',

'redis' => [

'host' => 'localhost',

'port' => 6379,

],

1. **Complete Web Installer**

Open browser:

http://cloud.example.com

Enter:

- Admin username & password
- Database: nextcloud
- DB user: nextcloud
- DB password
- Host: localhost

Nextcloud will auto‑create tables. [Nextcloud](https://docs.nextcloud.com/server/stable/admin_manual/installation/example_ubuntu.html)
