Page 1 of 1

Owncloud 8 on Ubuntu 14.04 LTS

Posted: Mon Feb 29, 2016 10:16 am
by dedwards
Install MySQL Server :

Code: Select all

sudo apt-get install mysql-server-5.6
sudo service mysql restart
While installation you will see couple of screen to set the MySQL root password. Hence, set a strong password for root user.

Login into MySQL Server with root user and password you set in the previous step:

Code: Select all

mysql -u root -p
At the mysql prompt after login (mysql> ) type the folllowing:

Code: Select all

mysql> create database owncloudDB;
mysql> CREATE USER 'ownclouduser'@'localhost' IDENTIFIED BY 'Password';
mysql> GRANT ALL ON owncloudDB.* TO 'ownclouduser'@'localhost'; 
mysql> flush privileges;
mysql> exit
Install Apache,php and php mysql module:

Code: Select all

sudo apt-get install apache2 php5 php5-mysql
Enable required Apache modules:

Code: Select all

sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
Restart Apache:

Code: Select all

sudo service apache2 restart
Install Owncloud:

Code: Select all

sudo sh -c "echo 'deb http://download.opensuse.org/repositories/isv:/ownCloud:/community/xUbuntu_14.04/ /' >> /etc/apt/sources.list.d/owncloud.list"
wget http://download.opensuse.org/repositories/isv:ownCloud:community/xUbuntu_14.04/Release.key
sudo apt-key add - < Release.key  
sudo apt-get update
sudo apt-get install owncloud
Create an owncloud-ssl.conf file in /etc/apache2/sites-available and enter the following:

Code: Select all

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin support@deeztek.com
DocumentRoot /var/www/owncloud
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile      /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
#SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.cer
#SSLCACertificateFile /etc/ssl/certs/ca.cer
#Strong SSL Ciphers for Apache Below
SSLProtocol ALL -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
SSLCompression off
#SSLSessionTickets Off
SSLUseStapling on

<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

<Directory /var/www/owncloud>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>

</VirtualHost>
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
</IfModule>
Disable default ssl site:

Code: Select all

a2dissite default-ssl.conf
Enable owncloud-ssl.conf:

Code: Select all

a2ensite owncloud-ssl.conf
Restart Apache2:

Code: Select all

service apache2 restart
Open the web browser and in address field, type the ip address of server prefix with /owncloud:

Code: Select all

https://IP-ADDRESS-OF-SERVER
Set the Admin username and password for Owncloud. Give the details of database that was created previously. Wait for a few minutes, and you will see Owncloud dashboard and admin user by default get login on first time.

Go under Apps --> Not Enabled and enable the External Storage support

In order to enable SMB/CIFS external storage, you must install smbclient and php5-libsmbclient from the command line:

Code: Select all

apt-get install smbclient
apt-get install php5-libsmbclient
Edit /var/www/owncloud/.htaccess file and set the following parameters:

Code: Select all

php_value upload_max_filesize 4G
php_value post_max_size 4G
php_value memory_limit 4G
Create script to update owncloud filesystem at regular intervals:

Code: Select all

vi /scripts/owncloud_update_files.sh
Paste the following:

Code: Select all

#!/bin/sh
sudo -H -u www-data bash -c 'php /var/www/owncloud/console.php files:scan --all'
Save and make executable:

Code: Select all

chmod +x /scripts/owncloud_update_files.sh
schedule a cron job to run the script every 5 minutes:

Code: Select all

# m h  dom mon dow   command
00 19 * * * /scripts/owncloud_backup.sh
05 *  * * * /scripts/owncloud_update_files.sh
Ensure /var/www/owncloud is owned by www-data:

Code: Select all

chown –R www-data /var/www/owncloud
Setup Owncloud Backups

Create backup script in /scripts/owncloud_backup.sh:

Code: Select all

vi /scripts/owncloud/backup.sh
Paste the following ensuring that the you change the relevant server names, paths, usernames and passwords to match your configuration:

Code: Select all

#Umount Backup Directory
/bin/umount /mnt/owncloud

/sbin/mount.cifs //backupserver/backupshare /mnt/owncloud -o username=username,password=password

#EXAMPLE DOMAIN MOUNT
/sbin/mount.cifs //2008-server.firstmd.local/owncloudbackups /mnt/owncloud -o username=owncloudbackups,dom=FIRSTMD,password=SOMEPASSWORD

#CHECK IF MOUNT EXISTS
if mount | grep -q "/mnt/owncloud"; then

#BACKUP DATABASE

/usr/bin/mysqldump --user=root --password=dbasepassword --opt owncloudDB>/mnt/owncloud/dbase/`date +%m-%d-%Y-%H%M`-owncloudDB.sql

#BACKUP DATA

/usr/bin/rsync -r -v --progress --delete /var/www/owncloud/data /mnt/owncloud/data


#BACKUP CONFIG

/usr/bin/rsync -r -v --progress --delete /var/www/owncloud/config /mnt/owncloud/config


#Delete backup files older than 14 days
/usr/bin/find /mnt/owncloud/dbase -mtime +14 -exec rm {} \;


#Umount Backup Directory
/bin/umount /mnt/owncloud

#SEND EMAIL CONFIRMATION
/usr/bin/sendemail -f from@domain.tld -t to@domain.tld -u "Owncloud backup completed" -m "Owncloud backup completed"  -s smtpserver

else

#SEND EMAIL MOUNT ERROR
/usr/bin/sendemail -f from@domain.tld -t to@domain.tld -u "Owncloud Mount Backup Error" -m "Unable to mount Owncloud backup mount point"  -s smtpserver

fi
Make script executable:

Code: Select all

/scripts/owncloud/backup.sh
Ensure you create a "dbase" directory on the backup share or the script will fail

Schedule a cron job to run the backup script daily:

Code: Select all

crontab -e
Paste the following:

Code: Select all

00 19 * * * /scripts/owncloud_backup.sh
Install sendemail:

Code: Select all

apt-get install sendemail
Install cifs-utils:

Code: Select all

apt-get install cifs-utils
Create Owncloud backups mount point to match the backup script above:

Code: Select all

mkdir /mnt/owncloud