Difference between revisions of "NextCloud/Installation"

From SETV Springfield Technical Wiki
Jump to: navigation, search
m (Installing NextCloud [3])
m
Line 1: Line 1:
{{Under Construction}}
+
= '''HOW TO: INSTALL NEXTCLOUD 10 ON FREEBSD JAIL''' =
  
This guide was written for the custom installation of [[NextCloud]] on a FreeNAS Jail. This guide assumes:
+
I wrote this guide primarily as a backup in case I needed to redo things over again, and decided to spruce it up and share it with others.
  
You have not set up a jail
+
'''The Goal:'''
  
You have already set up a Cloud volume under Storage
+
Put Nextcloud 10 on a FreeNAS jail using a standard LAMP setup for FreeBSD (FAMP)
  
You have Jails configured
+
This guide is a mix of several other guides I found for installing OwnCloud. The process for OC9 and NC10 is virtually identical. But most of the guides were out of date in regards to FreeNAS, so I updated it for FreeNAS 9.10.1, Nextcloud 10, Apache 2.4, PHP 7, and MariaDB 10.1 and FreeBSD 10+ Jail. I sourced all of the guides and pages I had used down at the bottom.
  
== Setting Up Jail ==
+
== '''Getting Started -''' ==
 +
'''General Assumptions:'''
 +
* You are familiar with Linux and comfortable with command line, but not so familiar with FreeBSD
 +
* You have already set up a proper pool for your NextCloud dataset
 +
* You are using FreeNAS 9.10.1-RELEASE with FreeBSD Jail Template "------"
 +
* Your FreeNAS is connected to the internet, and your jails are properly configured.
 +
* That you're generally on a clean install of 9.10.1-RELEASE, upgrades from 9.3, 9.2.1, etc have some issues with jails and templates. I ain't got time for that nonsense so this was a fresh install for me.
 +
* You're using this for maybe a small start-up with no more than 100 users.
 +
''''''Specifics:''''''
  
=== Create Dataset<ref name=":0">https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/</ref> ===
+
My Build: A real budget strapped build. (<$1400)
 +
 
 +
ASRock C2550d4n
 +
 
 +
16GB Crucial (2x8gb) DDR3-1600 EUDIMM 1.35v
 +
 
 +
x2 5TB HGST NAS 7200rpm 
 +
 
 +
x2 2TB Seagate Barracuda 7200rpm (These two are used for my NextCloud setup)
 +
 
 +
Target: 100+ users for Cloud and Archive storage, currently, with disk-to-disk mirroring. Soon to be expanded to a proper raid when I get the funds.
 +
 
 +
== '''Creating the Dataset & Jail''' ==
 +
 
 +
=== '''Let's Begin''' ===
 +
'''''Pool Name: "SETV_Cloud"'''''
 +
 
 +
'''''Static IP Address: 10.130.12.191'''''
 +
 
 +
==== '''Create Dataset'''<ref name=":02">https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/</ref> ====
 
Within FreeNAS Userspace:
 
Within FreeNAS Userspace:
  
Line 25: Line 52:
 
* All other options default
 
* All other options default
  
=== Create Jail ===
+
==== '''Create Jail''' ====
 
Jails > Add Jail
 
Jails > Add Jail
 +
 
* Jail Name: nextcloud
 
* Jail Name: nextcloud
 
* Template: "------"
 
* Template: "------"
* IPv4 Address: 10.130.12.191
+
* IPv4 Address: 10.130.10.121
 
* IPv4 Subnet: 255.255.248.0
 
* IPv4 Subnet: 255.255.248.0
 
* Leave all else default
 
* Leave all else default
 
* Ensure VIMAGE is checked
 
* Ensure VIMAGE is checked
Add Storage
+
 
 +
==== Add Storage ====
 +
Jails -> Storage
 
* Jail: nextcloud
 
* Jail: nextcloud
 
* Source = /mnt/SETV_Cloud/files
 
* Source = /mnt/SETV_Cloud/files
Line 42: Line 72:
 
* Destination = /var/db/mysql
 
* Destination = /var/db/mysql
  
==== Setting primary cache ====
+
==== '''Setting primary cache''' ====
 
In FreeNAS UserSpace Shell
 
In FreeNAS UserSpace Shell
zfs set primarycache=metadata SETV_Cloud/db
 
  
== Configure Jail for First Use ==
+
<code><kbd>$ zfs set primarycache=metadata Cloud/db</kbd></code>
 +
 
 +
=== '''Configure Jail for SSH''' ===
 
We need to set up the jail to be able to SSH in and make faster adjustments.
 
We need to set up the jail to be able to SSH in and make faster adjustments.
  
 
Enter the Jail's shell from within FreeNAS
 
Enter the Jail's shell from within FreeNAS
pkg upgrade
 
If it asks any questions, select Y and continue.
 
  
==== Enable SSH ====
+
<code><kbd>$ pkg upgrade</kbd></code>
$ cd /etc/ssh
 
$ vi sshd_config
 
Personally I despise vi, but this is the quickest method.
 
  
Scroll down using the DOWN arrow key until you find  <code>#PermitRootLogin no</code> line.
+
If it asks any questions, select Y and continue.
  
With the cursor on the <code>#</code> hit <code>x</code> this will delete the hash now use the RIGHT arrow key to select the space before 'no'
+
==== '''Enable SSH''' ====
 +
<code><kbd>$ cd /etc/ssh</kbd></code>
  
Hit <code>i</code> type <code>yes</code>
+
<code><kbd>$ vi sshd_config</kbd></code>
  
Hit <code>esc</code>
+
''Personally, I despise vi, but this is the quickest method I have found. Know a way better, please let me know.''
  
Select the n in 'no' and hit <code>x</code> twice to delete 'no' so the line reads  <code>PermitRootLogin yes</code> 
+
''if you don't know how to use vi, here's a quick step by step. I suggest you check out this [http://www.lagmonster.org/docs/vi.html cheat sheet]''
  
type <code>:wq</code>
+
# Scroll down using the DOWN arrow key until you find <code><kbd>#PermitRootLogin no</kbd></code> line.
 +
# With the cursor on the # hit x this will delete the hash now use the RIGHT arrow key to select the space before 'no'
 +
# Hit <code><kbd>i</kbd></code> type <code><kbd>yes</kbd></code>
 +
# Hit <code><kbd>esc</kbd></code>
 +
# Select the n in 'no' and hit x twice to delete 'no' so the line reads PermitRootLogin yes
 +
# type <code><kbd>:wq</kbd></code>
 +
# Hit ENTER
 +
# The file is now saved
  
Hit <code>ENTER</code>
+
==== '''Now enable and start SSH''' ====
  
The file is now saved
+
<code><kbd>$ sysrc sshd_enable=yes</kbd></code>
  
Now enable and start SSH
+
<code><kbd>$ service ssh start</kbd></code>
$ sysrc sshd_enable=yes
 
$ service ssh start
 
  
==== Change Jail Root PW ====
+
===== '''Change Jail Root PW''' =====
 
We need to reset the jails root password; type this command, and follow the prompts
 
We need to reset the jails root password; type this command, and follow the prompts
$ passwd
+
 
 +
<code><kbd>$ passwd</kbd></code>
  
 
Now close the shell within FreeNAS, and use PuTTY to SSH to the jail.
 
Now close the shell within FreeNAS, and use PuTTY to SSH to the jail.
  
== F.A.M.P Installation ==
+
== '''F.A.M.P Installation''' ==
In this section we are going to install F.A.M.P, an iteration of LAMP (Linux, Apache, MySQL, PHP)
+
In this section we are going to install F.A.M.P, an iteration of LAMP (Linux, Apache, MySQL, PHP). I chose this because I, personally, haven't had much luck with nginx and mariadb. Another guide suggested lighttp and sqlite, but those might not hold up to a good amount of users storing a bit of data.
 +
 
 +
The setup is:
 
* FreeBSD 10.1
 
* FreeBSD 10.1
 
* Apache 2.4
 
* Apache 2.4
 
* MariaDB 10.1
 
* MariaDB 10.1
 
* PHP 7.0
 
* PHP 7.0
This provides the basics for our webserving jail.
+
This provides the basis for our webserving jail.
 +
 
 +
Before we get started, let's add a few necessary packages as they aren't currently installed.
 +
 
 +
<code><kbd>$ pkg install nano wget sudo</kbd></code>
 +
 
 +
We will install each part of FAMP one-by-one. FreeBSD is the Operating system so good to go on that!
  
Before we get started, let's add a few necessary packages
+
=== '''Apache 2.4''' <ref name=":22">https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1</ref> ===
$ pkg install nano wget sudo
 
$ vi sshd_config
 
We will install each part of FAMP one-by-one. FreeBSD is the Operating system so check!
 
  
=== Apache 2.4 <ref name=":2">https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1</ref> ===
+
==== '''Install''' ====
 +
<code><kbd>$ pkg install apache24</kbd></code>
  
====== Install ======
+
==== '''Setup in rc.conf''' ====
$ pkg install apache24
+
<code><kbd>$ sysrc apache24_enable=yes</kbd></code>
  
====== Setup in rc.conf ======
+
==== '''Start Apache''' ====
$ sysrc apache24_enable=yes
+
<code><kbd>$ service apache24 start</kbd></code>
  
====== Start Apache ======
+
'''Check that it works'''
$ service apache24 start
 
  
====== Check that it works ======
+
Navigate to [http://10.130.12.191/ http://'''192.168.1.99'''] and you should see the text "It Works!"
Navigate to http://10.130.12.191 and you should see the text "It Works!"
 
  
=== MariaDB 10.1 <ref name=":1" /> ===
+
=== '''MariaDB 10.1''' <ref name=":12">https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/</ref> ===
  
====== Install ======
+
==== '''Install''' ====
[[File:MySQL Setup.png|thumb|MySQL Secure Setup ]]
 
$ pkg install mariadb101-server
 
  
==== Setup in rc.conf ====
+
<code><kbd>$ pkg install mariadb101-server</kbd></code>
$ sysrc mysql_enable=yes
 
  
====== Run Wizard Script ======
+
==== '''Setup in rc.conf''' ====
$ mysql_secure_installation
+
<code><kbd>$ sysrc mysql_enable=yes</kbd></code>
'''Read and follow prompts. There is no root password set, and answer Y to all the following questions.'''
+
 
 +
==== '''Run Wizard Script''' ====
 +
<code><kbd>$ mysql_secure_installation</kbd></code>
 +
 
 +
'''Read and follow prompts. There is no root password set just hit enter, and answer Y to all the following questions.'''
 +
 
 +
==== '''Login to MySQL, create Nextcloud DB and User''' ====
 +
<code><kbd>$ mysql -u root -p</kbd></code>
  
====== Login to MySQL, create Nextcloud DB and User ======
 
$ mysql -u root -p
 
 
enter password you made for root during setup.
 
enter password you made for root during setup.
  
 
Enter each of these commands one-by-one, and make sure to include the semi-colon ;
 
Enter each of these commands one-by-one, and make sure to include the semi-colon ;
  
  CREATE DATABASE nextcloud;
+
Code:
 +
  CREATE DATABASE nextcloud;  
 
   
 
   
  CREATE USER 'nextcloud_admin'@'localhost' IDENTIFIED BY 'MAKEUP-YOUR-OWN-PASSWORD';
+
  CREATE USER 'nextcloud_admin'@'localhost' IDENTIFIED BY 'MAKEUP-YOUR-OWN-PASSWORD';  
 
   
 
   
  GRANT ALL ON nextcloud.* TO 'nextcloud_admin'@'localhost';
+
  GRANT ALL ON nextcloud.* TO 'nextcloud_admin'@'localhost';  
 
   
 
   
  FLUSH PRIVILEGES;
+
  FLUSH PRIVILEGES;  
 
   
 
   
  exit
+
  exit  
 
Replace MAKEUP-YOUR-OWN-PASSWORD with a password of your choosing. You need this for the NextCloud setup.
 
Replace MAKEUP-YOUR-OWN-PASSWORD with a password of your choosing. You need this for the NextCloud setup.
  
=== PHP 7.0 ===
+
=== '''PHP 7.0''' ===
 +
 
 +
==== '''Install PHP and associated modules''' ====
 +
Code:
 +
pkg install redis php70-bz2 php70-ctype php70-curl php70-dom php70-exif php70-fileinfo php70-filter php70-gd php70-hash php70-iconv php70-intl php70-json php70-mbstring php70-mcrypt php70-pdo_mysql php70-openssl php70-posix php70-session php70-simplexml php70-xml php70-xmlreader php70-xmlwriter php70-xsl php70-wddx php70-zip php70-zlib php70-APCu php70-redis
 +
 
 +
==== Setup rc.conf ====
 +
 
 +
<code><kbd>sysrc 'mysql_enable=YES' 'redis_enable=YES'</kbd></code>
 +
 
 +
==== '''Configuring Apache for PHP7''' ====
 +
Ensure that the rewrite and ssl modules are enabled (uncommented) in /usr/local/etc/apache24/httpd.conf.
  
====== Install PHP and associated modules<ref name=":0" /> ======
+
<code><kbd>$ cd /usr/local/etc/apache24/</kbd></code>
{| class="wikitable"
 
|pkg install redis php70-bz2 php70-ctype php70-curl php70-dom php70-exif php70-fileinfo php70-filter php70-gd php70-hash php70-iconv php70-intl php70-json php70-mbstring php70-mcrypt php70-pdo_mysql php70-openssl php70-posix php70-session php70-simplexml  php70-xml php70-xmlreader php70-xmlwriter php70-xsl php70-wddx php70-zip php70-zlib php70-APCu php70-redis
 
|}
 
sysrc 'mysql_enable=YES' 'redis_enable=YES'
 
  
====== Configuring Apache for PHP7 ======
+
<code><kbd>$ nano httpd.conf</kbd></code>
Ensure that the rewrite and ssl modules are enabled (uncommented) in <code>/usr/local/etc/apache24/httpd.conf</code>.
 
  
CREATE DATABASE nextcloud;
 
$ cd /usr/local/etc/apache24/
 
$ nano httpd.conf
 
 
Search the conf file for "ssl_module"
 
Search the conf file for "ssl_module"
  ctrl+w
+
 
  ssl_module
+
Code:
 +
  ctrl+w  
 +
  ssl_module  
 
  ENTER
 
  ENTER
Uncomment (delete the <code>#</code> at the start of the line) so it looks like this:
 
LoadModule ssl_module libexec/apache24/mod_ssl.so
 
Repeat for
 
  
<code>LoadModule rewrite_module libexec/apache24/mod_rewrite.so</code>
+
Uncomment (delete the # at the start of the line) so it looks like this:
  
'''Remove php5 add php7:''' <ref>https://kdenby.homelinux.com/?p=208</ref> <ref>http://serverfault.com/questions/646333/apache-24-not-serving-php-on-freebsd-10</ref>
+
<code><kbd>LoadModule ssl_module libexec/apache24/mod_ssl.so</kbd></code>
* Find & Remove this >> LoadModule php5_module  libexec/apache24/libphp5.so
 
* Replace with >>           LoadModule php7_module  libexec/apache24/libphp7.so
 
  
 +
Repeat for
 +
 +
<code><kbd>LoadModule rewrite_module libexec/apache24/mod_rewrite.so</kbd></code>
 +
 +
==== '''Remove php5 add php7:''' <ref>http://serverfault.com/questions/646333/apache-24-not-serving-php-on-freebsd-10</ref><ref>https://kdenby.homelinux.com/?p=208</ref> ====
 +
* Find & Remove this >> <code><kbd>LoadModule php5_module libexec/apache24/libphp5.so</kbd></code>
 +
* Replace with >> <code><kbd>LoadModule php7_module libexec/apache24/libphp7.so</kbd></code>
 
Right after libphp7.so line add
 
Right after libphp7.so line add
 +
 +
Code:
 
  <IfModule php5_module>
 
  <IfModule php5_module>
 
     <FilesMatch "\.(php|phps|php5|phtml)$">
 
     <FilesMatch "\.(php|phps|php5|phtml)$">
 
         SetHandler php5-script
 
         SetHandler php5-script
 
     </FilesMatch>
 
     </FilesMatch>
     DirectoryIndex index.php
+
     DirectoryIndex index.php  
 
  </IfModule>
 
  </IfModule>
Then FIND  <code><IFModule mime_module></code>
+
Then FIND <code><kbd><IFModule mime_module></kbd></code>
  
 
Insert Right After:
 
Insert Right After:
  
 +
Code:
 
  AddType application/x-httpd-php-source .phps
 
  AddType application/x-httpd-php-source .phps
 
  AddType application/x-httpd-php        .php
 
  AddType application/x-httpd-php        .php
 +
Save the file & exit
 +
 +
==== Add a PHP handler ====
 +
<code><kbd># cd/usr/local/etc/apache24/modules.d</kbd></code>
  
Add a PHP handler <ref name=":2" /> to <code>/usr/local/etc/apache24/modules.d</code>
+
<code><kbd># touch /usr/local/etc/apache24/modules.d/001_mod_php.conf</kbd></code>
  
<code># touch /usr/local/etc/apache24/modules.d/001_mod_php.conf</code>
+
<code><kbd># nano /usr/local/etc/apache24/modules.d/001_mod_php.conf</kbd></code>
  
<code># nano /usr/local/etc/apache24/modules.d/001_mod_php.conf</code>
+
Paste:
  
    <code><FilesMatch "\.php$"></code>
+
Code:
         <code>SetHandler application/x-httpd-php</code>
+
<FilesMatch "\.php$">
     <code></FilesMatch></code>
+
         SetHandler application/x-httpd-php
     <code><FilesMatch "\.phps$"></code>
+
     </FilesMatch>
         <code>SetHandler application/x-httpd-php-source</code>
+
     <FilesMatch "\.phps$">
     <code></FilesMatch></code>
+
         SetHandler application/x-httpd-php-source
   <code></IfModule></code>
+
     </FilesMatch>
<code>service apache24 restart</code>
+
   </IfModule>
 +
Save & Exit
  
Once you're done save and close <code>CTRL+x, Y, ENTER</code>
+
<code><kbd>service apache24 restart</kbd></code>
  
====== Configure PHP.INI <ref name=":0" /> ======
+
Once you're done save and close CTRL+x, Y, ENTER
<code>$ nano /usr/local/etc/php.ini</code>
 
  
find <code>cgi.fix_pathinfo=0</code> change from =0 to =1
+
==== '''Configure PHP.INI''' <ref name=":03">https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/</ref> ====
 +
<code><kbd>$ nano /usr/local/etc/php.ini</kbd></code>
  
find <code>date.timezone =</code> Change to your timezone (America/New_York)
+
find <code><kbd>cgi.fix_pathinfo=0</kbd></code> change from =0 to =1
  
find <code>post_max_size=</code> change it to 1999M
+
find <code><kbd>date.timezone =</kbd></code> Change to your timezone (America/New_York)
  
find <code>upload_max_size=</code> change to 1999M
+
find <code><kbd>post_max_size=</kbd></code> change it to 1999M
  
CTRL+X, Y, ENTER
+
find <code><kbd>upload_max_size=</kbd></code> change to 1999M
 +
 
 +
CTRL+X, Y, ENTER
  
 
Restart Apache
 
Restart Apache
$ service apache24 restart
 
  
===== Testing with PHPINFO() <ref name=":2" /><ref>https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page</ref> =====
+
<code><kbd>$ service apache24 restart</kbd></code>
Navigate to <code>/usr/local/www/apache24/data/</code>  
+
 
 +
===== '''Testing with PHPINFO()''' <ref>https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page</ref><ref name=":23">https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1</ref> =====
 +
Navigate to <code><kbd>/usr/local/www/apache24/data/</kbd></code>
 +
 
 +
<code><kbd>$ touch info.php</kbd></code>
 +
 
 +
<code><kbd>$ nano info.php</kbd></code>
  
$ touch info.php
 
$ nano info.php
 
 
Paste:
 
Paste:
  
 +
Code:
 
  <?php
 
  <?php
// Show all information, defaults to INFO_ALL
+
  // Show all information, defaults to INFO_ALL
phpinfo();
+
  phpinfo();
?>
+
  ?>
  
 
Save & Exit
 
Save & Exit
  
Navigate to <code>http://10.130.12.191/info.php</code>
+
Navigate to [http://10.130.12.191/info.php http://'''192.168.1.99'''/info.php]
  
 
You should see a full page with all the information regarding your PHP installation.
 
You should see a full page with all the information regarding your PHP installation.
  
=== Configure REDIS <ref name=":1">https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/</ref> ===
+
=== '''Configure REDIS''' <ref name=":13">https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/</ref> ===
Update <code>/usr/local/etc/redis.conf</code> to run on local socket
+
Update <code><kbd>/usr/local/etc/redis.conf</kbd></code>to run on local socket
  
Find <code>port=</code> and change it to 0
+
Find <code><kbd>port=</kbd></code> and change it to 0
  
 
Find and replace:
 
Find and replace:
  unixsocket /tmp/redis.sock
+
 
 +
Code:
 +
  unixsocket /tmp/redis.sock  
 
  unixsocketperm 750
 
  unixsocketperm 750
  
$ sysrc redis_enable=yes
+
==== Add REDIS to rc.conf ====
 +
<code><kbd>$ sysrc redis_enable=yes</kbd></code>
  
$ service redis start
+
==== Start REDIS ====
 +
<code><kbd>$ service redis start</kbd></code>
  
Run  <code>ls -al /tmp</code> to run on local socket, you should see redis.sock and mysql.sock in the list.
+
==== Check Redis ====
 +
Run <code><kbd>ls -al /tmp</kbd></code> to run on local socket, you should see redis.sock and mysql.sock in the list.
  
 
If you see those two, you're ALMOST DONE!!
 
If you see those two, you're ALMOST DONE!!
  
== Installing NextCloud <ref name=":1" /> ==
+
== '''Installing NextCloud'''<ref name=":14">https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/</ref> ==
Download in apache data directory <code>/usr/local/www/apache24/data/</code>
+
 
# Go to the default apache data directory  
+
=== Download ===
cd /usr/local/www/apache24/data  
+
Go to the default apache data directory
<nowiki>#</nowiki> Download Nextcloud  
+
 
wget <nowiki>https://download.nextcloud.com/server/releases/nextcloud-10.0.0.zip</nowiki>  
+
<code><kbd>$ cd /usr/local/www/apache24/data</kbd></code>
# Unzip Nextcloud  
+
 
unzip nextcloud-10.0.0.zip
+
Download Nextcloud
 +
 
 +
<code><kbd>$ wget <nowiki>https://download.nextcloud.com/server/releases/nextcloud-10.0.0.zip</nowiki></kbd></code>
 +
 
 +
Unzip Nextcloud
 +
 
 +
<code><kbd>$ unzip nextcloud-10.0.0.zip</kbd></code>
 +
 
 +
Give correct owner
 +
 
 +
<code><kbd>chown -R www:www /usr/local/www/apache24/data/nextcloud /mnt/files</kbd></code>
  
Extract
+
=== '''Add virtual Host info''' <ref>https://www.linuxbabe.com/cloud-storage/setup-nextcloud-server-ubuntu-16-04-apache-mariadb-php7</ref> ===
chown -R www:www /usr/local/www/apache24/data/nextcloud /mnt/files
+
Navigate to <code><kbd>/usr/local/etc/apache24/Includes</kbd></code>
  
====== Add virtual Host info <ref>https://www.linuxbabe.com/cloud-storage/setup-nextcloud-server-ubuntu-16-04-apache-mariadb-php7</ref> ======
+
Touch file:
Navigate to <code>/usr/local/etc/apache24/Includes</code>
 
Make file:
 
$ touch cloud.ssdcougars.tv.conf
 
  
$ nano cloud*
+
<code><kbd>$ touch cloud.YOURDOMAIN.com.conf</kbd></code>
Copy and paste the below text !!!!THIS DOES NOT INCLUDE MOD_REWITE!!!!! It will be enabled once we get a glocal URL.
+
 
  <VirtualHost *:80>
+
<code><kbd>$ nano cloud*</kbd></code>
<nowiki> </nowiki>DocumentRoot "/usr/local/www/apache24/data/nextcloud"
+
 
<nowiki> </nowiki>ServerName cloud.ssdcougars.tv
+
Copy and paste the below text.
<nowiki>#</nowiki>  RewriteEngine on
+
 
<nowiki>#</nowiki>  RewriteCond %{SERVER_NAME} =cloud.ssdcougars.tv
+
'''''I commented out mod_rewrite and did not include SSL because I am waiting to setup a real domain to attach to it and did not want to run into issues until I had the domain.'''''
<nowiki>#</nowiki>  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
+
 
  #ErrorLog ${APACHE_LOG_DIR}/error.log
+
Code:
  #CustomLog ${APACHE_LOG_DIR}/access.log combined
+
  <VirtualHost *:80><nowiki> </nowiki>DocumentRoot "/usr/local/www/apache24/data/nextcloud"<nowiki> </nowiki>ServerName cloud.ssdcougars.tv <nowiki>#</nowiki>  RewriteEngine on <nowiki>#</nowiki>  RewriteCond %{SERVER_NAME} =cloud.ssdcougars.tv <nowiki>#</nowiki>  RewriteRule ^ [https://%25%7Bserver_name%7D%25%7Brequest_uri%7D/ https://%{SERVER_NAME}%{REQUEST_URI}] [END,QSA,R=permanent] #ErrorLog ${APACHE_LOG_DIR}/error.log #CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /usr/local/www/apache24/data/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /usr/local/www/apache24/data/nextcloud SetEnv HTTP_HOME /usr/local/www/apache24/data/nextcloud Satisfy Any </Directory> </VirtualHost>
<Directory /usr/local/www/apache24/data/nextcloud/>
+
 
  Options +FollowSymlinks
+
Restart apache... again...
  AllowOverride All
+
 
  <IfModule mod_dav.c>
+
<code><kbd>$ service apache24 restart</kbd></code>
  Dav off
 
  </IfModule>
 
  SetEnv HOME /usr/local/www/apache24/data/nextcloud
 
  SetEnv HTTP_HOME /usr/local/www/apache24/data/nextcloud
 
  Satisfy Any
 
</Directory>
 
</VirtualHost>
 
  
Restart apache again
 
$ service apache24 restart
 
 
Navigate to the website
 
Navigate to the website
<nowiki>http://10.130.12.191/</nowiki>
 
  
You should now see the setup screen for NextCloud
+
[http://10.130.12.191/ http://'''192.168.1.99'''/]
 +
 
 +
You should now see the setup screen for NextCloud!!
  
====== '''NextCloud WebUI'''  ======
+
If you do, give yourself a pat on the back. Now for the last steps...
 +
 
 +
== ''''''NextCloud WebUI'''''' ==
 
Set up your admin account with a username and password you choose.
 
Set up your admin account with a username and password you choose.
  
Storage & database
+
=== Storage & database ===
 
* Data folder = /mnt/files
 
* Data folder = /mnt/files
 
* Database user = nextcloud_admin
 
* Database user = nextcloud_admin
Line 306: Line 373:
 
* Database name = nextcloud
 
* Database name = nextcloud
 
* Database host = localhost:/tmp/mysql.sock
 
* Database host = localhost:/tmp/mysql.sock
Jail Shell:
 
  
'''Console in jail's userland'''
+
=== '''Final Setup''' ===
 +
In Jail Shell
 +
 
 +
==== Setup redis for caching ====
  
 
Code:
 
Code:
  su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.local --value="\OC\Memcache\APCu"'  
+
  $ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.local --value="\OC\Memcache\APCu"'  
  su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis"'  
+
  $ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis"'  
  su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis host --value="/tmp/redis.sock"'  
+
  $ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis host --value="/tmp/redis.sock"'  
  su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis port --value=0 --type=integer'  
+
  $ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis port --value=0 --type=integer'
  
'''Console in jail's userland'''
+
==== Setup NC's cron jobs ====
 +
 
 +
<code><kbd>crontab -u www -e</kbd></code>
  
 
Code:
 
Code:
  crontab -u www -e
+
  */15 * * * * /usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php
 
 
<code>*/15 * * * * /usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php</code>
 
  
 
And VOILA! YOU ARE DONE!!!!!
 
And VOILA! YOU ARE DONE!!!!!
  
Stay Tuned for a CallaboraOnline setup.
+
I have NOT yet installed the CollaboraOnline stuff yet. I will have to figure that out....
 
 
===== CITES =====
 
https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1
 
 
 
https://www.linuxbabe.com/cloud-storage/setup-nextcloud-server-ubuntu-16-04-apache-mariadb-php7
 
 
 
https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/
 
 
 
https://forums.freenas.org/index.php?threads/drkks-definitive-guide-to-installing-owncloud-in-freenas-or-freebsd.19605/
 
<references />
 

Revision as of 07:48, 17 September 2016

HOW TO: INSTALL NEXTCLOUD 10 ON FREEBSD JAIL

I wrote this guide primarily as a backup in case I needed to redo things over again, and decided to spruce it up and share it with others.

The Goal:

Put Nextcloud 10 on a FreeNAS jail using a standard LAMP setup for FreeBSD (FAMP)

This guide is a mix of several other guides I found for installing OwnCloud. The process for OC9 and NC10 is virtually identical. But most of the guides were out of date in regards to FreeNAS, so I updated it for FreeNAS 9.10.1, Nextcloud 10, Apache 2.4, PHP 7, and MariaDB 10.1 and FreeBSD 10+ Jail. I sourced all of the guides and pages I had used down at the bottom.

Getting Started - 

General Assumptions:

  • You are familiar with Linux and comfortable with command line, but not so familiar with FreeBSD
  • You have already set up a proper pool for your NextCloud dataset
  • You are using FreeNAS 9.10.1-RELEASE with FreeBSD Jail Template "------"
  • Your FreeNAS is connected to the internet, and your jails are properly configured.
  • That you're generally on a clean install of 9.10.1-RELEASE, upgrades from 9.3, 9.2.1, etc have some issues with jails and templates. I ain't got time for that nonsense so this was a fresh install for me.
  • You're using this for maybe a small start-up with no more than 100 users.

'Specifics:'

My Build: A real budget strapped build. (<$1400)

ASRock C2550d4n

16GB Crucial (2x8gb) DDR3-1600 EUDIMM 1.35v

x2 5TB HGST NAS 7200rpm 

x2 2TB Seagate Barracuda 7200rpm (These two are used for my NextCloud setup)

Target: 100+ users for Cloud and Archive storage, currently, with disk-to-disk mirroring. Soon to be expanded to a proper raid when I get the funds.

Creating the Dataset & Jail 

Let's Begin

Pool Name: "SETV_Cloud"

Static IP Address: 10.130.12.191

Create Dataset[1]

Within FreeNAS Userspace:

Storage > Create ZFS Dataset

  • Dataset Name = files
  • Compression level = lz4
  • Enable atime = Off
  • All other options default
  • Dataset Name = db
  • Compression level = zle
  • Enable atime = Off
  • Record Size = 16K (Under Advanced Mode)
  • All other options default

Create Jail

Jails > Add Jail

  • Jail Name: nextcloud
  • Template: "------"
  • IPv4 Address: 10.130.10.121
  • IPv4 Subnet: 255.255.248.0
  • Leave all else default
  • Ensure VIMAGE is checked

Add Storage

Jails -> Storage

  • Jail: nextcloud
  • Source = /mnt/SETV_Cloud/files
  • Destination = /mnt/files
  • Jail: nextcloud
  • Source = /mnt/SETV_Cloud/db
  • Destination = /var/db/mysql

Setting primary cache

In FreeNAS UserSpace Shell

$ zfs set primarycache=metadata Cloud/db

Configure Jail for SSH

We need to set up the jail to be able to SSH in and make faster adjustments.

Enter the Jail's shell from within FreeNAS

$ pkg upgrade

If it asks any questions, select Y and continue.

Enable SSH

$ cd /etc/ssh

$ vi sshd_config

Personally, I despise vi, but this is the quickest method I have found. Know a way better, please let me know.

if you don't know how to use vi, here's a quick step by step. I suggest you check out this cheat sheet

  1. Scroll down using the DOWN arrow key until you find #PermitRootLogin no line.
  2. With the cursor on the # hit x this will delete the hash now use the RIGHT arrow key to select the space before 'no'
  3. Hit i type yes
  4. Hit esc
  5. Select the n in 'no' and hit x twice to delete 'no' so the line reads PermitRootLogin yes
  6. type :wq
  7. Hit ENTER
  8. The file is now saved

Now enable and start SSH

$ sysrc sshd_enable=yes

$ service ssh start

Change Jail Root PW

We need to reset the jails root password; type this command, and follow the prompts

$ passwd

Now close the shell within FreeNAS, and use PuTTY to SSH to the jail.

F.A.M.P Installation

In this section we are going to install F.A.M.P, an iteration of LAMP (Linux, Apache, MySQL, PHP). I chose this because I, personally, haven't had much luck with nginx and mariadb. Another guide suggested lighttp and sqlite, but those might not hold up to a good amount of users storing a bit of data.

The setup is:

  • FreeBSD 10.1
  • Apache 2.4
  • MariaDB 10.1
  • PHP 7.0

This provides the basis for our webserving jail.

Before we get started, let's add a few necessary packages as they aren't currently installed.

$ pkg install nano wget sudo

We will install each part of FAMP one-by-one. FreeBSD is the Operating system so good to go on that!

Apache 2.4 [2]

Install

$ pkg install apache24

Setup in rc.conf

$ sysrc apache24_enable=yes

Start Apache

$ service apache24 start

Check that it works

Navigate to http://192.168.1.99 and you should see the text "It Works!"

MariaDB 10.1 [3]

Install

$ pkg install mariadb101-server

Setup in rc.conf

$ sysrc mysql_enable=yes

Run Wizard Script

$ mysql_secure_installation

Read and follow prompts. There is no root password set just hit enter, and answer Y to all the following questions.

Login to MySQL, create Nextcloud DB and User

$ mysql -u root -p

enter password you made for root during setup.

Enter each of these commands one-by-one, and make sure to include the semi-colon ;

Code:

CREATE DATABASE nextcloud; 

CREATE USER 'nextcloud_admin'@'localhost' IDENTIFIED BY 'MAKEUP-YOUR-OWN-PASSWORD'; 

GRANT ALL ON nextcloud.* TO 'nextcloud_admin'@'localhost'; 

FLUSH PRIVILEGES; 

exit 

Replace MAKEUP-YOUR-OWN-PASSWORD with a password of your choosing. You need this for the NextCloud setup.

PHP 7.0

Install PHP and associated modules

Code:

pkg install redis php70-bz2 php70-ctype php70-curl php70-dom php70-exif php70-fileinfo php70-filter php70-gd php70-hash php70-iconv php70-intl php70-json php70-mbstring php70-mcrypt php70-pdo_mysql php70-openssl php70-posix php70-session php70-simplexml php70-xml php70-xmlreader php70-xmlwriter php70-xsl php70-wddx php70-zip php70-zlib php70-APCu php70-redis

Setup rc.conf

sysrc 'mysql_enable=YES' 'redis_enable=YES'

Configuring Apache for PHP7

Ensure that the rewrite and ssl modules are enabled (uncommented) in /usr/local/etc/apache24/httpd.conf.

$ cd /usr/local/etc/apache24/

$ nano httpd.conf

Search the conf file for "ssl_module"

Code:

ctrl+w 
ssl_module 
ENTER

Uncomment (delete the # at the start of the line) so it looks like this:

LoadModule ssl_module libexec/apache24/mod_ssl.so

Repeat for

LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Remove php5 add php7: [4][5]

  • Find & Remove this >> LoadModule php5_module libexec/apache24/libphp5.so
  • Replace with >> LoadModule php7_module libexec/apache24/libphp7.so

Right after libphp7.so line add

Code:

<IfModule php5_module>
   <FilesMatch "\.(php|phps|php5|phtml)$">
       SetHandler php5-script
   </FilesMatch>
   DirectoryIndex index.php 
</IfModule>

Then FIND <IFModule mime_module>

Insert Right After:

Code:

AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php        .php

Save the file & exit

Add a PHP handler

# cd/usr/local/etc/apache24/modules.d

# touch /usr/local/etc/apache24/modules.d/001_mod_php.conf

# nano /usr/local/etc/apache24/modules.d/001_mod_php.conf

Paste:

Code:

<FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
 </IfModule>

Save & Exit

service apache24 restart

Once you're done save and close CTRL+x, Y, ENTER

Configure PHP.INI [6]

$ nano /usr/local/etc/php.ini

find cgi.fix_pathinfo=0 change from =0 to =1

find date.timezone = Change to your timezone (America/New_York)

find post_max_size= change it to 1999M

find upload_max_size= change to 1999M

CTRL+X, Y, ENTER

Restart Apache

$ service apache24 restart

Testing with PHPINFO() [7][8]

Navigate to /usr/local/www/apache24/data/

$ touch info.php

$ nano info.php

Paste:

Code:

<?php
 // Show all information, defaults to INFO_ALL
 phpinfo();
 ?>

Save & Exit

Navigate to http://192.168.1.99/info.php

You should see a full page with all the information regarding your PHP installation.

Configure REDIS [9]

Update /usr/local/etc/redis.confto run on local socket

Find port= and change it to 0

Find and replace:

Code:

unixsocket /tmp/redis.sock 
unixsocketperm 750

Add REDIS to rc.conf

$ sysrc redis_enable=yes

Start REDIS

$ service redis start

Check Redis

Run ls -al /tmp to run on local socket, you should see redis.sock and mysql.sock in the list.

If you see those two, you're ALMOST DONE!!

Installing NextCloud[10]

Download

Go to the default apache data directory

$ cd /usr/local/www/apache24/data

Download Nextcloud

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

Unzip Nextcloud

$ unzip nextcloud-10.0.0.zip

Give correct owner

chown -R www:www /usr/local/www/apache24/data/nextcloud /mnt/files

Add virtual Host info [11]

Navigate to /usr/local/etc/apache24/Includes

Touch file:

$ touch cloud.YOURDOMAIN.com.conf

$ nano cloud*

Copy and paste the below text.

I commented out mod_rewrite and did not include SSL because I am waiting to setup a real domain to attach to it and did not want to run into issues until I had the domain.

Code:

<VirtualHost *:80> DocumentRoot "/usr/local/www/apache24/data/nextcloud" ServerName cloud.ssdcougars.tv #   RewriteEngine on #   RewriteCond %{SERVER_NAME} =cloud.ssdcougars.tv #   RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] #ErrorLog ${APACHE_LOG_DIR}/error.log #CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /usr/local/www/apache24/data/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /usr/local/www/apache24/data/nextcloud SetEnv HTTP_HOME /usr/local/www/apache24/data/nextcloud Satisfy Any </Directory> </VirtualHost>

Restart apache... again...

$ service apache24 restart

Navigate to the website

http://192.168.1.99/

You should now see the setup screen for NextCloud!!

If you do, give yourself a pat on the back. Now for the last steps...

'NextCloud WebUI'

Set up your admin account with a username and password you choose.

Storage & database

  • Data folder = /mnt/files
  • Database user = nextcloud_admin
  • Database password = MADEUP_PASSWORD_FROM_BEFORE
  • Database name = nextcloud
  • Database host = localhost:/tmp/mysql.sock

Final Setup

In Jail Shell

Setup redis for caching

Code:

$ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.local --value="\OC\Memcache\APCu"' 
$ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis"' 
$ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis host --value="/tmp/redis.sock"' 
$ su -m www -c 'php /usr/local/www/apache24/data/nextcloud/occ config:system:set redis port --value=0 --type=integer'

Setup NC's cron jobs

crontab -u www -e

Code:

*/15 * * * * /usr/local/bin/php -f /usr/local/www/apache24/data/nextcloud/cron.php

And VOILA! YOU ARE DONE!!!!!

I have NOT yet installed the CollaboraOnline stuff yet. I will have to figure that out....
  1. https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/
  2. https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1
  3. https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/
  4. http://serverfault.com/questions/646333/apache-24-not-serving-php-on-freebsd-10
  5. https://kdenby.homelinux.com/?p=208
  6. https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/
  7. https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page
  8. https://www.digitalocean.com/community/tutorials/how-to-install-an-apache-mysql-and-php-famp-stack-on-freebsd-10-1
  9. https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/
  10. https://levlaz.org/installing-nextcloud-on-a-freebsd-vps/
  11. https://www.linuxbabe.com/cloud-storage/setup-nextcloud-server-ubuntu-16-04-apache-mariadb-php7