added a vagrant configuration for development

This commit is contained in:
hauke 2015-11-08 16:54:15 +01:00
parent 6becf45e73
commit 50b60f6735
6 changed files with 393 additions and 4 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
favicon.*
tests/coverage.html
/vendor
/nbproject/private/

View File

@ -2,9 +2,9 @@
//MySQL host.
$db_host = 'localhost';
$db_user = 'friendica-dir';
$db_pass = 'thisisyourpasswordbuddy';
$db_data = 'friendica-dir';
$db_user = 'root';
$db_pass = 'root';
$db_data = 'friendica_dir';
// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles".
// It can be changed later and only applies to timestamps for anonymous viewers.

43
Vagrantfile vendored Normal file
View File

@ -0,0 +1,43 @@
server_ip = "192.168.33.10"
server_memory = "384" # MB
server_timezone = "UTC"
public_folder = "/vagrant"
Vagrant.configure(2) do |config|
# Set server to Ubuntu 14.04
config.vm.box = "ubuntu/trusty64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a hostname, don't forget to put it to the `hosts` file
# This will point to the server's default virtual host
# TO DO: Make this work with virtualhost along-side xip.io URL
config.vm.hostname = "friendica.dev"
# Create a static IP
config.vm.network :private_network, ip: server_ip
# Share a folder between host and guest
config.vm.synced_folder "./", "/vagrant/", owner: "www-data", group: "vagrant"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = server_memory
end
# Enable provisioning with a shell script.
config.vm.provision "shell", path: "./util/vagrant_provision.sh"
# run: "always"
# run: "once"
end

86
util/htconfig.vagrant.php Normal file
View File

@ -0,0 +1,86 @@
<?php
//MySQL host.
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'root';
$db_data = 'friendica_dir';
// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles".
// It can be changed later and only applies to timestamps for anonymous viewers.
$default_timezone = 'Europe/Amsterdam';
// What is your site name?
$a->config['sitename'] = "EXPERIMENTAL Friendica public directory";
//Statistic display settings.
$a->config['stats'] = array(
//For site health, the max age for which to display data.
'maxDataAge' => 3600*24*30*4 //120 days = ~4 months
);
//Settings related to the syncing feature.
$a->config['syncing'] = array(
//Pulling may be quite intensive at first when it has to do a full sync and your directory is empty.
//This timeout should be shorter than your cronjob interval. Preferably with a little breathing room.
'timeout' => 3*60, //3 minutes
//Push new submits to the `sync-target` entries?
'enable_pushing' => true,
//Maximum amount of items per batch per target to push to other sync-targets.
//For example: 3 targets x20 items = 60 requests.
'max_push_items' => 10,
//Pull updates from the `sync-target` entries?
'enable_pulling' => true,
//This is your normal amount of threads for pulling.
//With regular intervals, there's no need to give this a high value.
//But when your server is brand new, you may want to keep this high for the first day or two.
'pulling_threads' => 25,
//How many items should we crawl per sync?
'max_pull_items' => 250
);
//Things related to site-health monitoring.
$a->config['site-health'] = array(
//Wait for at least ... before probing a site again.
//The longer this value, the more "stable" site-healths will be over time.
//Note: If a bad (negative) health site submits something, a probe will be performed regardless.
'min_probe_delay' => 24*3600, // 1 day
//Probes get a simple /friendica/json file from the server.
//Feel free to set this timeout to a very tight value.
'probe_timeout' => 5, // seconds
//Imports should be fast. Feel free to prioritize healthy sites.
'skip_import_threshold' => -20
);
//Things related to the maintenance cronjob.
$a->config['maintenance'] = array(
//This is to prevent I/O blocking. Will cost you some RAM overhead though.
//A good server should handle much more than this default, so you can tweak this.
'threads' => 10,
//Limit the amount of scrapes per execution of the maintainer.
//This will depend a lot on the frequency with which you call the maintainer.
//If you have 10 threads and 80 max_scrapes, that means each thread will handle 8 scrapes.
'max_scrapes' => 80,
//Wait for at least ... before scraping a profile again.
'min_scrape_delay' => 3*24*3600, // 3 days
//At which health value should we start removing profiles?
'remove_profile_health_threshold' => -60
);

82
util/vagrant_provision.sh Normal file
View File

@ -0,0 +1,82 @@
#!/bin/bash
#Script to setup the vagrant instance for running friendica
#
#DO NOT RUN on your physical machine as this won't be of any use
#and f.e. deletes your /var/www/ folder!
echo "Friendica configuration settings"
sudo apt-get update
#Selfsigned cert
echo ">>> Installing *.xip.io self-signed SSL"
SSL_DIR="/etc/ssl/xip.io"
DOMAIN="*.xip.io"
PASSPHRASE="vaprobash"
SUBJ="
C=US
ST=Connecticut
O=Vaprobash
localityName=New Haven
commonName=$DOMAIN
organizationalUnitName=
emailAddress=
"
sudo mkdir -p "$SSL_DIR"
sudo openssl genrsa -out "$SSL_DIR/xip.io.key" 4096
sudo openssl req -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -key "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.csr" -passin pass:$PASSPHRASE
sudo openssl x509 -req -days 365 -in "$SSL_DIR/xip.io.csr" -signkey "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.crt"
#Install apache2
echo ">>> Installing Apache2 webserver"
sudo apt-get install -y apache2
sudo a2enmod rewrite actions ssl
sudo cp /vagrant/util/vagrant_vhost.sh /usr/local/bin/vhost
sudo chmod guo+x /usr/local/bin/vhost
sudo vhost -s 192.168.33.10.xip.io -d /var/www -p /etc/ssl/xip.io -c xip.io -a friendica.dev
sudo a2dissite 000-default
sudo service apache2 restart
#Install php
echo ">>> Installing PHP5"
sudo apt-get install -y php5 libapache2-mod-php5 php5-cli php5-mysql php5-curl php5-gd
sudo service apache2 restart
#Install mysql
echo ">>> Installing Mysql"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
sudo apt-get install -qq mysql-server
# enable remote access
# setting the mysql bind-address to allow connections from everywhere
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
# adding grant privileges to mysql root user from everywhere
# thx to http://stackoverflow.com/questions/7528967/how-to-grant-mysql-privileges-in-a-bash-script for this
MYSQL=`which mysql`
Q1="GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;"
Q2="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}"
$MYSQL -uroot -proot -e "$SQL"
service mysql restart
#make the vagrant directory the docroot
sudo rm -rf /var/www/
sudo ln -fs /vagrant /var/www
# initial config file for friendica in vagrant
cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php
# create the friendica database
echo "create database friendica_dir" | mysql -u root -proot
# import test database
$MYSQL -uroot -proot friendica_dir < /vagrant/dfrndir.sql
#Install composer
cd /vagrant
curl -sS https://getcomposer.org/installer | php
php composer.phar install
#create cronjob
echo "*/10 * * * * cd /vagrant; /usr/bin/php include/poller.php" >> friendicacron
sudo crontab friendicacron
sudo rm friendicacron

177
util/vagrant_vhost.sh Normal file
View File

@ -0,0 +1,177 @@
#!/usr/bin/env bash
# Run this as sudo!
# I move this file to /usr/local/bin/vhost and run command 'vhost' from anywhere, using sudo.
#
# Show Usage, Output to STDERR
#
function show_usage {
cat <<- _EOF_
Create a new vHost in Ubuntu Server
Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used
-d DocumentRoot - i.e. /var/www/yoursite
-h Help - Show this menu.
-s ServerName - i.e. example.com or sub.example.com
-a ServerAlias - i.e. *.example.com or another domain altogether
-p File path to the SSL certificate. Directories only, no file name.
If using an SSL Certificate, also creates a port :443 vhost as well.
This *ASSUMES* a .crt and a .key file exists
at file path /provided-file-path/your-server-or-cert-name.[crt|key].
Otherwise you can except Apache errors when you reload Apache.
Ensure Apache's mod_ssl is enabled via "sudo a2enmod ssl".
-c Certificate filename. "xip.io" becomes "xip.io.key" and "xip.io.crt".
Example Usage. Serve files from /var/www/xip.io at http(s)://192.168.33.10.xip.io
using ssl files from /etc/ssl/xip.io/xip.io.[key|crt]
sudo vhost -d /var/www/xip.io -s 192.168.33.10.xip.io -p /etc/ssl/xip.io -c xip.io
_EOF_
exit 1
}
#
# Output vHost skeleton, fill with userinput
# To be outputted into new file
#
function create_vhost {
cat <<- _EOF_
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName $ServerName
$ServerAlias
DocumentRoot $DocumentRoot
<Directory $DocumentRoot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined
</VirtualHost>
_EOF_
}
function create_ssl_vhost {
cat <<- _EOF_
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName $ServerName
$ServerAlias
DocumentRoot $DocumentRoot
<Directory $DocumentRoot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined
SSLEngine on
SSLCertificateFile $CertPath/$CertName.crt
SSLCertificateKeyFile $CertPath/$CertName.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
BrowserMatch "MSIE [2-6]" \\
nokeepalive ssl-unclean-shutdown \\
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
_EOF_
}
#Sanity Check - are there two arguments with 2 values?
if [ "$#" -lt 4 ]; then
show_usage
fi
CertPath=""
#Parse flags
while getopts "d:s:a:p:c:h" OPTION; do
case $OPTION in
h)
show_usage
;;
d)
DocumentRoot=$OPTARG
;;
s)
ServerName=$OPTARG
;;
a)
Alias=$OPTARG
;;
p)
CertPath=$OPTARG
;;
c)
CertName=$OPTARG
;;
*)
show_usage
;;
esac
done
# If alias is set:
if [ "$Alias" != "" ]; then
ServerAlias="ServerAlias "$Alias
else
ServerAlias=""
fi
# If CertName doesn't get set, set it to ServerName
if [ "$CertName" == "" ]; then
CertName=$ServerName
fi
if [ ! -d $DocumentRoot ]; then
mkdir -p $DocumentRoot
#chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ?
fi
if [ -f "$DocumentRoot/$ServerName.conf" ]; then
echo 'vHost already exists. Aborting'
show_usage
else
create_vhost > /etc/apache2/sites-available/${ServerName}.conf
# Add :443 handling
if [ "$CertPath" != "" ]; then
create_ssl_vhost >> /etc/apache2/sites-available/${ServerName}.conf
fi
# Enable Site
cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf
service apache2 reload
fi