In einem unserer vorherigen Blogbeiträge hatten wir behandelt, wie man ownCloud auf einem CentOS 6 VPS installiert, heute werden wir sehen, wie man ownCloud auf einem Ubuntu 12.04-Server mit einem automatisierten Bash-Skript installiert.
#!/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 "<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" Was wird das Skript tun?
- Überprüfen Sie, ob das Skript als root ausgeführt wird
- Überprüfen Sie, ob die Anzahl der Argumente korrekt ist
- MySQL-Datenbank erstellen
- Überprüfen Sie, ob die Datenbank erstellt wurde
- Erstellen Sie die Datei mit der VirtualHost-Konfiguration
- Installieren Sie die erforderlichen PHP-Module
- Laden Sie die neueste Version von ownCloud herunter und extrahieren Sie sie
- Legen Sie den Eigentümer fest, aktivieren Sie die Website und starten Sie Apache neu
- Den Datenbanknamen, Benutzer und Passwort anzeigen
Speichern Sie das obige Skript als installOwncloud.sh (falls noch nicht geschehen), ändern Sie „YOUR MYSQL ROOT PASSWORD“ durch Ihr MySQL-Root-Passwort und geben Sie dann die folgenden Befehle ein:
a+x installOwncloud.sh ./installOwncloud.sh your.domainname.com
Öffnen Sie schließlich Ihren Webbrowser und navigieren Sie zu Ihrer ownCloud-Instanz
Dieses Skript sollte auch auf Debian funktionieren.
PS. Wenn Ihnen dieser Beitrag gefallen hat, teilen Sie ihn bitte mit Ihren Freunden in den sozialen Netzwerken über die Schaltflächen auf der linken Seite oder hinterlassen Sie einfach unten eine Antwort. Danke.