{"id":153,"date":"2017-02-28T00:05:03","date_gmt":"2017-02-28T00:05:03","guid":{"rendered":"https:\/\/www.jasonsblog.place\/?p=153"},"modified":"2022-06-14T01:59:06","modified_gmt":"2022-06-14T06:59:06","slug":"migrating-my-nextcloud-server-to-another-server","status":"publish","type":"post","link":"https:\/\/www.jasonsblog.place\/index.php\/2017\/02\/28\/migrating-my-nextcloud-server-to-another-server\/","title":{"rendered":"Migrating My Nextcloud Server to Another Server"},"content":{"rendered":"<p><strong>Edit<\/strong>: As of June 14, 2022, probably most if not <em>all<\/em> of the information found in this article is out of date! You&#8217;ll probably find better information somewhere else.<\/p>\n<p>When I saw that my version of Ubuntu could not be upgraded any more (due to Digital Ocean&#8217;s system), I had to migrate my Nextcloud installation (version 11.0.2) to a newer version of Ubuntu (16.04). In the documentation for Nextcloud, it details how to exactly migrate your Nextcloud installation to another Linux server, so I tried using that. Sadly, though, they left a couple of things out. So here&#8217;s my version of how I migrated my Nextcloud installation to another server.<\/p>\n<p>First of all, they say to back up your data, which is what I did (to some extent). Next, I spun up a droplet which had similar specifications to my previous installation (it uses 512MB and has 20GB of storage, for instance). I made sure to put in my usual ssh key for this new droplet, as well as securing it in other ways. At first, I thought I knew how to easily do this: copy over the <code>\/var\/www\/nextcloud<\/code> directory to the new server (which was also set up for Nextcloud), change some directory names, and it would be done. However, this was not what I found.<\/p>\n<p>When I tried this method, I couldn&#8217;t access the web interface. What was worse was that I had forgotten to change the firewall configuration on the new droplet and accidently &#8220;locked&#8221; myself out. So, through some more research, I tried it again with another droplet.<\/p>\n<p>This time, I copied the files using rsync, and made sure that I used the proper switches (I used the &#8220;-a&#8221; and &#8220;-t&#8221; switches, in order to archive the files, as well as save the timestamps). I saved the files to a new directory on the server, and made sure to back up the old files. I thought that this time I had fixed the issue. But Fate can be cruel.<\/p>\n<p>Even though I had copied over the files in the &#8220;correct&#8221; fashion, the server still wasn&#8217;t accessible from the web. Looking at the <code>\/var\/log\/apache2\/error.log<\/code> file, I found that the webserver couldn&#8217;t start due to Nextcloud not be able to read the database. After researching the problem more, I learned that the data can&#8217;t be just &#8220;copied&#8221; over; rather the data has to be copied, and the database has to be imported. So, after scrapping that droplet (I had changed it too much already), I spun up a new droplet, and tried this whole thing all over again.<\/p>\n<p>First, I put the server into &#8220;maintenance mode&#8221; and stopped the Apache server. Then I extracted the data from the database (via the command <code>mysql -u ownCloud -p password ownCloud &gt; \/tmp\/dump.sql<\/code>), copied <em>that<\/em> over to the new server, and imported it into the new database. For importing the new database, I &#8220;dropped&#8221; the old database, created a new one, and finally imported the data with the command <code>mysql -u nextcloud -p password nextcloud &lt; \/tmp\/dump\/sql<\/code>. Then I copied the old Nextcloud as I did before (using the official documentation&#8217;s recommendation of the command <code>rsync -Aax<\/code>) and carefully moved the files into the new <code>\/var\/www\/Nextcloud<\/code> directory. Even through all of this, it still wasn&#8217;t enough.<\/p>\n<p>Looking again at the <code>\/var\/log\/apache2\/error.log<\/code> file, I found that the new Nextcloud install couldn&#8217;t read the database due to the <em>new<\/em> server using the <em>old<\/em> Nextcloud <code>config.php<\/code> file (are you still with me?). So, I changed a few values in the <code>config.php<\/code> file so as to use the new database. What I did was change the <code>dbname<\/code> to the name of the new database, as well as input the new database login information. Also, I added the new IP address to the &#8220;trusted hosts&#8221; array in the <code>config.php<\/code> file. This seems to have fixed most of my problems.<\/p>\n<p>Just in case, I also ran a script that I found in the official Nextcloud documentation for fixing the permissions on the new server. Then I changed some of the security configurations for the Apache server. I copied over previous configurations for SSL into the <code>\/etc\/apache2\/sites-available<\/code> directory, and enabled them through the <code>a2enmode<\/code> command. With all that finished, I started up the Apache server again, and took the Nextcloud installation out of &#8220;maintenance mode&#8221;. Finally, I was able to use the server. Except, it wasn&#8217;t exactly to my liking.<\/p>\n<p>You see, I had copied over the &#8220;data&#8221;, &#8220;config&#8221;, and &#8220;themes&#8221; directories. I did not copy over all of my previous apps. When I saw that I had only half of my previous apps, I thought, &#8220;I need to fix this,&#8221; and copied the contents of my previous Nextcloud&#8217;s &#8220;apps&#8221; directory to the new server. With those out of the way, I saw to using some of Nextcloud&#8217;s recommendations, and bumped up the memory (as well as putting in a timeout feature). These were harder to fix, partially because I had these problems with my <em>previous<\/em> Nextcloud installation. Nevertheless, I sought to fix them.<\/p>\n<p>One of my problems was with the <code>\/var\/www\/nextcloud\/.htaccess<\/code> file, specifically that it wasn&#8217;t working. To fix this, I edited the <code>\/etc\/apache2\/apache.conf<\/code> file and changed the <code>AllowOverride<\/code> directive for the <code>\/var\/www<\/code> section to &#8220;All&#8221;. This allowed the <code>\/var\/www\/nextcloud\/.htaccess<\/code> to work (at least, it would work since I&#8217;m accessing the site over a secure connection). Next, I added a memcache so as to speed up performance. I added in <code>php-apcu<\/code> and edited the <code>\/var\/www\/nextcloud\/config\/config.php<\/code> file to reflect this by assigning <code>memcache.local<\/code> the value <code>\\\\OC\\Memcache\\\\APCu<\/code>. My server was made much faster with this tweak. For added polish, I followed the directions on <a href=\"https:\/\/bayton.org\/2016\/07\/installing-nextcloud-on-ubuntu-16-04-lts-with-redis-apcu-apache\/\">this tutorial<\/a> and added Redis support.<\/p>\n<p>This was a tough migration that I thought would have been easy. I figured that it would have taken a couple hours. However, it was stretched out to a numbers of hours (not to mention one night). While it&#8217;s great that I have migrated to a more manageable configuration, I should have done more research.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Edit: As of June 14, 2022, probably most if not all of the information found in this article is out of date! You&#8217;ll probably find better information somewhere else. When I saw that my version of Ubuntu could not be upgraded any more (due to Digital Ocean&#8217;s system), I had to migrate my Nextcloud installation [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,76],"tags":[69,68,67,70,81],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-information-technology","category-programming","tag-apache","tag-migration","tag-nextcloud","tag-sql","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":4,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions\/621"}],"wp:attachment":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}