Install ownCloud on Ubuntu 12.04

Status: Deprecated

This article, “Install ownCloud on Ubuntu 12.04,” covers a version of Ubuntu 12.04 that reached end of life (EOL) on April 28th, 2017, and is no longer supported. Installing ownCloud on this Ubuntu version is thus outdated. For this reason, this guide is no longer maintained. If you are currently operating a server and wondering how to install ownCloud on Ubuntu 12.04, we highly recommend contacting RoseHosting’s fully managed support to upgrade or migrate to a supported version of Ubuntu.

See Instead: Although this guide may still be helpful as a reference for understanding the process of installing ownCloud on Ubuntu 12.04, it may not be compatible with other Ubuntu releases. The following RoseHosting tutorial outlines how to install OwnCloud 7 on Ubuntu 14.04.

In one of our previous blog posts, we had covered how to install ownCloud on a CentOS 6 VPS, today we will see how to install ownCloud on an Ubuntu 12.04 server using an automated bash script.

#!/bin/bash
#
# Install owncloud
# This script assumes you already have installed Apache & MySQL
#

# Change me
MYSQL_ROOT_PASSWD="YOUR MYSQL ROOT PASSWORD"

# Path to your localhost
www="/var/www"

# Apache User
wwwdata="www-data"

# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
   exit 1
fi

# Check arguments
if [ $# -ne 1 ]; then
    echo "Usage $0 domainName"
    exit 1
fi

# Create MySQL database
MYSQL_OC_PASSWD=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 8)
Q1="CREATE DATABASE IF NOT EXISTS owncloud;"
Q2="GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY '$MYSQL_OC_PASSWD';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"
mysql -uroot -p$MYSQL_ROOT_PASSWD -e "$SQL" > /dev/null 2>&1

# Check if the database is created
if [ $? -ne 0 ]; then
    echo "Cannot connect to the MySQL database server"
    exit 1
fi

# Create the file with VirtualHost configuration
echo "
        DocumentRoot $www/owncloud
        ServerName $1
        ServerAlias $1
        
                Options Indexes FollowSymLinks MultiViews +Includes
                AllowOverride All
                Order allow,deny
                allow from all
        
" > /etc/apache2/sites-available/$1

# Update System
apt-get -y update > /dev/null 2>&1

# Install PHP modules
apt-get -y install php5 php5-json php-xml php-mbstring php5-zip php5-gd php5-sqlite php5-mysql curl libcurl3 libcurl3-dev php5-curl php-pdo > /dev/null 2>&1

# Download and extract the latest version
wget -qO- -O tmp.tar.bz2 http://owncloud.org/releases/owncloud-latest.tar.bz2 && tar -C $www -xjf tmp.tar.bz2 && rm tmp.tar.bz2

# Set owner
chown $www-data: -R $www/owncloud

# Enable the site
a2ensite $1 > /dev/null 2>&1

# Reload Apache2
/etc/init.d/apache2 restart > /dev/null 2>&1

# Output
clear
echo "Open your web browser and navigate to your ownCloud instance"
echo "Url: $1"
echo "Database: owncloud"
echo "Database user: owncloud"
echo "Database user password: $MYSQL_OC_PASSWD"

What will the script do?

  • Check if the script is being run as root
  • Check if the number of arguments is correct
  • Create MySQL database
  • Check if the database is created
  • Create the file with VirtualHost configuration
  • Install necessary PHP modules
  • Download and extract the latest version of ownCloud
  • Set the owner, enable the site and restart Apache
  • Show you the database name, user and password

Save the script above as installOwncloud.sh (if you haven’t already), change “YOUR MYSQL ROOT PASSWORD” with your MySQL root password and then type the following commands:

a+x installOwncloud.sh
./installOwncloud.sh  your.domainname.com

Finally, open your web browser and navigate to your ownCloud instance

This script should work on Debian too.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment