How to Install Nextcloud on Ubuntu 17.04

In this tutorial, you will learn to install the NextCloud software. We will be using Caddy for our web server needs, as it allows easier configuration and simple issuing of SSL certificates. Instructions in this guide were written for NextCloud 12, but may also work for newer versions.

Before we begin, make sure your server is up-to-date, and install the required PHP 7.1 modules.

apt-get updateapt-get upgrade -yapt-get install software-properties-common unzip

PHP 7.1

Install and configure PHP 7.1.

apt-get install -y python-software-propertiesadd-apt-repository -y ppa:ondrej/phpapt-get update -yapt-get install -y php7.1 php7.1-fpm php7.1-cli php7.1-json php7.1-curl php7.1-imap php7.1-gd php7.1-mysql php7.1-xml php7.1-zip php7.1-intl php7.1-mcrypt php-imagick php7.1-mbstring

For Caddy, we will use TCP sockets instead of Unix sockets, as they are more optimized.

Edit the file /etc/php/7.1/fpm/pool.d/www.conf at around line 36. Look for the listen = /run/php/php7.1-fpm.sock. Comment it out and add the TCP socket instead, as shown below:

;listen = /run/php/php7.1-fpm.socklisten =

Now restart PHP7.1-fpm.

service php7.1-fpm restart


Next, we have to install Caddy.

Running the Caddy setup script will automatically download the correct version for your system (32/64bit) and install it.

curl | bash -s personal

Create the root directory where we will serve files from:

mkdir -p /var/www/nextcloud

Create the folder /etc/caddy and the file “Caddyfile“.

mkdir -p /etc/caddynano /etc/caddy/Caddyfile

Now, paste the following contents: {root   /var/www/nextcloudlog    /var/log/nextcloud_access.logerrors /var/log/nextcloud_errors.logfastcgi / php {    env PATH /bin}rewrite {    r ^/index.php/.*$    to /index.php?{query}}# client support (e.g. os x calendar / contacts)redir /.well-known/carddav /remote.php/carddav 301redir /.well-known/caldav /remote.php/caldav 301# remove trailing / as it causes errors with php-fpmrewrite {    r ^/remote.php/(webdav|caldav|carddav|dav)(//?)$    to /remote.php/{1}}rewrite {    r ^/remote.php/(webdav|caldav|carddav|dav)/(.+?)(//?)$    to /remote.php/{1}/{2}}rewrite {    r ^/public.php/(.+?)(//?)$    to /public.php/(.+?)(//?)$}# .htaccess / data / config / ... shouldn't be accessible from outsidestatus 403 {    /.htacces    /data    /config    /db_structure    /.xml    /README}header / Strict-Transport-Security "max-age=31536000;"}

Let’s also turn Caddy into a service. Paste these lines to the file /etc/systemd/system/caddy.service.

[Unit]Description=Caddy HTTP/2 web server %IDocumentation=[Service]; run user and group for caddyUser=rootGroup=rootExecStart=/usr/local/bin/caddy -agree=true -conf=/etc/caddy/CaddyfileRestart=on-failure; create a private temp folder that is not shared with other processesPrivateTmp=true; limit the number of file descriptors, see `man systemd.exec` for more limit settingsLimitNOFILE=8192[Install]

Enable and run the Caddy server.

systemctl enable caddy.servicesystemctl start caddy.service


A database is required for the NextCloud setup.

Note: Save and remember the root password you chose during MariaDB installation!

Run the following commands to install MariaDB. You may want to replace the MariaDB repository with another one of your choosing.

apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8add-apt-repository 'deb [arch=amd64,i386] zesty main'apt updateapt install mariadb-server -y

With MariaDB installed, we have to create a user and database for the NextCloud installation.

Run this command sequence:

mysql -u root -pCREATE DATABASE nextcloud;GRANT ALL PRIVILEGES ON nextcloud.* TO 'exampleUser'@'localhost' IDENTIFIED BY 'securepassword';FLUSH PRIVILEGES;exit


Change into the root directory for where the installation will reside and execute the following commands.

cd /var/www/nextcloudwget nextcloud-*mv nextcloud/* .chown -R www-data:www-data /var/www/nextcloudrm -rf nextcloud-*.zip

Now visit your domain name or IP address and you will be greeted by the installation screen.
Follow the installation instructions on the screen and fill in the desired admin account details, database user, password and name.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.