Installing Nextcloud on NixOS Latest
Nextcloud is a self-hosted file hosting and collaboration platform that allows you to store, share, and collaborate on your digital files.
In this tutorial, you will learn how to install Nextcloud on NixOS latest using Nix package manager.
Prerequisites
Before you begin, ensure that you have the following prerequisites:
- A NixOS Latest instance.
- Root or sudo user access to your server.
- Basic command-line familiarity.
Step 1: Install the Required Software
To install Nextcloud on NixOS Latest, you need to first install the required software packages including PHP, MariaDB, Apache or Nginx web server, and their respective PHP modules.
To install the required software packages, execute the following command:
$ sudo nix-env -iA nixos.php \
nixos.mariadb \
nixos.nginx \
nixos.phpMyAdmin
Step 2: Install Nextcloud
Once you have all the required software packages installed, you can start the Nextcloud installation process.
First, download the latest Nextcloud version from their website using the following command:
$ wget https://download.nextcloud.com/server/releases/nextcloud-21.0.2.zipOnce you have downloaded the latest version, extract the files to the
/var/wwwdirectory.$ sudo unzip nextcloud-21.0.2.zip -d /var/wwwAfter extracting the files, you can rename the Nextcloud directory for easier access.
$ sudo mv /var/www/nextcloud /var/www/mycloudMake sure to change
mycloudto the name of your choice.Next, set the correct permissions for the
/var/www/myclouddirectory.$ sudo chown -R www-data:www-data /var/www/mycloud
Step 3: Configure the Web Server
At this point, you have Nextcloud installed on your server. However, you still need to configure the web server to serve the application files.
Nginx Configuration
If you are using Nginx as your web server, you need to create a new virtual host configuration file for Nextcloud.
Create a new virtual host file.
$ sudo nano /etc/nginx/sites-available/mycloud.confAdd the following contents to the file.
server { listen 80; server_name your-domain.com; root /var/www/mycloud; location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; } }Make sure to replace
your-domain.comwith your actual domain name.Create a symlink to the newly created site configuration file.
$ sudo ln -s /etc/nginx/sites-available/mycloud.conf /etc/nginx/sites-enabled/Restart Nginx to apply the changes.
$ sudo systemctl restart nginx
Apache Configuration
If you are using Apache as your web server, you can add the following code to your httpd.conf file or create a new virtual host configuration file:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/mycloud
ServerName your-domain.com
<Directory /var/www/mycloud/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
You will also need to enable the rewrite module and restart Apache.
$ sudo a2enmod rewrite
$ sudo systemctl restart apache2
Step 4: Complete the Web-based Installer
At this point, you can open your web browser and navigate to your Nextcloud URL. You should see the following page:

Enter your desired admin username and password, then click the Finish setup button.
You will be redirected to the main Nextcloud dashboard where you can continue setting up your Nextcloud instance.
Conclusion
Congratulations! You have successfully installed Nextcloud on NixOS Latest! You now have a self-hosted file hosting and collaboration platform that you can use to store, share, and collaborate on your digital files.