Now that I have a LAMP server set up at home, I’ll need to install my own instance of NextCloud. For self hosting, they have three different sets of instructions on their website, depending on your needs. I went with manual installation on Linux, which you can find here. Your needs may vary, and I’m no expert, but this worked for me. My installation follows.

First, I needed to download the latest version, unzip it, and copy it to my directory for web files: (Don’t forget to change the ownership!)

   30  cd Downloads/
   31  wget https://download.nextcloud.com/server/releases/nextcloud-20.0.6.zip
   32  sudo apt install unzip
   33  sudo unzip nextcloud-20.0.6.zip -d /var/www/
   34  sudo chown www-data:www-data /var/www/nextcloud/ -R

Then I had to set up the mysql/mariadb with a nextcloud user and nextcloud database.

   35  sudo mysql
MariaDB [(none)]> create database nextcloud;
MariaDB [(none)]> create user nextclouduser@localhost identified by 'MYPASSWORD';
MariaDB [(none)]> grant all privileges on nextcloud.* to nextclouduser@localhost identified by 'MYPASSWORD';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

And of course, set up Apache to serve that website:

   36  sudo nano /etc/apache2/sites-available/nextcloud.conf
   37  sudo a2ensite nextcloud.conf
   38  sudo a2enmod rewrite headers env dir mime setenvif ssl
   39  sudo apache2ctl -t
   40  sudo systemctl restart apache2

My nextcloud.conf file looked like this:

<VirtualHost *:80>
        DocumentRoot "/var/www/nextcloud"
        ServerName (MYSERVERNAME)

        ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
        CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined

        <Directory /var/www/nextcloud/>
            Require all granted
            Options FollowSymlinks MultiViews
            AllowOverride All

           <IfModule mod_dav.c>
               Dav off
           </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
        Satisfy Any

       </Directory>

</VirtualHost>

It was missing the portions you may be used to seeing if you use HTTPS, which is because the next thing I needed to do was add a certificate from Let’s Encrypt:

   41  sudo apt install php-imagick libapache2-mod-php7.4 php7.4-common php7.4-mysql php7.4-fpm php7.4-gd php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp
   42  sudo systemctl reload apache2
   43  sudo apt install certbot python3-certbot-apache
   44  sudo certbot --apache --agree-tos --redirect --staple-ocsp --email (MYEMAIL) -d (MYSERVER)
   45  sudo nano /etc/apache2/sites-enabled/nextcloud-le-ssl.conf
   46  sudo apache2ctl -t
   47  sudo systemctl reload apache2

Now that changed my nextcloud.conf file to look like this:

<VirtualHost *:80>
        DocumentRoot "/var/www/nextcloud"
        ServerName (MYSERVER)

        ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
        CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined

        <Directory /var/www/nextcloud/>
            Require all granted
            Options FollowSymlinks MultiViews
            AllowOverride All

           <IfModule mod_dav.c>
               Dav off
           </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
        Satisfy Any

       </Directory>

RewriteEngine on
RewriteCond %{SERVER_NAME} =(MYSERVER)
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

And created a secure version for HTTPS traffic, called nextcloud-le-ssl.conf:

<IfModule mod_ssl.c>
SSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)
<VirtualHost *:443>
        DocumentRoot "/var/www/nextcloud"
        ServerName (MYSERVER)

        ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
        CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined

        <Directory /var/www/nextcloud/>
            Require all granted
            Options FollowSymlinks MultiViews
            AllowOverride All

           <IfModule mod_dav.c>
               Dav off
           </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
        Satisfy Any

       </Directory>


SSLCertificateFile /etc/letsencrypt/live/(MYSERVER)/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/(MYSERVER)/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLUseStapling on
Header always set Strict-Transport-Security "max-age=31536000"
</VirtualHost>
</IfModule>

Now that it was set up to receive standard and secure traffic, I could get to setting up nextcloud itself:

   48  sudo mkdir /<SOMEPLACE/ELSE>/nextcloud-data
   49  sudo chown www-data:www-data /<SOMEPLACE/ELSE>/nextcloud-data -R
   57  sudo mysql

That just set up the data directory and changed the ownership. The system was ready for me to log into and set it up on the web gui! The web gui steps are covered from NextCloud’s instruction page as well, but essentially, you log in as the admin and put in your mariadb credentials. It was really straight forward and simple to do at this point. Praise God it all worked, and now NextCloud was up and running!

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *