0

What's the right way to uninstall Nextcloud fron Linux when it was installed via the web installer?

All I can find is search results like this one that only say what to do when it was installed via Snap.

This Nextcloud manual describes the use of the web installer (run by opening setup-nextcloud.php) but it doesn't say anything about uninstalling. (Except that if you uninstall Nextcloud you need to remove the Nextcloud directory labels.)

I tried opening setup-nextcloud.php again in case it offered an uninstall option, but no.

I'm sure it would be possible to work it out by going through setup-nextcloud.php and manually removing everything it added, such as the server registration, the firewall rules, and so on... but obviously that could be time-consuming and error-prone. Surely there must be an automatic way?

2
  • Is the goal simply to uninstall NextCloud? Or do you want to reverse it’s installation process? 🤔
    – matigo
    Aug 5 at 12:53
  • The former, @matigo. My goal is purely practical. Maybe there's a simple solution I'm missing (I've worked more with Windows, and my Linux knowledge doesn't cover all areas... yet!) so I welcome any suggestions. But I did read in more than one place that the Nextcloud uninstallation approach depends on how you installed it. So my starting assumption is that unless I do it right, the end result won't be correct/comprehensive. Sure, I could delete the firewall rules in UFW, but that was just one example off the top of my head. Could leave trouble of one kind or another lurking on that machine.
    – Reg Edit
    Aug 5 at 22:10

2 Answers 2

2

Reading through the code for NextCloud's web installer, NextCloud would have been installed in the directory where you placed the setup-nextcloud.php file. So, with this in mind, removal of NextCloud may be pretty simple.

Note: As I do not know the directory structure of your server, the following assumptions will be made. Any differences will need to be addressed by you as you remove NextCloud from your system.

Assumptions:

Item Assumption
Server OS Ubuntu 18.04, 20.04, or 22.04
Web Server Apache
NextCloud Directory /var/www/nextcloud
Database MySQL
Database Name nextcloud

With that out of the way, let's remove NextCloud from your server. First we will disable the Apache configuration.

  1. SSH into your server (if not already connected)

  2. Change to Apache's sites-available directory:

    cd /etc/apache2/sites-available 
    
  3. Determine which Apache configuration file is used by NextCloud. If you are unsure, you can quickly determine the answer with the following command:

    grep -rnw '/etc/apache2/sites-available' -e 'nextcloud'
    

    This will hopefully give you a short list with the location of NextCloud:

    /etc/apache2/sites-available/010-storage.conf:6:        ServerAlias cloud.example.com nextcloud.example.com
    

    Note: The example above is not the exact same thing you will see on your system. Expect a different file name and text extract.

  4. Disable the NextCloud site using the supplied file name:

    sudo a2dissite 010-storage.conf
    

    Note: You do not need to enter the entire file path, because we're in the appropriate directory already.

  5. Reload (or restart) Apache:

    sudo service apache2 reload 
    

With this done, nobody can access the NextCloud installation. Now you can remove the files.

  1. Change to the Apache root directory:

    cd /var/www
    
  2. If you would like to backup NextCloud before clearing it out, you can wrap everything in a compressed tarball like this:

    sudo tar -czvf nextcloud-backup.tar.gz nextcloud
    

    Note: Be sure to replace nextcloud with the proper directory of your NextCloud installation if the initial assumption is incorrect.

  3. Remove NextCloud:

    PAY ATTENTION TO THIS COMMAND! THERE IS NO UNDO!

    sudo rm -Rf /var/www/nextcloud
    

    Note: Use the full path here so that there is less chance of completely wiping your server of everything. This command will completely remove the nextcloud directory and its contents.

  4. There is no step 4. The NextCloud files have been removed.

Finally, let's clear out the database.

  1. Connect to MySQL via the command line as the administrator:

    sudo mysql 
    
  2. List all of the databases to confirm the name of the NextCloud database:

    SHOW DATABASES;
    

    You may see a result like this:

    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | nextcloud          |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.03 sec)
    
  3. Remove the NextCloud database:

    PAY ATTENTION HERE, TOO. THERE IS NO UNDO!

    DROP DATABASE nextcloud;
    
  4. Exit MySQL:

    quit;
    

Done and done.

1
  • Thank you for taking the time to derive a process. Yes, the server is Linux Mint 20.1 (which is based on Ubuntu 20.04), apache2 and MariaDB/MySQL. In the absence of any "official" way, I'm encouraged to think the steps you've detailed could be the best way forward, and they appeared to just work--albeit with a few differences which, in case it helps anyone else using the process in the future, I've enumerated in my own supplementary answer.
    – Reg Edit
    2 days ago
0

I'm grateful to matigo for taking the time to derive an uninstall process from the web setup, and to document it in a great answer.

I'm providing this supplementary answer with a few differences I encountered (which may or may not relate to the fact that this Ubuntu 20.04 machine is a Linux Mint installation). Hopefully this will help any other Linux "semi-noobs" using the process in the future.

These are the differences I found, and what I did about them:

Apache root: I found my Apache root was one level lower, at /var/www/html. This didn't seem to cause any particular problem, just needed additional care to use the right path where commands refer to the Apache root.

Nextcloud not in sites-available: I could find no mention of Nextcloud in any files in /etc/apache2/sites-available (even with grep -i; nor in any other /etc/apache2/ subfolder). This remains unexplained, and is strange, as Nextcloud had been working quite recently for a few test connections to the website. Anyway, so I had to skip the a2dissite, but the rm (with additional www in path as noted above) was successful (Nextcloud folder gone), and the apache reload, which I did anyway for good measure, didn't report any errors (I assume it would say at least something at the console if the reload had problems? And the remaining sites are working without any issues).

Nextcloud database: in the MariaDB/MySQL step, I found I had no database called "nextcloud" but there was one called "ncexample" which I thought was probably the one. A web search revealed that the Nextcloud database contains a bunch of tables prefixed "oc_" (Nextcloud being a fork of ownCloud), which helped to confirm that the db I was about to delete was at least some Nextcloud database on that server. In my case that was all I needed to know before deleting it.

enter image description here

Nextcloud firewall rules: I went into the graphical UI for UFW (GUFW) by choosing Firewall Configuration from the main menu in Linux Mint. There, by selecting each of the profiles in turn (Home, Office, Public etc), I located and deleted the Nextcloud rules. The UI made this very easy because the displayed table of rules has a Name column, and there were rules with Nextcloud in the name. (I don't know whether the Nextcloud firewall rules were added automatically by setup; given that matigo makes no mention of them, I'm guessing not, meaning they would have been added manually afterwards. So it looks as though this step would be needed in any case following any auto-uninstall, should such a thing ever be found to exist and be used.)

That's it! By making these or similar adjustments applicable to your own server, you should find that matigo's process works very well to uninstall Nextcloud when the web installer was used to install it. If at any point I find anything further related to uninstalling Nextcloud this way, I'll post an update. I'd welcome comments regarding others' experiences with the process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.