Table of Contents

Install EgoWeb 2.0

Installation Overview

EgoWeb 2.0 has been optimized for running on a web server and providing access to authoring and administering social network data collection interviews over the web, but it can also be installed on stand-alone machines and run locally through web browsers without use of the internet. Below are instructions for the various types of installations.

NOTE: The Linux instructions below assume a web server and the Windows and Mac instructions assume local installation, but the Linux instructions apply to a local installation and EgoWeb 2.0 can also be run on a Windows or Mac based web server.

Desktop and Laptop Installations

Although EgoWeb 2.0 was designed to be installed and run on a web server broadcasting over the internet, it can also be installed onto a single machine and run as a local server only. Stand-alone Linux machines can run the instructions above. Windows and Mac machine installation instructions are below. This installation will not allow use of some of the features that require the internet, such as sending links to respondents to fill out EgoWeb 2.0 surveys or for using EgoWeb 2.0 mobile.


Install EgoWeb 2.0 on a Windows machine

UPDATE FROM DAVE K 9 NOV 18: Newer versions of WAMP are no longer working with EgoWeb so we are switching to AMPPS. There are some beneifts to this. The instructions are easier for AMPPS and they are nearly identical for Macs and Windows machines.

Before starting to install the programs that need to run to use EgoWeb, go to www.github.com and download the latest zip file from the EgoWeb 2.0 Github repository located here and extract its contents onto the desktop. Unzip the file somewhere you can access it later. The link is to the “dev” branch of EgoWeb 2.0. There is a “Master” branch as well as a “dev” branch. Currently “dev” has much more updated code and is close to being made the master branch, but testing for a few new features and bug fixes is in progress. There are known bugs in the master branch that will be fixed once we update from dev, so we recommend using dev for now. The master branch cannot be installed with newer versions of PHP because we had to change the encryption library which was no longer supported.

1) Install AMPPS

2) Configure AMPPS

NOTE: If Apache is not running when you start AMPPS and if it does not start when you click “ON”, you may have Apache already running with some other program. It is typically turned off by default but if you have installed some other program that runs Apache, it might be running and needs to be shut down in order to run it through AMPPS.

3) Create default Egoweb database

4) Import database structure from SQL file

5) Add user privileges to egoweb database

6) Install the EgoWeb PHP files into the AMPPS www directory

Go to the folder ”/Program Files/AMPPS/www“. It is located inside the same folder where the AMPPS.exe file is located.

7) Configure egoweb

8) Start EgoWeb 2.0

Open a browser and go to “http://localhost” to start using EgoWeb 2.0. You will be prompted to create an admin user. After creating the user, you can log in to EgoWeb 2.0 with the user’s email and password.


Update an EgoWeb 2.0 installation on a Windows Machine

1) Repeat steps from the main installation instructions starting with 6 (copy files from the .zip file app folder into the www folder).

2) Type the following into a browser address and hit enter:

localhost/admin/migrate

If there are database changes, these will be migrated into the existing data base and EgoWeb 2.0 will be fully updated. If there are no changes that need to be migrated, running this will confirm that your system is up to date.


Install EgoWeb 2.0 on a Mac OS machine

NOTE FROM DAVE K: 04/04/20 AMPPS was updated for 64 bit, so it now works for Mac OS Catalina. I tested the installation and nothing changed as far as I could tell from the previous instructions. I updated them to make them more clear.

Before you begin installation, get the latest EgoWeb 2.0 files from github. As of 4/4/20 the dev branch is the best branch because it has all the latest files for newer versions of PHP. https://github.com/qualintitative/egoweb/tree/dev. Download the latest zip file and extract its contents somewhere on your desktop where yo will be able to find them in the next steps.

1) Install AMPPS

2) Configure AMPPS

3) Create default egoweb database

4) Import database structure from SQL file

5) Add user privileges to egoweb database

6) Turn on Show Hidden Files for Finder

This step is necessary to copy the hidden file .htaccess, which is necessary for Apache to set the configurations for EgoWeb 2.0.

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder

(Note 3 below has alternative terminal command)

7) Install the EgoWeb PHP files into the AMPPS www directory

Go to the folder ”/Applications/AMPPS/www“. It is located inside the AMPPS app in the application folder.

8) Configure egoweb

9) Start EgoWeb 2.0

Open a browser and go to “http://localhost” to start using EgoWeb 2.0. You will be prompted to create an admin user. After creating the user, you can log in to EgoWeb 2.0 with the user’s email and password.

NOTE1: If Apache is not running when you start AMPPS and if it does not start when you click “ON”, you may have Apache already running. It is typically turned off by default but if you have installed MAMP or some other program that runs Apache, it might be running and needs to be shut down in order to run it through AMPPS.

In order to turn Apache off, you will need to run some commands in the “terminal” app on your Mac. Open up a terminal by going into the Application Launcher and typing in “Terminal”. If you enter a password to access your Mac, you will need to enter the same password to use Terminal. Copy and paste the lines below and hit “enter” after each line. (I found these commands on a Q&A message board):

After running these you should be able to click Apache “On” in the AMPPS application.

NOTE2: If setting up a production server that is not broadcasting / facing externally (if you are not just using your Mac to run EgoWeb – e.g. if you are running it over a network and others will have access to the installation on a server) please replace egowebpass with a password of your choice. If you change this value you will need to change the corresponding value in the “main.php” config file under the “db” section.

NOTE3:

defaults write com.apple.finder AppleShowAllFiles TRUE ; killall Finder

Update an EgoWeb 2.0 installation on a Mac OS Machine

1) Repeat steps from the main installation instructions starting with 7 (copy files from the .zip file app folder into the www folder).

2) Type the following into a browser address and hit enter:

localhost/admin/migrate

If there are database changes, these will be migrated into the existing data base and EgoWeb 2.0 will be fully updated. If there are no changes that need to be migrated, running this will confirm that your system is up to date.


Install EgoWeb 2.0 on an existing Linux server

These are instructions for a machine running Ubuntu 14.10 with the latest Ubuntu / Debian repositories. Open up a terminal on your server and execute the commands listed below.
1) Install LAMP Server

sudo apt-get update
sudo apt-get install lamp-server^ git php-gd php-mbstring php-xml

When prompted whether or not to install, hit 'y' and press enter. Remember the root password you enter when installing the MySQL server. You will need this password later.

2) Configure Apache

sudo nano /etc/apache2/apache2.conf

Under <Directory /var/www/>, change AllowOverride None to AllowOverride All Ctrl + X and type Y to save.

3) Enable the Apache rewrite and PHP Mcrypt modules

a2enmod rewrite
php5enmod mcrypt
service apache2 restart

4) Install the EgoWeb PHP files into the Apache www directory

git clone https://github.com/qualintitative/egoweb
rm -rf /var/www/*
cp -r egoweb/app/. /var/www/html/

5) Configure MySQL Database

mysql -p
CREATE DATABASE egoweb DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
USE egoweb
SOURCE ~/egoweb/sql/egoweb_db.sql

For production servers, please replace egowebpass in the command below with a password of your choice. If egoweb is the only database you're setting up in MySQL, you may re-use the root password from Step 1. Otherwise, please use a different password.

CREATE USER 'egowebuser'@'localhost' IDENTIFIED BY 'egowebpass';
GRANT ALL PRIVILEGES ON egoweb.* TO 'egowebuser'@'localhost';
quit

6) Configure Yii by running initialize.sh

cd /var/www/html
./initialize.sh

For production servers, you will need to edit /var/www/html/protected/config/main.php. Replace egowebpass in the database connection string with the password you used in Step 4. For additional security, you may change the encryption key near the bottom of the configuration file.

7) Start EgoWeb 2.0

Open a browser and go to “http://localhost” (Or replace localhost with your IP) to start using EgoWeb 2.0. You will be prompted to create an admin user with a name, email (which will be used as a username for logging in), and password. Please note that this is different from the database username and password which allows EgoWeb 2.0 to connect to the MySQL database. You may want to use a different password than the one used in Step 4. After creating the user, you can log in to EgoWeb 2.0 with the user’s email and password.


Update an EgoWeb 2.0 installation on a Linux server

This set of instructions assumes you followed the Linux setup instructions on this wiki to install EgoWeb 2.0 initially, and that there is a copy of egoweb in the ~/ folder. (You may need to install rsync if not installed already with the following command: > apt-get install rsync)

After logging in, type these following commands:

cd egoweb
git pull
cd ..
rsync -avz egoweb/app/ /var/www/html/

After these commands are successfully run, open a browser and log in to the version of EgoWeb 2.0 just updated. Go to the following URL extension of the EgoWeb 2.0 URL that is being updated:

~admin/migrate

If there are database changes, these will be migrated into the existing data base and EgoWeb 2.0 will be fully updated.


Update a Linux server to a different EgoWeb 2.0 branch

Run this set of commands if you want to switch your webpage to a different EgoWeb 2.0 branch. The final 5 lines are the same as the final 5 lines above. (You may need to install rsync if not already installed with the following command: > apt-get install rsync)

cd -
cd egoweb
git checkout {branch name}
git pull
cd ..
rsync -avz egoweb/app/ /var/www/html/

And then run the same migrate command to update the data base if necessary:

~/admin/migrate

Update an EgoWeb 2.0 to the new framework, version 2.0.10

EgoWeb 2.0.10 is a major update with improved security and UX features. These include the following updated libraries:

Yii Framework 2.0 Bootstrap 4.0 jQuery 3.4

The Authoring section was also updating using VueJS to streamline editing and administrating studies.

Before updating:

1) Make sure your database migrations are up to date. You can trigger this by going to https://[your-server-domain]/admin/migrate in your browser.

2) Make a backup of your database. This can be done by exporting the entire database in PhpMyAdmin.

3) Make a copy of protected/config/main.php on your current server. Rename “main.php” to “main.php.backup”

Updating process:

1) Download the latest version from the new_framework branch of the EgoWeb github located here.

2) On linux, run the command “rsync -avz app/ /var/www/html/” from the github repo folder. OR, copy the contents of the app folder to the root folder of your current server.

3) Run the script ./initialize.sh, OR manually make a copy of main.php.example and name it main.php.

4) Update config files

In main.php.backup, find the securityManager section, and copy the value for “encryptionKey”.

      'securityManager' => array(
          'cryptAlgorithm' => 'rijndael-128',
          'encryptionKey' => 'oldencryptionkey',
      )

Open the new main.php and look for the params section towards the end of the file. replace the value 'old_key1old_key1' with the encryptionKey value from your old config, like so:

  'params' => [
      'version'=>'2.0.10.0',
	// this is used in contact page
	'adminEmail' => 'admin@egoweb.com',
	// The max login attempt before showing captcha
	'maxLoginAttempts' => 3,
	'maxUploadFileSize' => 1024 * 1024 * 3, // 3MB		// file path for study export
	'exportFilePath' => '',
	// Enabling audio upload may make your server less secure
	'enableAudioUpload' => false,
      'surveyURL' => 'http://'.$_SERVER['HTTP_HOST'].'/survey',
      'APIPassword' => 'yourpasswordhere',
      'encryptionKey' => 'oldencryptionkey',
      'user.passwordResetTokenExpire' => 3600,
      'user.passwordMinLength' => 8,
  ],

on some servers this might be 'old_key1old_key1', in which case it doesn't need to be changed. However, it is strongly recommend that you create a unique encryption key for your server. if you wish to change the encryption key, you will need to export yall our studies, along with interview data, in the Import / Export section prior to updating Egoweb, change the encryption key, then re-import your study files. This will re-encrypt your data using the new key.

2. Update the database username and password. Look for the following section in main.php.backup

      'db' => array(
          'connectionString' => 'mysql:host=localhost;dbname=egoweb',
          'username' => 'new_egowebuser',
          'password' => "new_egowebpass",
          //'enableProfiling'=>true,
          'emulatePrepare' => true,
          'charset' => 'utf8',
      ),

use the values above to replace the username and password values tin the “db” section in the new main.php:

      'db' => [
          'class' => 'yii\db\Connection',
          'dsn' => 'mysql:host=localhost;dbname=egoweb',
          'username' => 'new_egowebuser',
          'password' => 'new_egowebuser',
          'charset' => 'utf8',
      ],

On some servers use the default password egowebuser and egowebpass. we recommend creating a unique username and password for the egoweb database in your mysql server. this can be done by creating a new user and granting them access to the egoweb database, then editing the database username and password in the main.php config file. this may or may not be required depending on your organization's security policy, though not necessary for servers on personal computers.

5) Create new user accounts

Passwords are encrypted differently in EgoWeb 2.0.10. You will need to reset your password in order to be able to login. There are two ways to address this issue:

  1. Use the new password reset feature.  This will only work if you have a mail service such as sendmail or postfix installed on your server, as it will attempt to send a password reset email to the user email.
  2. Delete all the users in the user table in the database.  Afterwards, going to the EgoWeb homepage will bring up a Create New Admin User form.  If there were multiple users who are not Super Admins who have authored studies, those studies will  no longer be accessible by non-Super Admins unless the study table is updated with the user ids of newly created users.

Update a server running the new framework

This set of instructions assumes you are running EgoWeb 2.0 to the new framework, version 2.0.10, and that there is a copy of egoweb in the ~/ folder. (You may need to install rsync if not installed already with the following command: > apt-get install rsync)

After logging in, type these following commands:

cd egoweb
git pull
rsync -avz app/ /var/www/html/

After these commands are successfully run, open a browser and log in to the version of EgoWeb 2.0 just updated. Go to the following URL extension of the EgoWeb 2.0 URL that is being updated:

~admin/migrate

If there are database changes, these will be migrated into the existing data base and EgoWeb 2.0 will be fully updated.


Creating a new Linux server with www.linode.com

The script below is available in the www.linode.com stack script library. This StackScript installs EgoWeb 2.0 and all software required to run on Linode. Most of the code should work on other systems. It was run in April 2020 by Scot Hickey (I have not run it myself) and he sent me the script and I pasted it here and created the stack script in Linode. I have not run it there.

Here are some notes provided by a project coordinator who set up an EgoWeb VM in 3/2020. The notes are based on reading the old instructions, so some of the stack script might have addressed what he noticed that was outdated.

1. Ubuntu 14.10 is very old, and most are using later distros (18.04, 20.04). Because of this some of the commands are out of date (sudo apt-get is now sudo apt). While apt-get still works, it’s outdated. 2. PHP latest release is 8.0.3, and therefore using phpenmod rather than php5enmod. 3. Mcrypt is not supported by default in PHP anymore (as of 7.1), so there were some extra steps I had to go through. Here is a good guide that should work: https://php.tutorials24x7.com/blog/how-to-install-mcrypt-for-php-7-on-ubuntu-20-04-lts 4. For those who aren’t super technically skilled, I would suggest that the step to replace the egowebpass in the config file should be it’s own step. 5. It might be helpful to your users to include a section on configuring apache for a custom domain / SSL.

Below is the stack script:

#!/bin/bash -e

exec > >(tee -i /var/log/stackscript.log)

# <UDF name=“DB_PASSWORD” Label=“Root password for mysql” example=“Password for administrative access to mysql.” />

DB_NAME=“egoweb” DB_USER=“egowebuser” DB_USER_PASSWORD=“egowebpass”

echo “db_password is $DB_PASSWORD” echo “db_name is $DB_NAME” echo “db_user is $DB_USER” echo “db_user_password is $DB_USER_PASSWORD”

############################################## # FUNCTIONS (SOMETIMES) USED DURING SETUP ##############################################

function system_update() {

 sudo apt-get update
  sudo dpkg --configure -a
  sudo apt-get -y install 
  # aptitude -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" full-upgrade

}

function system_primary_ip() {

  # returns the primary IP assigned to eth0
  echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')

}

function get_rdns() {

  # calls host on an IP address and returns its reverse dns
  if [ ! -e /usr/bin/host ]; then
      aptitude -y install dnsutils > /dev/null
  fi
  echo $(host $1 | awk '/pointer/ {print $5}' | sed 's/\.$//')

}

function get_rdns_primary_ip() {

  # returns the reverse dns of the primary IP assigned to this system
  echo $(get_rdns $(system_primary_ip))

}

function system_set_hostname() {

  # $1 - The hostname to define
  HOSTNAME="$1"
  if [ ! -n "$HOSTNAME" ]; then
      echo "Hostname undefined"
      return 1;
  fi
  echo "$HOSTNAME" > /etc/hostname
  hostname -F /etc/hostname

}

function system_add_host_entry() {

  # $1 - The IP address to set a hosts entry for
  # $2 - The FQDN to set to the IP
  IPADDR="$1"
  FQDN="$2"
  if [ -z "$IPADDR" -o -z "$FQDN" ]; then
      echo "IP address and/or FQDN Undefined"
      return 1;
  fi
  echo $IPADDR $FQDN  >> /etc/hosts

}

########################################################### # Users and Authentication ###########################################################

function user_add_sudo() {

  # Installs sudo if needed and creates a user in the sudo group.
  #
  # $1 - Required - username
  # $2 - Required - password
  USERNAME="$1"
  USERPASS="$2"
  if [ ! -n "$USERNAME" ] || [ ! -n "$USERPASS" ]; then
      echo "No new username and/or password entered"
      return 1;
  fi
  aptitude -y install sudo
  adduser $USERNAME --disabled-password --gecos ""
  echo "$USERNAME:$USERPASS" | chpasswd
  usermod -aG sudo $USERNAME

}

function user_add_pubkey() {

  # Adds the users public key to authorized_keys for the specified user. Make sure you wrap your input variables in double quotes, or the key may not load properly.
  #
  #
  # $1 - Required - username
  # $2 - Required - public key
  USERNAME="$1"
  USERPUBKEY="$2"
  if [ ! -n "$USERNAME" ] || [ ! -n "$USERPUBKEY" ]; then
      echo "Must provide a username and the location of a pubkey"
      return 1;
  fi
  if [ "$USERNAME" == "root" ]; then
      mkdir /root/.ssh
      echo "$USERPUBKEY" >> /root/.ssh/authorized_keys
      return 1;
  fi
  mkdir -p /home/$USERNAME/.ssh
  echo "$USERPUBKEY" >> /home/$USERNAME/.ssh/authorized_keys
  chown -R "$USERNAME":"$USERNAME" /home/$USERNAME/.ssh

}

function ssh_disable_root() {

  # Disables root SSH access.
  sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  touch /tmp/restart-ssh

}

########################################################### # Postfix ###########################################################

function postfix_install_loopback_only() {

  # Installs postfix and configure to listen only on the local interface. Also
  # allows for local mail delivery
  echo "postfix postfix/main_mailer_type select Internet Site" | debconf-set-selections
  echo "postfix postfix/mailname string localhost" | debconf-set-selections
  echo "postfix postfix/destinations string localhost.localdomain, localhost" | debconf-set-selections
  aptitude -y install postfix
  /usr/sbin/postconf -e "inet_interfaces = loopback-only"
  #/usr/sbin/postconf -e "local_transport = error:local delivery is disabled"
  touch /tmp/restart-postfix

}

########################################################### # Apache ###########################################################

function apache_install() {

  # installs the system default apache2 MPM
  aptitude -y install apache2
  a2dissite default # disable the interfering default virtualhost
  # clean up, or add the NameVirtualHost line to ports.conf
  sed -i -e 's/^NameVirtualHost \*$/NameVirtualHost *:80/' /etc/apache2/ports.conf
  if ! grep -q NameVirtualHost /etc/apache2/ports.conf; then
      echo 'NameVirtualHost *:80' > /etc/apache2/ports.conf.tmp
      cat /etc/apache2/ports.conf >> /etc/apache2/ports.conf.tmp
      mv -f /etc/apache2/ports.conf.tmp /etc/apache2/ports.conf
  fi

}

function apache_tune() {

  # Tunes Apache's memory to use the percentage of RAM you specify, defaulting to 40%
  # $1 - the percent of system memory to allocate towards Apache
  if [ ! -n "$1" ];
      then PERCENT=40
      else PERCENT="$1"
  fi
  # aptitude -y install apache2-mpm-prefork
  PERPROCMEM=10 # the amount of memory in MB each apache process is likely to utilize
  MEM=$(grep MemTotal /proc/meminfo | awk '{ print int($2/1024) }') # how much memory in MB this system has
  MAXCLIENTS=$((MEM*PERCENT/100/PERPROCMEM)) # calculate MaxClients
  MAXCLIENTS=${MAXCLIENTS/.*} # cast to an integer
  sed -i -e "s/\(^[ \t]*MaxClients[ \t]*\)[0-9]*/\1$MAXCLIENTS/" /etc/apache2/apache2.conf
  touch /tmp/restart-apache2

}

function apache_virtualhost() {

  # Configures a VirtualHost
  # $1 - required - the hostname of the virtualhost to create 
  if [ ! -n "$1" ]; then
      echo "apache_virtualhost() requires the hostname as the first argument"
      return 1;
  fi
  if [ -e "/etc/apache2/sites-available/$1" ]; then
      echo /etc/apache2/sites-available/$1 already exists
      return;
  fi
  mkdir -p /srv/www/$1/public_html /srv/www/$1/logs
  echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$1
  echo "    ServerName $1" >> /etc/apache2/sites-available/$1
  echo "    DocumentRoot /srv/www/$1/public_html/" >> /etc/apache2/sites-available/$1
  echo "    ErrorLog /srv/www/$1/logs/error.log" >> /etc/apache2/sites-available/$1
  echo "    CustomLog /srv/www/$1/logs/access.log combined" >> /etc/apache2/sites-available/$1
  echo "</VirtualHost>" >> /etc/apache2/sites-available/$1
  a2ensite $1
  touch /tmp/restart-apache2

}

function apache_virtualhost_from_rdns() {

  # Configures a VirtualHost using the rdns of the first IP as the ServerName
  apache_virtualhost $(get_rdns_primary_ip)

}

function apache_virtualhost_get_docroot() {

  if [ ! -n "$1" ]; then
      echo "apache_virtualhost_get_docroot() requires the hostname as the first argument"
      return 1;
  fi
  if [ -e /etc/apache2/sites-available/$1 ];
      then echo $(awk '/DocumentRoot/ {print $2}' /etc/apache2/sites-available/$1 )
  fi

}

########################################################### # mysql-server ###########################################################

function mysql_install() {

  # $1 - the mysql root password
  echo "mysql root pass is  $1"
  if [ ! -n "$1" ]; then
      echo "mysql_install() requires the root pass as its first argument"
      return 1;
  fi
  echo "mysql-server mysql-server/root_password password $1" | debconf-set-selections
  echo "mysql-server mysql-server/root_password_again password $1" | debconf-set-selections
  apt-get -y install mysql-server mysql-client
  echo "Sleeping while MySQL starts up for the first time..."
  sleep 5

}

function mysql_tune() {

  # Tunes MySQL's memory usage to utilize the percentage of memory you specify, defaulting to 40%
  # $1 - the percent of system memory to allocate towards MySQL
  if [ ! -n "$1" ];
      then PERCENT=40
      else PERCENT="$1"
  fi
  sed -i -e 's/^#skip-innodb/skip-innodb/' /etc/mysql/my.cnf # disable innodb - saves about 100M
  MEM=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo) # how much memory in MB this system has
  MYMEM=$((MEM*PERCENT/100)) # how much memory we'd like to tune mysql with
  MYMEMCHUNKS=$((MYMEM/4)) # how many 4MB chunks we have to play with
  # mysql config options we want to set to the percentages in the second list, respectively
  OPTLIST=(key_buffer sort_buffer_size read_buffer_size read_rnd_buffer_size myisam_sort_buffer_size query_cache_size)
  DISTLIST=(75 1 1 1 5 15)
  for opt in ${OPTLIST[@]}; do
      sed -i -e "/\[mysqld\]/,/\[.*\]/s/^$opt/#$opt/" /etc/mysql/my.cnf
  done
  for i in ${!OPTLIST[*]}; do
      val=$(echo | awk "{print int((${DISTLIST[$i]} * $MYMEMCHUNKS/100))*4}")
      if [ $val -lt 4 ]
          then val=4
      fi
      config="${config}\n${OPTLIST[$i]} = ${val}M"
  done
  sed -i -e "s/\(\[mysqld\]\)/\1\n$config\n/" /etc/mysql/my.cnf
  touch /tmp/restart-mysql

}

function mysql_create_database() {

  # $1 - the mysql root password
  # $2 - the db name to create
  if [ ! -n "$1" ]; then
      echo "mysql_create_database() requires the root pass as its first argument"
      return 1;
  fi
  if [ ! -n "$2" ]; then
      echo "mysql_create_database() requires the name of the database as the second argument"
      return 1;
  fi
  echo "CREATE DATABASE $2;" | mysql -u root -p$1

}

function mysql_create_user() {

  # $1 - the mysql root password
  # $2 - the user to create
  # $3 - their password
  if [ ! -n "$1" ]; then
      echo "mysql_create_user() requires the root pass as its first argument"
      return 1;
  fi
  if [ ! -n "$2" ]; then
      echo "mysql_create_user() requires username as the second argument"
      return 1;
  fi
  if [ ! -n "$3" ]; then
      echo "mysql_create_user() requires a password as the third argument"
      return 1;
  fi
  echo "CREATE USER '$2'@'localhost' IDENTIFIED BY '$3';" | mysql -u root -p$1

}

function mysql_grant_user() {

  # $1 - the mysql root password
  # $2 - the user to bestow privileges 
  # $3 - the database
  if [ ! -n "$1" ]; then
      echo "mysql_create_user() requires the root pass as its first argument"
      return 1;
  fi
  if [ ! -n "$2" ]; then
      echo "mysql_create_user() requires username as the second argument"
      return 1;
  fi
  if [ ! -n "$3" ]; then
      echo "mysql_create_user() requires a database as the third argument"
      return 1;
  fi
  echo "GRANT ALL PRIVILEGES ON $3.* TO '$2'@'localhost';" | mysql -u root -p$1
  echo "FLUSH PRIVILEGES;" | mysql -u root -p$1

}

########################################################### # PHP functions ###########################################################

function php_install_with_apache() {

  aptitude -y install php php-mysql libapache2-mod-php
  touch /tmp/restart-apache2

}

function php_tune() {

  # Tunes PHP to utilize up to 32M per process
  iniloc=$(php --ini | grep Loaded | cut -d" " -f12)
  # echo "iniloc is $iniloc"
  sed -i'-orig' 's/memory_limit = [0-9]\+M/memory_limit = 32M/' $iniloc
  touch /tmp/restart-apache2

}

function php_fixtimeout() {

  iniloc=$(php --ini | grep Loaded | cut -d" " -f12)
 echo "iniloc is $iniloc"
 sed -i 's/max_input_vars = [0-9]/max_input_vars = 10000/' $iniloc
 sed -i 's/max_execution_time = [0-9]/max_execution_time = 5000/' $iniloc
  sed -i 's/post_max_size = [0-9]\+M/post_max_size = 1900M/' $iniloc
  sed -i 's/upload_max_filesize = [0-9]\+M/upload_max_filesize = 2000M/' $iniloc
  sed -i 's/memory_limit = [0-9]\+M/memory_limit = 3072M/' $iniloc
  sed -i 's/max_file_uploads = [0-9]/max_file_uploads = 5000/' $iniloc
  touch /tmp/restart-apache2

}

function php_fixtimeouta() {

  iniloc=$(sudo find /etc/ -name php.ini | grep 'apache2')
 echo "iniloc is $iniloc"
 sed -i 's/max_input_vars = [0-9]/max_input_vars = 10000/' $iniloc
 sed -i 's/max_execution_time = [0-9]/max_execution_time = 5000/' $iniloc
  sed -i 's/post_max_size = [0-9]\+M/post_max_size = 1900M/' $iniloc
  sed -i 's/upload_max_filesize = [0-9]\+M/upload_max_filesize = 2000M/' $iniloc
  sed -i 's/memory_limit = [0-9]\+M/memory_limit = 3072M/' $iniloc
  sed -i 's/max_file_uploads = [0-9]/max_file_uploads = 5000/' $iniloc
  touch /tmp/restart-apache2

}

########################################################### # Other niceties! ###########################################################

function goodstuff() {

  # Installs the REAL vim, wget, less, and enables color root prompt and the "ll" list long alias
  aptitude -y install wget vim less
  sed -i -e 's/^#PS1=/PS1=/' /root/.bashrc # enable the colorful root bash prompt
  sed -i -e "s/^#alias ll='ls -l'/alias ll='ls -al'/" /root/.bashrc # enable ll list long alias <3

}

########################################################### # utility functions ###########################################################

function restartServices() {

  # restarts services that have a file in /tmp/needs-restart/
  for service in $(ls /tmp/restart-* | cut -d- -f2-10); do
      /etc/init.d/$service restart
      rm -f /tmp/restart-$service
  done

}

function randomString {

  if [ ! -n "$1" ];
      then LEN=20
      else LEN="$1"
  fi
  echo $(</dev/urandom tr -dc A-Za-z0-9 | head -c $LEN) # generate a random string

}

export DEBIAN_FRONTEND=noninteractive echo “Updating OS” sudo apt-get update sudo apt-get -y install aptitude

echo “Installing MySQL” mysql_install “$DB_PASSWORD” mysql_tune 40 mysql_create_database “$DB_PASSWORD” “$DB_NAME” mysql_create_user “$DB_PASSWORD” “$DB_USER” “$DB_USER_PASSWORD” mysql_grant_user “$DB_PASSWORD” “$DB_USER” “$DB_NAME” echo “Installing PHP and Apache” php_install_with_apache sudo apt-get -y install php-mbstring sudo apt-get -y install php-xml sudo apt-get -y install php-gd sudo apt-get -y install php-imagick apache_install && apache_tune 40 goodstuff php_tune php_fixtimeout php_fixtimeouta

restartServices

a2enmod rewrite

sudo apt-get install -y git echo 'CLONING EGOWEB FROM GIT' git clone https://github.com/qualintitative/egoweb –branch dev echo 'REMOVING DEFAULT WEB FILES' sudo rm -rf /var/www/* echo 'ADDING EGOWEB FILES TO WEB DIRECTORY' sudo cp -r egoweb/app/. /var/www/html/ echo 'SETTING UP TABLES IN MYSQL FOR EGOWEB - USE SQL FILE AS SOURCE' # echo “source /egoweb/sql/egoweb_db.sql” | mysql egoweb -u root -p$DB_PASSWORD mysql egoweb -u root -p$DB_PASSWORD < /egoweb/sql/egoweb_db.sql ELINENOF=$(grep -n '/var/www/' /etc/apache2/apache2.conf |cut -f1 -d:) ELINENO=$1) echo “$ELINENO s/None/All/” sed -i -e “$ELINENO s/None/All/” /etc/apache2/apache2.conf

restartServices

cd /var/www/html

./initialize.sh


Other Important Information

How to reset the administrative password

If attempts to login with any administrative passwords fail, access can be regained to an EgoWeb 2.0 installation by deleting all entries in the “user” table. If this table is blank when a user attempts to open an EgoWeb instance, the user is immediately prompted to create an administrative account name and password. Deleting entries in the “user” table can be done using MySQL for Linux installations, WAMP for Windows installations, and MAMP for Mac installations.

After re-entry into EgoWeb 2.0, any users that were deleted would have to be re-created using the new administrator account.

What to do if the page is not loading properly

If EgoWeb 2.0 code has changed, browsers may still load old versions of pages because they are storing page data in the cache. Sometimes there is a mixture of old and new page code, which can cause the page to appear broken in different ways.

To remedy this problem, do a hard browser refresh, which clears the browser’s cache for that page and forces the browser to load the current page code. Browsers hang onto old code so that they do not have to load everything each time you visit the same page, but it sometimes hangs onto too much.

Doing a hard refresh depends on the browser and the operating system. For Windows and Chrome, hold down the “ctrl” key and click the browser refresh (or F5) and this should make the menu bar load properly. For Mac, do the same but instead of “ctrl” hold down “shift”.

See this page about clearing the cache for other options.

OLD WAMP Instructions

1) Download EgoWeb files

The first step for running EgoWeb 2.0 on a laptop or desktop computer (for use without an active connection to the internet) is to download all of the program files onto the machine you are using. Download the latest zip file from https://github.com/qualintitative/egoweb and extract its contents onto the Desktop. There is a “Master” branch as well as a “dev” branch. Dev has more updated code by testing is in progress.

2) Download and install supporting programs: Visual Basic Windows Update

Because Windows cannot execute PHP scripts, additional software is necessary to run EgoWeb 2.0 on a desktop or laptop running Windows OS. To run EgoWeb 2.0 locally, you will need to install the software WampServer. This will allow a Windows machine to mimic the functions of a web server without broadcasting over the internet. Below are the steps for installing WampServer.

NOTE: Some older versions of Windows require installation of a Windows update program called “Visual C++ Redistributable for Visual Studio 2012 Update 4” before moving onto the WampServer software installation procedures described below. If you know that you have this update, you can skip to Step 3. However, it is probably a good idea to install and run the update just to be safe. In some previous attempts to install EgoWeb 2.0 without first installing the update file above, WAMP crashed after install because of a missing *.dll file that caused the WampServer install to break. This required uninstalling WampServer, deleting the remaining WAMP folder and then starting the reinstallation process again after installing the Visual C++ file. Therefore, we recommend installing this first before trying to install WampServer to be sure this does not need to happen.

The file was available for downloading at the link below when these instructions were written (but it's possible the link could change or be moved in the future): https://www.microsoft.com/en-us/download/details.aspx?id=30679

Download and run the file from the link above and follow the default installation steps. If the link above does not work because it has been changed, a current link can be found through an internet search for “Visual C++ Redistributable for Visual Studio 2012 Update 4”.

The download page looks like this:

3) Download and install supporting programs: WampServer (version 2.5)

Install WampServer by going to the following link and downloading the appropriate version (32 or 64 bit): WAMPSERVER 2.5.

NOTE: We have examples of users who had installation problems with WAMP 3.0+ and the problem was fixed by using 2.5. Therefore, we recommend 2.5! The main WampServer page with current versions of WAMP is at http://www.wampserver.com/en/ but this will take you to newer versions of WampServer that cause problems. All of the installation instructions are based on WAMP version 2.5, 64-bit, so to avoid problems use this version.

Select default options for the install. Other versions may require slight variations. Therefore, we recommend the 64-bit version if possible.

4) Start WampServer and services

If it's not already running after installation, start WampServer from the Windows start menu.

NOTE: This required an admin login to run after initial set up.

Locate the WAMP menu in system tray (lower right-hand side of Windows desktop screen). If the icon is not green, you may need to manually install a component. For instance, I had to manually install Apache by going to Apache → Service → Install Service, then start it by going to Apache → Service → Start Service.

5) Edit httpd.conf

From the WAMP Menu, go to Apache → httpd.conf. In Notepad, search for the phrase “AllowOverride all” and remove the hash tag character (“#”) immediately preceding it. Save the file.

6) Enable the rewrite module

From the WAMP menu, make sure Apache → Apache Modules → rewrite_module is checked. Clicking on an unchecked module will enable it.

After clicking on rewrite_module, WAMP will reboot. Follow the same steps as above to confirm that the rewrite_module has been checked.

7) Launch PHPMyAdmin

Click on the WAMP menu in the system tray, and visit PHPMyAdmin, a PHP Application that allows you to manage the MySQL server in WAMP. A browser should open with PHPMyAdmin loaded. If you are prompted for a password, leave it blank and log in.

8) Create default egoweb database

In the PHPMyAdmin browser window, click on “databases.” Under “Create database”, put in “egoweb” for the database name (all lowercase) and select “utf8mb4_unicode_ci” for the collation. (We have previously recommended utf8_general_ci for fast performance, but that may have issues with special characters). Click create. A new database named “egoweb” should appear in the left sidebar.

9) Import database structure from SQL file

In the PHPMyAdmin browser window, click on “egoweb”, then select “Import” from the top navigation bar. Click on the file input under “File to import”. Find “egoweb_db.sql” in the “sql” folder among the extracted files on the desktop. After the file is selected, click on “Go” at the bottom of the page. The egoweb database should now be populated with tables.

10) Add user privileges to egoweb database

In the PHPMyAdmin browser window, click on “privileges” in the navigation menu, then click on the “Add User” link. The default username is “egowebuser” and the default password is “egowebpass”. For production servers, please replace egowebpass with a password of your choice. if you change this value you will need to change the corresponding value in the “main.php” config file. Select “Local” for the host field. Click on “Go” at the bottom of the page.

11) Install the EgoWeb 2.0 PHP files into the WAMP www directory

12) Configure EgoWeb 2.0

13) Start EgoWeb 2.0

Open a browser and go to “http://localhost” to start using EgoWeb 2.0. You will be prompted to create an admin user. After creating the user, you can log in to EgoWeb 2.0 with the user’s email and password. Enjoy!

NOTE: The initial installation was conducted with an administrator account. A non-admin account could not run wampserver. We attempted to set up wampserver to automatically load at startup without administrative rights but have not figured that out yet. We will update the documentation when we identify reliable procedures.


Update an EgoWeb 2.0 installation on a Windows machine

1) Repeat steps from the main installation instructions starting with Step 11 (copy files from the .zip file webapp folder into the www folder).

2) Type the following into a browser address and hit enter:

localhost/admin/migrate

If there are database changes, these will be migrated into the existing data base and EgoWeb 2.0 will be fully updated. If there are no changes that need to be migrated, running this will confirm that your system is up to date.


1)
$ELINENOF + 2