Setup Nextcloud – Ubuntu

Many of the developers at Owncloud left the project in favor of forking a new file share and sync service. So there is no reason why Nextcloud should fail, I’ve followed Nextcloud since their blog post in may and I have been very excited about the project.
The developers at Nextcloud are doing their best to give the users a more secure platform, fewer bugs and overall a better product! They even made Enterprise-features opensource! They haven’t released repositories like Owncloud have and I was talking with some of the guys on their IRC channel about it and everyone seemed happy about it because it was a pain in the ass to maintain and I often caused more trouble than expected for the users. So I don’t think we will see something like this in the near future but that shouldn’t stop you!

I can see there is a lot of the visitors at the site there is searching for “debian packages nextcloud”, “debian nextcloud”, “apt nextcloud package” and so on. And let me say this, there is no repositories or easy to install .deb files and ect. for nextcloud, but that shouldn’t be you brick wall! this is a easy and straight forward process there doesn’t take too long and it is easy to maintain and upgrade and should be a lot more bug free than Owncloud’s repositories.

Step 1. Setup LAMP

Ubuntu have a complete LAMP package in their repository so we don’t have to install
everything manually, yeah lucky us and applause to Ubuntu’s dev team.
So run the command and everything will be installed automatically, the only thing you will have to do is give Mysql a password when prompted for it.

Nextcloud need a couple of php-modules to function, so go ahead and install them and activate a2enmod-rewrite

It is recommended by nextcloud to use MariaDB there is a fork of Mysql to get the best performance so let’s install that

Step 2. Download & Configure Nextcloud

We have a fully functional LAMP server now and we only need to setup a database for Nextcloud and then download and configure Nextcloud.

We are going to download nextcloud, make sure you get the lates release

extract the tar ball and moove it to Apache’s web root.

Then we will give the files in /var/www/nextcloud the right permissions.
copy the content below and make a file called with vim /tmp/nextcloud_permissions and feel free to use your favorite text editor.

This is actually a script provided by Owncloud but is also working with Nextcloud because Nextcloud is a for off Owncloud.
Give the file permission to be executed with sudo chmod +x and run tile script.

Configure Apache

it will look something like This

add the changes in the configuration file below to you configuration file or just copy it.

Restart Apache

Configure MariaDB

The last thing we will need before the setup in the browser is to create a database and a database user, run each line separate and don’t forget to change tha nextcloud-password

and that is basically it! open up your browser and enter your IP/FQDN in the address field. you will see something like this.
Enter the credentials for your new admin user and insert the databseuser/password and database name that we created earlier!.


When you have finished the setup you will see a page like this, and I actually don’t think there is more to say about that other than enjoy you new nextcloud instanse! it os only waiting for being used by you and your users! if you have any questions feel free to ask.


  • Leon

    What repos do I need to install php-modules I’ve a base install on Ubuntu 14.04.4 server

    • which one do you have problems with ?

  • Andrew Wilson

    Very useful. THANKS. Any chance you could post additional instructions showing how to make this an HTTPS connection setup versus the insecure HTTP one presented? I want to start using nextcloud but I need remote file access and it has to be over https of course.

    • I think i can find the time to make it in this week, do you have a certificate or should the guide be using let’s encrypt (free certificate) ?

      • Andrew Wilson

        Awesome! Using a Lets Encrypt would be fine, but I warn that one day I am bound to ask how to add my own certificate, as ultimately I want a site I can share with other people. Right now, that seems a long way away.

        • Lol :D that is what let’s encrypt is for! This site is running on a let’s encrypt certificate

          • Andrew Wilson

            Probably another dumb question: so is operating under a self-signed certificate? If so, I would have expected a certificate warning error (the kind that usually makes me click “get me out of here”). If the Let’s Encrypt option creates a certificate that doesn’t create one of those scary warnings then it will be just fine by me! Thanks again.

          • Short anwser yes. Take a look here to get more information :

    • Hi again. I am having some trouble in the family so don’t think I can make it in this week or next week.
      But basiscly you should use to get a certificate then follow thie guide from step 3
      and don’t forget to change DocumentRoot and ther certificate path and inster this as you did in this guide

      Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      allow from all

  • Andrew Wilson

    Comments for those like me who are new to trying to get this deep into Linux. This works for me on Ubuntu 16.04, but not 14.04. Also, some of the commands above did not work as written for me:

    cd /temp

    I had to issue this BEFORE the above commands:

    sudo mkdir /temp
    cd /temp
    sudo wget https://

    Also, I changed “tar -vxjf nextcloud-9.0.50.tar.bz2” to “sudo tar -vxjf nextcloud-9.0.50.tar.bz2”

    and I changed “sudo /etc/apache2/sites-available/000-default.conf” to “sudo nano /etc/apache2/sites-available/000-default.conf”

    And finally, I issued “sudo service apache2 restart” after I changed the sites-available/000-default.conf file.

    Recognize I don;t really know what I am doin…but I was rewarded with a nextcloud login screen after my experiments/changes. This is still a super guide – and even I got it to work. :) THANKS again to techknight for the blog post and instructions.

    • Thanks for the feedback! I have edited the article so i should be right this time ;)

      Was the error message something like this:
      AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message

      • Andrew Wilson

        So I should use mkdir rather than sudo mkdir – I will remember that, Linux is so hard for me to understand. I have seen that Apache error but I have read elsewhere that it’s not a big issue. Also, there is a command (that escapes me…) on how to fix it.

        • inthis case you shouldn’t use mkdir ;)
          But when you use sudo then you “normal” user won’t have the sufficient permissions/ownership and there is no rule to say that you shouldn’t use sudo to create directories. It all depends on the enviroment on your server.

  • mr3 mr4

    What to do when I have dynamic DNS on my server and I put it on my browser and get connection timed out?

    • Let’s start with ther internal problems, I am almost 100% sure your apache configuration is the problem and your DocmentRoot is probably set to /var/www/html and not /var/www/nextcloud
      Try to see if that doesn’t fix it, otherwise paste your apache conf on and give me the link.

      • mr3 mr4

        Thanks for your reply here is my 000-default.conf: In your guide it says and I modified it to but neither seems to work and I just go to apache2 ubuntu default page also can’t connect my dynamic DNS.

        • and you have restarted or reloaded apache2 right? “sudo service apach2 restart”

          • mr3 mr4

            Ah, now it works thank you! Just needed to restart apache2.

          • Gonna add that to the Guide ;) how about over the public ip, does it Work there?

          • mr3 mr4

            No I can’t connect my dynamic dns for some reason only ( Also I encountered new problem when I’m filling those informations: error while trying to create admin user: failed to connect to the database: An expection occurred in driver: SQLSTATE[HY000] [1045] Acces denied for user ‘nextclouduser’@’localhost’ (using password: YES)

          • Okay lets forget about the access for the public again ;)
            Are you 100% sure that you are using the right database,database user and password?

          • mr3 mr4

            I’m using those nextclouduser and password nextcloud-password and database is next cloud like in your guide.

          • Hmmmm. it is a little hard to help when I don’t have access to your server, but try to run :
            sudo mysql -u root -p

            # and then copy the output of this command(Plz use hastebin again and don’t insert the output in the comment only the link):

            SHOW DATABASES;

          • mr3 mr4


            I was thinking should I do that mariadb configuration again? Can I somehow delete this nextcloud.

          • You should leave the nextcloud database but try to run the commands below and then use another and then change the username and the password.
            sudo mysql -u root -p

            CREATE USER nextclouduser@localhost IDENTIFIED BY ‘nextcloud-password’;

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

          • mr3 mr4

            Got it to work now, thank you very much. Can you maybe write guide how to make your nextcloud public internet with dyn dns safely, so you can use it with friends?

          • Great to hear that!
            But i am afraid i can’t help you with that I only have a static IP so i can’t test dynDNS.
            But have you tried to make a port forward on port 80 from your nextcloud server to the router and then accessed you public IP?

          • mr3 mr4

            No haven’t tried that but I try to find some guide. For example I can access my teamspeak3 server with my dynamic dns.

          • and you haven’t made a portforward for that?
            It is pretty simple, make a port forward and then your site is public

          • mr3 mr4

            Yes, I portforwarded ts3 server, but I need to change owncloud something else than 80 because my router is using it or something.

          • you are going to need a reverse proxy to send multiple servers traffic out on port 80 then
   see this guide.
            But you should setup HTTPS:// for nextcloud

          • mr3 mr4

            I got everything working, thank you very much for your efforts.

          • SC
          • Bee Kay

            For me the issue was that I had a character in my password. I now have a password without in it. Alternatively you can use a character to escape the when typing your original password.

  • MrMagicalKid

    i see this within the admin area, “Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.” Do you think your update your amazing howto to fix this? i see the correct settings withing your post, but still showing up.

    • Can you show me your permissions with ” ls-l ” and post it at hastebin or something like that?
      Did you use the sh script?

  • Suajie Nik Mat

    Hi Bro.. Thanks for Awesome Tutorial.. Sorry for being noob.. I stuck at “”.. i dont know how to use vim..

    Just used notepad++.. I copy that script and save it as I pasted that file with sudo nautilus into /var/www/nextcloud and run “sudo ./” but FAILED.

    (chmod: cannot access ‘’)

    Or anyone can help me?. Thanks in advance ^_^

    • Your welcome ;)

      Do you use a headless system or one with a GUI?
      If you are running headless you could use nano instead of vim.
      Then paste the content of the page here, save it as,and then run “./nextcloud_permissions”

      • Suajie Nik Mat

        Solved it.. Save it at Desktop run manual from Terminal.. But facing new error :-( .. Error SQLSTATE[HY000][1045].. Cant login.. I saw ‘nextcloud’ databases in SHOW databases. But data was EMPTY after SHOW tables.. I tried to deleted that database so i can create new one.. But wont allow me to DROP..

        I tried new command, but still empty
        CREATE USER admin@localhost IDENTIFIED BY ‘1234’;

        GRANT ALL PRIVILEGES ON nextcloud.* TO admin@localhost IDENTIFIED BY ‘1234;

        • What message do you get while trying to drop the table?

          And also:
          GRANT ALL PRIVILEGES ON nextcloud.* TO admin@localhost IDENTIFIED BY ‘1234;
          should be
          GRANT ALL PRIVILEGES ON nextcloud.* TO admin@localhost;

          • Suajie Nik Mat

            Morning bro..
            Thanks for reply again.. Here error msg

            “ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘nextcloud’ at line 1”

          • Suajie Nik Mat

            Solved it by enable binary loggin in MariaDB /etc/mysql/mariadb.conf.d/50-server.cnf..


            log-bin = /var/log/mysql/mariadb-bin
            log-bin-index = /var/log/mysql/mariadb-bin.index
            binlog_format = mixed

            *But i dont know how to connect nextcloud over internet if i am not in same network..

            I tried to add WAN IP @ Static IP in Trusted Domain but not working..
            0 = LAN IP
            1 = WAN IP

            ** For your info, i did TCP port forwarding to LAN IP
            FTP – 21
            SSH – 22
            HTTP – 80
            HTTPS -443

          • It should only be nessesay to make a port forward for 80 for http and 443 https.
            Do you have other servers running?

          • Lol what cmd di you use ? ;)