Page MenuHomePhabricator
Paste P2068

Ubuntu 16.04.3 Installer Script
ActivePublic

Authored by chad on Aug 12 2017, 9:05 PM.
Tags
None
Subscribers
None
Tokens
"Evil Spooky Haunted Tree" token, awarded by saggid.
#!/bin/bash
confirm() {
echo "Press RETURN to continue...";
read -e ignored
}
#
# Installation variables. These are the defaults used when running this
# script. You may modify as you need for your environment.
#
# Where to install stuff
DEFAULT_PATH="/var/www/"
DEFAULT_REPO="/var/repo/"
# MySQL Defaults
DEFAULT_MYSQL_USER="root"
DEFAULT_MYSQL_HOST="localhost"
# Full-Qualified Domain Name for your Phabricator installation
# Should *not* begin with `http`
DOMAIN_NAME=""
# Pre-configure Large File Support, options are 'none, mysql, disk'
STORAGE_ENGINE="mysql"
STORAGE_PATH="/var/www/phabricator/files/"
# The default Timezone you want Phabricator to operate in
# http://php.net/manual/en/timezones.php
TIMEZONE=""
#
# Check Ubuntu Version
#
ISSUE=`cat /etc/issue`
if [[ $ISSUE != Ubuntu* ]]
then
echo "This script is intended for use on Ubuntu, but this system appears";
echo "to be something else. Your results may vary.";
echo
confirm
fi
#
# Test if using sudo
#
echo "Testing sudo..."
sudo true
if [ $? -ne 0 ]
then
echo "ERROR: You must be able to sudo to run this script.";
exit 1;
fi;
echo "OK..."
#
# Create the installation path
#
echo "----- PHABRICATOR UBUNTU INSTALL SCRIPT -----";
echo "This script will install Phabricator and all of its core dependencies.";
echo
read -p "Path to install Phabricator to [${DEFAULT_PATH}]:" INSTALL_PATH
if [ -z "$INSTALL_PATH" ]
then
INSTALL_PATH="$DEFAULT_PATH"
else
echo "Phabricator will be installed to: ${INSTALL_PATH}.";
confirm
fi
sudo mkdir -p "$INSTALL_PATH"
#
# Create the repository path
#
read -p "Store repositories to [${DEFAULT_REPO}]:" INSTALL_REPO
if [ -z "$INSTALL_REPO" ]
then
INSTALL_REPO="$DEFAULT_REPO"
else
echo "Respositories will be hosted from: ${INSTALL_REPO}.";
confirm
fi
sudo mkdir -p "$INSTALL_REPO"
#
# Set the server domain name
#
if [ -z "$DOMAIN_NAME" ]
then
echo
echo "Phabricator needs too be installed on its own fully qualified domain name.";
echo
read -p "This computer's domain name: " SERVER_NAME
else
SERVER_NAME="$DOMAIN_NAME"
fi
if ! [[ $SERVER_NAME == *"."* ]]
then
echo "ERROR: You must set a valid domain name.";
exit 1;
fi;
echo "Phabricator will served from: http://${SERVER_NAME}";
echo
confirm
#
# Install Dependencies
#
echo "Let's get cooking.";
echo "Adding apt-repository for PHP 7.1...";
echo
sudo add-apt-repository -y ppa:ondrej/php
echo "Installing dependencies: git, svn, hg, apache, mysql, php...";
echo
set +x
#
# TODO: APCu for 7.1?
#
sudo apt-get -qq update
sudo apt-get install \
git mysql-server apache2 dpkg-dev \
php7.1 php7.1-cli php7.1-common php7.1-curl php7.1-gd php7.1-json \
php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-xml php7.1-apcu \
npm subversion mercurial python-pygments sendmail
#
# Enable mod_rewrite
#
sudo a2enmod rewrite
sudo systemctl restart apache2
#
# Prepare directory permissions
#
sudo chown -R www-data "$INSTALL_PATH"
sudo chown -R www-data "$INSTALL_REPO"
#
# Download Phabricator directly from GitHub
#
cd $INSTALL_PATH
if [ ! -e libphutil ]
then
git clone -b stable https://github.com/phacility/libphutil.git
else
(cd libphutil && git pull --rebase)
fi
if [ ! -e arcanist ]
then
git clone -b stable https://github.com/phacility/arcanist.git
else
(cd arcanist && git pull --rebase)
fi
if [ ! -e phabricator ]
then
git clone -b stable https://github.com/phacility/phabricator.git
else
(cd phabricator && git pull --rebase)
fi
#
# Set local config variables for Phabricator
#
cd phabricator
echo "Setting up database connection...";
echo
read -p "Enter MySQL username [${DEFAULT_MYSQL_USER}]:" USERNAME
if [ -z "$USERNAME" ]
then
USERNAME="$DEFAULT_MYSQL_USER"
fi
read -p "Enter MySQL password: " PASSWORD
read -p "Enter MySQL hostname [${DEFAULT_MYSQL_HOST}]: " HOSTNAME
if [ -z "$HOSTNAME" ]
then
HOSTNAME="$DEFAULT_MYSQL_HOST"
fi
bin/config set mysql.user $USERNAME
bin/config set mysql.pass $PASSWORD
bin/config set mysql.host $HOSTNAME
bin/config set phabricator.base-uri "http://${SERVER_NAME}"
bin/config set repository.default-local-path "${INSTALL_REPO}"
bin/config set pygments.enabled true
bin/storage upgrade --force
#
# Enable Large File Support
#
if [ "$STORAGE_ENGINE" == "mysql" ]
then
echo "Setting large file storage to MySQL...";
bin/config set storage.mysql-engine.max-size 8388608
fi
if [ "$STORAGE_ENGINE" == "disk" ]
then
echo "Setting large file storage to Disk...";
mkdir -p "$STORAGE_PATH"
bin/config set storage.local-disk.path "$STORAGE_PATH"
fi
#
# Set php.ini variables (Setup Issue Resolution)
#
PHP_INI="/etc/php/7.1/apache2/php.ini"
if [ -z "$TIMEZONE" ];
then
TIMEZONE=`cat /etc/timezone`
fi
echo "date.timezone=$TIMEZONE" >> "$PHP_INI"
echo "post_max_size=32M" >> "$PHP_INI"
echo "opcache.validate_timestamps=0" >> "$PHP_INI"
bin/config set phabricator.timezone "$TIMEZONE"
#
# Set my.cnf variables (Setup Issue Resolution)
#
MY_CNF="/etc/mysql/my.cnf"
echo "[mysqld]" >> $MY_CNF
echo "innodb_buffer_pool_size=1600M" >> $MY_CNF
echo "max_allowed_packet=33554432" >> $MY_CNF
echo "sql_mode=STRICT_ALL_TABLES" >> $MY_CNF
sudo service mysql restart
#
# Configure Apache 2
#
echo "Writing Apache site config...";
echo
FILE="/etc/apache2/sites-available/054-phabricator.conf"
sudo cat > $FILE << EOM
<VirtualHost *>
ServerName ${SERVER_NAME}
DocumentRoot ${INSTALL_PATH}phabricator/webroot
RewriteEngine on
RewriteRule ^(.*)$ /index.php?__path__=\$1 [B,L,QSA]
</VirtualHost>
<Directory "${INSTALL_PATH}phabricator/webroot">
Require all granted
</Directory>
EOM
sudo a2ensite 054-phabricator
sudo a2dissite 000-default
sudo systemctl restart apache2
#
# Set up Aphlict Notification Server
#
# Side Note - Aphlict listens on whatever IP the SERVER_NAME translates to
# on your /etc/hosts file. If clients are having issues connecting, but
# the server isn't, please check the values in /etc/hosts and relaunch
# everything.
#
cd support/aphlict/server/
npm install ws
cd $INSTALL_PATH
cd phabricator/
sudo touch /var/log/aphlict.log
sudo chown www-data /var/log/aphlict.log
APHLICT_FILE="${INSTALL_PATH}phabricator/conf/aphlict/aphlict.custom.json"
sudo cat > $APHLICT_FILE << EOM
{
"servers": [
{
"type": "client",
"port": 22280,
"listen": "${SERVER_NAME}",
"ssl.key": null,
"ssl.cert": null,
"ssl.chain": null
},
{
"type": "admin",
"port": 22281,
"listen": "127.0.0.1",
"ssl.key": null,
"ssl.cert": null,
"ssl.chain": null
}
],
"logs": [
{
"path": "/var/log/aphlict.log"
}
],
"pidfile": "/var/tmp/aphlict/pid/aphlict.pid"
}
EOM
read -r -d '' APHLICT_TMP << EOM
[
{
"type": "client",
"host": "${SERVER_NAME}",
"port": 22280,
"protocol": "http"
},
{
"type": "admin",
"host": "127.0.0.1",
"port": 22281,
"protocol": "http"
}
]
EOM
bin/config set notification.servers "$APHLICT_TMP"
sudo -u www-data bin/aphlict start
#
# Launch the phd daemons
#
echo "Starting phd daemons...";
sudo -u www-data bin/phd start
echo
#
# Goodluck and Godspeed.
#
echo
echo
echo "Install probably worked ok. Continue at your local install:";
echo
echo " http://$SERVER_NAME";
echo

Event Timeline

chad created this paste.Aug 12 2017, 9:05 PM
chad edited the content of this paste. (Show Details)Aug 12 2017, 9:15 PM
chad edited the content of this paste. (Show Details)Aug 12 2017, 9:21 PM
chad edited the content of this paste. (Show Details)Aug 14 2017, 4:40 AM
chad edited the content of this paste. (Show Details)Aug 18 2017, 4:42 AM
chad edited the content of this paste. (Show Details)Aug 19 2017, 3:45 AM
chad edited the content of this paste. (Show Details)Aug 19 2017, 9:38 PM
chad edited the content of this paste. (Show Details)Aug 20 2017, 7:08 PM