diff --git a/docs/installation/vagrant.md b/docs/installation/vagrant.md index ffc331ff542..5f37d03ab80 100644 --- a/docs/installation/vagrant.md +++ b/docs/installation/vagrant.md @@ -4,11 +4,23 @@ If you want a quick and easy way to get a Monica development/test environment up 1. Download and install [Vagrant](https://www.vagrantup.com/) for your operating system 2. Create a folder to put the vagrant configuration files -3. Download the `Vagrantfile` and the `provision.sh` script from [this repository](https://github.com/dp87/vagrantfiles/tree/master/Monica) -4. Put both of these files inside the Vagrant folder you have created in step 2 -5. Open a terminal and `cd` to this folder -6. Initialize a virtual machine based on Ubuntu 16.04: `vagrant init ubuntu/xenial64` -7. Launch the virtual machine with `vagrant up` +```sh +mkdir ~/monica +cd ~/monica +``` +3. Download the `Vagrantfile` and the `provision.sh` script +```sh +curl -sS https://raw.githubusercontent.com/monicahq/monica/master/scripts/vagrant/Vagrantfile -o Vagrantfile +curl -sS https://raw.githubusercontent.com/monicahq/monica/master/scripts/vagrant/provision.sh -o provision.sh +``` +4. Initialize a virtual machine based on Ubuntu 16.04: +```sh +vagrant box add ubuntu/xenial64 +``` +5. Launch the virtual machine with +```sh +vagrant up +``` The virtual machine will be first created and then provisioned using the `provision.sh` script, which will take care of installing Monica for you. @@ -19,11 +31,11 @@ Once the installation process is complete (you will see all of the output in you ### Database users * Root database user -* * Username: `root` -* * Password: `changeme` + - Username: `root` + - Password: `changeme` * Monica database user -* * Username: `monica` -* * Password: `changeme` + - Username: `monica` + - Password: `changeme` ### Apache configuration diff --git a/scripts/vagrant/.gitignore b/scripts/vagrant/.gitignore new file mode 100644 index 00000000000..dae60d66b46 --- /dev/null +++ b/scripts/vagrant/.gitignore @@ -0,0 +1,2 @@ +*.log +.vagrant/ diff --git a/scripts/vagrant/Vagrantfile b/scripts/vagrant/Vagrantfile new file mode 100644 index 00000000000..bbf0fa5f476 --- /dev/null +++ b/scripts/vagrant/Vagrantfile @@ -0,0 +1,14 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION ||= "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "ubuntu/xenial64" + config.vm.define "monicahq" + config.vm.hostname = "monica" + + config.vm.network "forwarded_port", guest: 80, host: 8080 + + config.vm.provision "shell", path: "provision.sh", keep_color: true +end \ No newline at end of file diff --git a/scripts/vagrant/provision.sh b/scripts/vagrant/provision.sh new file mode 100644 index 00000000000..decf4f266f9 --- /dev/null +++ b/scripts/vagrant/provision.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# +# Author: Daniel Pellarini +# GitHub profile: dp87 - https://github.com/dp87/ +# Date: 11/12/2017 +# +# Provisioning script to install Monica Personal Relationship Manager on a Ubuntu 16.04 box +# + +set -euo pipefail + +MYSQL_ROOT_PASSWORD=changeme +MYSQL_MONICA_DATABASE=monica +MYSQL_MONICA_USER=monica +MYSQL_MONICA_PASSWORD=changeme +DESTDIR=/var/www/html/monica + +MONICA_USER=admin@admin.com +MONICA_PASSWORD=admin + +function update_setting() { + file=$1 + name=$2 + value=$3 + if $(grep -q "$name" $file); then + sed -i "s/\($name\).*/\1=$value/" $file; + else + echo -e "\n$name=$value" | tee -a $file; + fi +} + +echo "########################" +echo "Installing prerequisites" +echo "########################" + +echo "Installing apache" +apt-get update +apt-get install -y apache2 + +echo "ServerName vagrant" >> /etc/apache2/apache2.conf # suppress apache warning + +echo "Installing MySQL with default root password" +debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD" +debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD" +apt-get install -y mysql-server mysql-client + +#echo "Installing PHP" +#apt-get install -y php libapache2-mod-php php-mcrypt php-mysql >/dev/null 2>&1 + +echo "Installing PHP 7.1" +add-apt-repository -y ppa:ondrej/php +apt-get update >/dev/null +apt-get install -y php7.1 >/dev/null + +echo "Installing git" +apt-get install -y git >/dev/null + +echo "Installing composer" +apt-get install -y curl php7.1-cli git +curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +echo "Installing packages for Monica" +apt-get install -y php7.1-intl php7.1-simplexml php7.1-gd php7.1-mbstring php7.1-curl php7.1-zip php7.1-mysql + +echo "Getting database ready" +mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE $MYSQL_MONICA_DATABASE; +CREATE USER '$MYSQL_MONICA_USER'@'localhost' IDENTIFIED BY '$MYSQL_MONICA_PASSWORD'; +GRANT ALL ON $MYSQL_MONICA_DATABASE.* TO '$MYSQL_MONICA_USER'@'localhost'; +FLUSH PRIVILEGES;" + +echo "Installing Monica" +git clone https://github.com/monicahq/monica.git $DESTDIR +cd $DESTDIR +composer install --no-interaction --prefer-dist --no-suggest --optimize-autoloader --no-dev --no-progress + +echo "Configuring Monica" +cp .env.example .env +update_setting .env DB_DATABASE "$MYSQL_MONICA_DATABASE" +update_setting .env DB_USERNAME "$MYSQL_MONICA_USER" +update_setting .env DB_PASSWORD "$MYSQL_MONICA_PASSWORD" +update_setting .env APP_DISABLE_SIGNUP "false" +chown -R www-data:www-data . +sudo -u www-data php artisan key:generate +sudo -u www-data php artisan setup:production --force --email=$MONICA_USER --password=$MONICA_PASSWORD +sudo -u www-data php artisan passport:install + +echo "Configuring cron script" +{ crontab -l -u www-data; echo "* * * * * /usr/bin/php $DESTDIR/artisan schedule:run"; } | crontab -u www-data - || true + +echo "Configuring apache" +a2enmod rewrite +sed -i "s/\(DocumentRoot\).*/\1 ${DESTDIR//\//\\\/}\/public/" /etc/apache2/sites-enabled/000-default.conf +sed -i "s/\/var\/www\//${DESTDIR//\//\\\/}\/public\//" /etc/apache2/apache2.conf +sed -i "//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/" /etc/apache2/apache2.conf + +echo "Restarting apache" +systemctl restart apache2 + +echo "Done! You can access Monica by visiting http://localhost:8080 from your host machine"