Duplicating Application to New Server

OS: Ubuntu 12.04 LTS (Precise Pangolin) in VPS (OpenVZ)

In this example we will duplicate the https://gas-devel.leader.it application into https://intergas-devel.leader.it. The old database is gas, the new one intergas. Because the MasonSQL application is already installed on the server no additional packages need to be installed.

On this page:

Install Packages

For the Postgres follow the PostgreSQL 9.5 installation recommendations.

Install the remaining packages:

# Proceed with root privileges
sudo su -

# Locale settings
update-locale LC_ALL=it_IT.UTF-8 LANG=it_IT.UTF-8
locale-gen

# Time zone
dpkg-reconfigure tzdata

# Update packages
apt-get update
apt-get upgrade
apt-get dist-upgrade


## Packages needed to use MasonSQL

# Apache2 & mod_perl

# Ubuntu template already installed package apache2 apache2-mpm-prefork
apt-get install libapache2-mod-perl2 libapache2-request-perl
a2enmod apreq perl ssl

# Postgresql & Perl DBI, DBD::Pg
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >/etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
apt-get install postgresql-9.6 postgresql-client-9.6 postgresql-plperl-9.6 postgresql-contrib-9.6

# Perl DBI, DBD::Pg
apt-get install build-essential libpq-dev
cpan DBD::Pg
apt-get install libdbi-perl libapache-dbi-perl

# Various packages
apt-get install libjson-perl libautobox-perl libxml-simple-perl libclone-perl
apt-get install liblog-log4perl-perl libipc-run-perl
apt-get install libspreadsheet-writeexcel-perl libtext-unidecode-perl

# Mail::Sender
apt-get -y purge libmail-sender-perl
cpan Mail::Sender

# Mason
apt-get install libhtml-mason-perl

# ODT Report manager
apt-get install python-software-properties
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt-get update
sudo apt-get upgrade
apt-get install libreoffice-writer
apt-get install pdftk
apt-get install file
# user auto registration
apt-get install libstring-random-perl

# Various packages available from CPAN
cpan String::Diff
cpan install App::cpanminus
# with new releases authentication not work
cpanm Apache2::AuthCookie@3.23
cpan SQL::Statement
cpan HOP::Lexer
cpan SQL::Dialects::ANSI
cpan SQL::Interpolate
cpan Sys::RunAlone
cpan MIME::Parser
cpan Archive::Tar::Wrapper
cpan Archive::Zip
cpan Perl6::Form
cpan HTTP::BrowserDetect
cpan IPC::Run::SafeHandles
cpan Text::Balanced
# user auto registration
cpan Captcha::reCAPTCHA

Duplicate Database

On Old Server

Make gas.tar.gz package and database dump:

sudo tar -f ~/gas.tar.gz -czv /COPIA/masonsql_dojo1.9 /COPIA/dojo-release-1.9.2 /COPIA/dojo-release-1.9.2-src /opt/gas_dojo1.9
sudo -upostgres pg_dump -f db.out gas

Copy gas.tar.gz, db.out and roles.sql files to the new server;

On New Server

# Change dir name:
mv /opt/gas_dojo1.9 /opt/intergas_dojo1.9

# Create links in /opt/:
cd /opt
ln -s  /COPIA/masonsql_dojo1.9 masonsql_dojo1.9
ln -s masonsql_dojo1.9 masonsql
ln -s intergasgas_dojo1.9 intergas

# Customize and apply the roles.sql file:
# Rename all occurrences of string "TO gas;" to "TO intergas;".
# Add a new username "intergas".

# Create a new database:
sudo -upostgres createdb intergas -E unicode -T template0 --lc-collate='it_IT.UTF-8' --lc-ctype='it_IT.UTF-8'

# Restore the old database into the new one:
sudo -upostgres sh -c "cat db.out | psql intergas"

Now the gas database is duplicated into the intergas which contains schema gas.

Change Database Access Permissions

We edit /etc/postgresql/9.6/main/pg_hba.conf, duplicating gas configuration and renaming it to intergas:

# intergas.leader.it
local   intergas    intergas                                password
host    intergas    intergas    127.0.0.1 255.255.255.255   password

Then we find location of the pg_ctl executable and the location of the database files in order to reload the configuration:

sudo -upostgres /usr/lib/postgresql/9.6/bin/pg_ctl reload -D /var/lib/postgresql/9.6/main

Finish Environment Setup

chmod 755 /var/log/apache2/
chmod 770 /opt/intergas/archive/
chmod 770 /var/log/apache2/intergas
chown root.www-data /var/log/apache2/intergas

# Update the DBD::Pg perl package:
apt-get install postgresql-server-dev-9.5
cpan DBD::Pg

# Customize Apache2 configuration file:
# Edit the configuration file by adjusting the parameters: 
# VirtualHost, SSLCertificateFile, SSLCertificateKeyFile, ServerAdmin, ServerName, MailFrom, Auth_AC_Domain, DBIconnect, etc;

# Rename Apache2 configuration file:
mv /opt/intergas/etc/apache2.gas-devel.leader.it.conf /opt/intergas/etc/apache2.intergas-devel.leader.it.conf

# Link it to the Apache2 configuration folder:
ln -s /opt/intergas/etc/apache2.intergas-devel.leader.it.conf /etc/apache2/conf.d/intergas.conf


#Duplicate command in the /etc/crontab to periodically empty the temporary files folder:

# svuoto file temporanei di intergas.leader.it
12 6  * * *     root find /opt/intergas/tmp -maxdepth 1 -mindepth 1 -mtime +7 -exec rm -r '{}' ';'

New Putty and pgAdmin Settings

New Putty tunnel:

NewPuttyTunnel.PNG

Changed pgAdmin settings:

NewPgAdminSettings.PNG
Topic revision: r9 - 18 Mar 2017, GuidoBrugnara
This site is powered by FoswikiCopyright (©) Leader.IT - Italy P.I. IT01434390223 Privacy policy & use of cookies