Last active
August 29, 2015 14:04
-
-
Save l3lake/876ce7ec5f56948aab78 to your computer and use it in GitHub Desktop.
Script: Install ownCloud on an Ubuntu 12.04 VPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Install owncloud | |
| # http://www.rosehosting.com/blog/script-install-owncloud-on-an-ubuntu-12-04-vps/ | |
| # | |
| # This script assumes you already have installed Apache & MySQL | |
| # Save the script as installOwncloud.sh (if you haven’t already), and | |
| # 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 | |
| # 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 "<VirtualHost *:80> | |
| DocumentRoot $www/owncloud | |
| ServerName $1 | |
| ServerAlias $1 | |
| <Directory $www/owncloud> | |
| Options Indexes FollowSymLinks MultiViews +Includes | |
| AllowOverride All | |
| Order allow,deny | |
| allow from all | |
| </Directory> | |
| </VirtualHost>" > /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"f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment