Setup NextCloud on Ubuntu 18.04 LTS with Apache2, MariaDB and PHP

I will be using DigitalOcean Droplet. Before you start installing anything ever you want to do a basic update by typing:

sudoapt-get update

Then type:

sudoapt-get upgrade

After you are finished you will want to type:

` apt-get install apache2mariadb-server libapache2-mod-php7.2

apt-get install php7.2-gd php7.2-json php7.2-mysql php7.2-curl php7.2-mbstring

apt-get install php7.2-intl php-imagickphp7.2-xml php7.2-zip `

This will install apachemariadb and the couple php

One useful command to check your version of mariadbis:

mysql-v

We will want to now secure mysql by typing this command:

sudomysql_secure_installation

It will ask you a few questions, I say yes to all of them but choose what you would like.

We are now going to setup the database, type:

` sudomysql

create databasenextclouddb: `

Now the database is created, now we are going to create a user:

CREATE USER 'nextclouduser'@'localhost'' IDENTIFIED BY 'password':

Change password to your actual password. Now we are going to grant all privileges and flush them:

` GRANT ALL ONnextclouddb.TO ‘nextclouduser’@‘localhost’:*

FLUSH PRIVILEGES

EXIT: `

Now continue with this command to make php more robust:

nano/etc/php/7.2/apache2/php.ini

Ctrl+W then type:

memory_limit and we want to change that to 512M

Search for upload_max_file and change it to 500M

Search post_max and change it to 500M

Search max_execution and change it to 300

Search date.time and change it to your timezone which for me is America/Chicago

You now will want to Ctrl + X to save all of this.

Now start Apache:

` systemctlstart apache2

systemctlstartmariadb

systemctlenable apache2

systemctlenablemariadb `

Next you will want to open your web browser and go to https://www.nextcloud.com/install

Click download for server, we are downloading next cloud as archive file so right-click the download button and grab the link. Proceed by typing this command, you can use the link you copied:

wget https://download.nextcloud.com/server/releases/nextcloud-18.0.2.zip

You will want to have unzip installed so you will need to run the command:

apt install unzip

Once it has downloaded then type the commands:

` unzip nextcloud-18.0.2.zip

cp –rnextcloud/var/www/html

chown–Rwww-data:www-data/var/www/html/nextcloud/

chmod–R 755 /var/www/html/nextcloud/

nano/etc/apache2/sites-available/nextcloud.conf `

Copy and paste this:

`

ServerAdmin admin@example.com

DocumentRoot /var/www/html/nextcloud/

ServerName cloud-demo.its

Alias /nextcloud “/var/www/html/nextcloud/>

Options +FollowSymlinks

AllowOverride All

Require all granted

 <IfModule mod_dav.c> 

    Dav off 

<IfModule> 

SetEnv Home /var/www/html/nextcloud

SetEnv HTTP_HOME /var/www/html/nextcloud

ErrorLog ${APACHE_LOG_DIR}/error.log `

You will need to change server name to yours and then save.

Continue with these commands:

` a2ensitenextcloud.conf

a2enmod rewrite

a2enmod headers

a2enmod env

a2enmoddir

a2enmod mime `

Then do a restart of apache:

systemctlrestart apache2

Then Nextcloud should be setup

Now we want to setup a more secure connection:

apt-get install python-certbot-apache –y

Then change the domain to the right domain and then set your email when it prompts.

We select 2 for the option to redirect https so its more secure.

Now going to Nextcloud fill out all the information and then click Finish Setup.