How to Install latest Owncloud 9.1.1 in Ubuntu 16.04.

share on:
how to install owncloud on ubuntu server
Here’s a simple Script to install OWNCLOUD  on UBUNTU 16.04 unattended. I have tested this script few times on fresh servlet from Digitalocean.

I m not giving any guarantees here and I have no interest in damaging your system also ????.

If you want to use this script then I will request you to try this script on new servlet only, you can try it on old servlet at your own risk.

This script will create three info files in /root directory.

  • OWNCLOUD.txt
  • LAMP.txt
  • Mysql_password-Change.txt

This script will save OwnCloud database and user info in  /root/OWNCLOUD.txt  and MySQL user &  password in  /root/LAMP.txt

.

If you want to set MySQL root password of your choice, then you can find instructions about that in

/root/Mysql_password-Change.txt .

 

Please don’t use this script in production servers.  🙂

 

Owncloud ubuntu server Script

 

#!/bin/sh

	# Updating system
	apt-get update -y	
	apt-get install rsync wget curl unzip pwgen debconf-utils apache2 firewalld -y

	# Solve apr_sockaddr_info_get() or in simple Hostname problem.
	echo "ServerName localhost" >> /etc/apache2/apache2.conf 
	a2enmod rewrite
	systemctl enable apache2
	systemctl restart apache2

	# apt-get update -y > /dev/null 2>&1
	PASSWORD=pwgen -c -1 8

	export DEBIAN_FRONTEND=noninteractive
	debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
	debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"

	# # ********************************* Installing MySQL-SERVER *********************************
	apt-get install mysql-server -y

	# echo "Maually doing what "mysql_secure_installation" is supposed to do."
	mysql -uroot -p"$PASSWORD" -e "UPDATE mysql.user SET Password=PASSWORD('$PASSWORD') WHERE User='root'" > /dev/null 2>&1
	mysql -uroot -p"$PASSWORD" -e "DELETE FROM mysql.user where User='root' and Host not in ('localhost','127.0.0.1', '::1')" > /dev/null 2>&1
	mysql -uroot -p"$PASSWORD" -e "DELETE FROM mysql.user where User=''" > /dev/null 2>&1
	mysql -uroot -p"$PASSWORD" -e "DELETE from mysql.db where db='test' or Db='test\_%'" > /dev/null 2>&1
	mysql -uroot -p"$PASSWORD" -e "FLUSH PRIVILEGES" > /dev/null 2>&1				

	# restarting MYSQL service

	systemctl enable mysql.service
	systemctl start mysql.service

	# Saving info about Password FOR MySQL-server and How to change Password Later.
	echo -e "username root \npassword $PASSWORD\n                 >>>>>Have a Nice Day<<<<<\n" >> /root/LAMP.txt
	echo -e "\n\n\n           To change the password to your liking just use this command.\n\n               mysqladmin -u root -p'oldpassword' password 'newpassword'\n\n\n               Don't forget to change "oldpassword" and "newpassword" value.\n\n\n" >> /root/Mysql_password-Change.txt	



	# ********************************* Installing PHP *********************************
	sudo apt-get install php libapache2-mod-php php-gd php-json php-curl php-intl php-mcrypt php-mysql php-imagick php-zip php-xml php-mbstring -y
	echo -e "<IfModule mod_dir.c>\n    DirectoryIndex index.php index.html index.cgi index.xhtml index.pl index.htm\n </IfModule>" > /etc/apache2/mods-enabled/dir.conf

	firewall-cmd --add-service=http --add-service=https --permanent
	firewall-cmd --add-port=80/tcp --add-port=443/tcp --permanent
	firewall-cmd --reload


	# Allow Apache through Ubuntu Firewall.
	ufw allow in "Apache Full"
	service ufw restart

# ******************************* INSTALLING OWNCLOUD ********************************
# ************************************************************************************

		dpkg-query -l mysql-server
		# dpkg-query -l mysql-server-5.6
	if [ $? -eq 0 ] 
		then 	

		FILE=/root/LAMP.txt
		PASSWORD=$(cat $FILE | grep -i password | awk '{print $2}')			

		# Just in case.
		apt-get install php-gd php-json php-curl php-intl php-mcrypt php-mysql php-imagick php-zip php-xml php-mbstring -y

		mysql -u root -p"$PASSWORD" -e "CREATE DATABASE ownclouddb" 
		mysql -u root -p"$PASSWORD" -e "GRANT ALL PRIVILEGES ON ownclouddb.* to 'ownclouduser'@'localhost' identified by '$PASSWORD'"
		mysql -u root -p"$PASSWORD" -e "FLUSH PRIVILEGES" 

		sudo service apache2 restart 

		# OWNCLOUD INFO
		IPOFSERVER=ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'
		echo -e "\n\nOWNCLOUD installed.\n\n                 Please open http://$IPOFSERVER/owncloud to finish the installation.\n\n                     ***** Use the following when setting up OWNCLOUD Database Setup *****\n\n user credentials\n\n      Database User:                          ownclouduser\n      Database Password:                      $PASSWORD\n      Database Name:                          ownclouddb\n      Server:                                 localhost\n\n\n" > /root/OWNCLOUD.txt

		# echo "always_populate_raw_post_data = -1" >> /etc/php.ini
		echo "always_populate_raw_post_data = -1" >> /etc/php/7.0/cli/php.ini
		# wget http://51.255.13.156/packages/owncloud-9.0.4.tar.bz2
		wget https://download.owncloud.org/community/owncloud-9.1.1.tar.bz2
		tar -xvf owncloud-9.1.1.tar.bz2 -C /var/www/html/
	
		chown www-data:www-data -R /var/www/html/owncloud/

		echo -e "<IfModule mod_alias.c>\n 	Alias /owncloud /var/www/html/owncloud\n</IfModule>\n\n<Directory “/var/www/html/owncloud”>\n 	Options Indexes FollowSymLinks\n 	AllowOverride All\n 	Require all granted\n</Directory>" >> /etc/apache2/sites-available/owncloud.conf
		systemctl restart apache2.service
	fi

 

Now you know how to install owncloud on ubuntu server for testing purpose.

Thanks for visiting this page and have a great day. 🙂

share on:
engy

engy

Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Don't forget to leave the feedback. Have a great day. :)

Leave a Response

share on: