Difference between revisions of "Tutorial: PhpRunner 9.8 and Photo Display"

From dftwiki3
Jump to: navigation, search
 
(18 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
----
 
----
 
<onlydft>
 
<onlydft>
 
+
=PhpRunner 9.8 on MacBook Pro=
=Remote Server: Hadoop0=
+
* Get IP of MacBook (192.168.1.151)
 +
* Start Parallels
 +
* Start Windows7
 +
* Start PhpRunner9.8
 +
* Project NohoSkies
 +
* Set mysql server to 192.168.1.151 (whatever address MacBook has)
 +
=Transfer Project to Hadoop01=
 +
* In Output window of PhpRunner, pick or create server for MySQL that is localhost, as when on hadoop01, the MySQL and Apache2 will be on same server. 
 +
* Build All
 +
* Run script rsyncPhotos.sh on MacBook (see below)
 +
=Remote Server Setup: Hadoop0=
 
* Reinstall Ubuntu 16.04.4 on Hadoop0.  Desktop AMD64.
 
* Reinstall Ubuntu 16.04.4 on Hadoop0.  Desktop AMD64.
 
* Install ddclient with hadoop0.dyndns.org
 
* Install ddclient with hadoop0.dyndns.org
Line 9: Line 19:
 
* Install openssh-server
 
* Install openssh-server
 
* Then create virtualbox server hadoop01, Ubuntun 16.04.4 (temporarily add real DVD player to virtual box to load OS)
 
* Then create virtualbox server hadoop01, Ubuntun 16.04.4 (temporarily add real DVD player to virtual box to load OS)
==VirtualBox: Hadoop01==
+
==VirtualBox: Hadoop01 setup==
 
* Install ddclient, hadoop01
 
* Install ddclient, hadoop01
 
* Install emacs
 
* Install emacs
Line 22: Line 32:
 
  post_max_size = 48M
 
  post_max_size = 48M
 
</source>
 
</source>
==Script to copy PHPRunner Output Folder to Hadoop01==
+
==Script to copy PHPRunner Output Folder on MacBook to Hadoop01==
 +
<br />
 +
* Change '''voidfunction''' to real password
 
<br />
 
<br />
 
::<source lang="bash">
 
::<source lang="bash">
Line 32: Line 44:
 
echo "rsyncing php dir to hadoop01"
 
echo "rsyncing php dir to hadoop01"
 
rsync -azv ~/Documents/PHPRunnerOutput/* dominique@hadoop01.dyndns.org:/var/www/html/photos/
 
rsync -azv ~/Documents/PHPRunnerOutput/* dominique@hadoop01.dyndns.org:/var/www/html/photos/
 +
ssh -tt dominique@hadoop01.dyndns.org <<EOF
 +
chmod g+w /var/www/html/photos/files
 +
exit
 +
EOF
  
 
# dump photo database to sql file
 
# dump photo database to sql file
Line 38: Line 54:
  
 
#echo -n "Enter mysql root password on MacBook: "
 
#echo -n "Enter mysql root password on MacBook: "
mysqldump -u root -pvoidm%20 NohoSkies >> NohoSkies.sql
+
mysqldump -u root -pvoidfunction NohoSkies >> NohoSkies.sql
  
 
echo "rsyncing dum to hadoop01"
 
echo "rsyncing dum to hadoop01"
Line 45: Line 61:
 
echo "loading up dump on remote db"
 
echo "loading up dump on remote db"
 
ssh -tt dominique@hadoop01.dyndns.org <<EOF  
 
ssh -tt dominique@hadoop01.dyndns.org <<EOF  
mysql -u root -pvoidm%20 < ~/Downloads/NohoSkies.sql  
+
mysql -u root -pvoidfunction < ~/Downloads/NohoSkies.sql  
 
exit
 
exit
 
EOF
 
EOF
Line 52: Line 68:
 
   
 
   
  
 +
 +
=Misc.=
 +
==How to send message to /var/log/apache2/error.log==
 +
<br />
 +
::<source lang="php">
 +
// in php script:
 +
file_put_contents('php://stderr', print_r( $dico, TRUE));
 +
</source>
 +
<br />
 +
The TRUE value in print_r makes print_r return the string it displays rather than displaying it.
 +
<br />
 +
==How to get width and height of uploaded image==
 +
<br />
 +
::<source lang="php">
 +
$fileInfozzz = $values["fileName"];
 +
$dicozzz = explode( ",", $fileInfozzz );
 +
$fileNamezzz = str_replace( "[{", "", $dicozzz[0] );
 +
$fileNamezzz = str_replace( "\"", "", explode( ":", $fileNamezzz )[1] );
 +
$fileNamezzz = str_replace( "\\", "", $fileNamezzz );
 +
$filePathzzz = $_SERVER["DOCUMENT_ROOT"]. "/photos/" . $fileNamezzz;
 +
$paramszzz = getimagesize( $filePathzzz );
 +
$widthzzz = $paramszzz[0];
 +
$heightzzz = $paramszzz[1];
 +
 +
//file_put_contents('php://stderr', print_r( "\nBefore Record Added\ndico=", TRUE ) );
 +
//file_put_contents('php://stderr', print_r( $dico, TRUE));
 +
//file_put_contents('php://stderr', print_r( "\nfilePath=", TRUE ) );
 +
//file_put_contents('php://stderr', print_r( $filePathzzz, TRUE));
 +
//file_put_contents('php://stderr', print_r( "\nparams=", TRUE ) );
 +
//file_put_contents('php://stderr', print_r( $paramszzz, TRUE ));
 +
 +
file_put_contents('php://stderr', print_r( "\nwidth = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $widthzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $heightzzz, TRUE ));
 +
 +
 +
// pass width and height to javascript (not sure this works...)
 +
//$pageObject->setProxyValue("widthzzz", $widthzzz);
 +
//$pageObject->setProxyValue("heightzzz",$heightzzz);
 +
 +
</source>
 +
==How to compute dpi, width, height and store in MySQL DB==
 +
===Reproduced, Add page, "After Record Added" Event===
 +
<br />
 +
::<source lang="php">
 +
 +
 +
 +
$fileInfozzz = $values["fileName"];
 +
$dicozzz = explode( ",", $fileInfozzz );
 +
$fileNamezzz = str_replace( "[{", "", $dicozzz[0] );
 +
$fileNamezzz = str_replace( "\"", "", explode( ":", $fileNamezzz )[1] );
 +
$fileNamezzz = str_replace( "\\", "", $fileNamezzz );
 +
$filePathzzz = $_SERVER["DOCUMENT_ROOT"]. "/photos/" . $fileNamezzz;
 +
$paramszzz = getimagesize( $filePathzzz );
 +
$widthzzz = (int) $paramszzz[0];
 +
$heightzzz = (int) $paramszzz[1];
 +
/*
 +
file_put_contents('php://stderr', print_r( "\nwidth = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $widthzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $heightzzz, TRUE ));
 +
*/
 +
 +
// get DPI info
 +
$dpi = 72;
 +
$cmd = 'identify -quiet -format "%x" '.$filePathzzz;     
 +
@exec( escapeshellcmd($cmd), $data );
 +
if($data && is_array($data)){
 +
  $data = explode(' ', $data[0]);
 +
  if($data[1] == 'PixelsPerInch'){
 +
      $dpi = $data[0];
 +
  } elseif($data[1] == 'PixelsPerCentimeter'){
 +
      $dpi = ceil($data[0] * 2.54);
 +
  }elseif($data[1] == 'Undefined'){
 +
      $dpi = $data[0];
 +
  }                     
 +
}
 +
$dpi = (int) $dpi;
 +
 +
//file_put_contents('php://stderr', print_r( "\n\n\ndpi=", TRUE ) );
 +
//file_put_contents('php://stderr', print_r( $dpi, TRUE ));
 +
//file_put_contents('php://stderr', print_r( "\n", TRUE ) );
 +
 +
$widthIn = $widthzzz / $dpi;
 +
$heightIn = $heightzzz / $dpi;
 +
 +
 +
// pass width and height to javascript
 +
//$pageObject->setProxyValue("widthzzz", $widthzzz);
 +
//$pageObject->setProxyValue("heightzzz",$heightzzz);
 +
 +
// --- get last record added to reproduced table
 +
$sql = "SELECT Id FROM reproduced ORDER BY Id DESC LIMIT 1";
 +
$res = CustomQuery($sql);
 +
$data = db_fetch_array($res);
 +
$Id = $data["Id"];
 +
 +
//--- display Id of last record
 +
//file_put_contents('php://stderr', print_r( $data["Id"], TRUE ));
 +
//file_put_contents('php://stderr', "\n" );
 +
 +
//--- update width and height of record just added ---
 +
$sql = "Update reproduced set dpi='$dpi', widthP='$widthzzz'," .
 +
      " widthIn='$widthIn', heightIn='$heightIn',".
 +
      " heightP='$heightzzz' where Id=".$Id;
 +
CustomQuery($sql);
  
  
 +
</source>
 +
<br />
 +
===Originals, Add Page, "After Record Added" Event===
 +
<br />
 +
::<source lang="php">
  
 +
$fileInfozzz = $values["fileName"];
 +
$dicozzz = explode( ",", $fileInfozzz );
 +
$fileNamezzz = str_replace( "[{", "", $dicozzz[0] );
 +
$fileNamezzz = str_replace( "\"", "", explode( ":", $fileNamezzz )[1] );
 +
$fileNamezzz = str_replace( "\\", "", $fileNamezzz );
 +
$filePathzzz = $_SERVER["DOCUMENT_ROOT"]. "/photos/" . $fileNamezzz;
 +
$paramszzz  = getimagesize( $filePathzzz );
 +
$widthzzz    = $paramszzz[0];
 +
$heightzzz  = $paramszzz[1];
  
 +
file_put_contents('php://stderr', print_r( "Originals\n============\nwidth = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $widthzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $heightzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nfilePathzzz = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $filePathzzz, TRUE ));
  
</onlydft>
+
 
 +
// get DPI info
 +
$dpi = 72;
 +
$cmd = 'identify -quiet -format "%x" '.$filePathzzz;     
 +
@exec( escapeshellcmd($cmd), $data );
 +
if($data && is_array($data)){
 +
  $data = explode(' ', $data[0]);
 +
  if($data[1] == 'PixelsPerInch'){
 +
      $dpi = $data[0];
 +
  } elseif($data[1] == 'PixelsPerCentimeter'){
 +
      $dpi = ceil($data[0] * 2.54);
 +
  }elseif($data[1] == 'Undefined'){
 +
      $dpi = $data[0];
 +
  }                     
 +
}
 +
$dpi = (int) $dpi;
 +
 
 +
file_put_contents('php://stderr', print_r( "\n\n\noriginals:  dpi=", TRUE ) );
 +
file_put_contents('php://stderr', print_r( $dpi, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nwidth = ", TRUE ) );
 +
file_put_contents('php://stderr', print_r( $widthzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ) );
 +
file_put_contents('php://stderr', print_r( $heightzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\n", TRUE ) );
 +
 
 +
// --- get last record added to reproduced table
 +
$sql = "SELECT Id FROM originals ORDER BY Id DESC LIMIT 1";
 +
$res = CustomQuery($sql);
 +
$data = db_fetch_array($res);
 +
$Id = (int) $data["Id"];
 +
 
 +
//--- display Id of last record
 +
file_put_contents('php://stderr', "\n" );
 +
file_put_contents('php://stderr', print_r( $data["Id"], TRUE ));
 +
file_put_contents('php://stderr', "\n" );
 +
 
 +
//--- update width and height of record just added ---
 +
$sql = "Update originals set dpi='$dpi', width='$widthzzz'," .
 +
      " height='$heightzzz' where Id=".$Id;
 +
CustomQuery($sql);
 +
 
 +
 
 +
</source>
 
<br />
 
<br />
 +
=Create Photo Project=
 
<br />
 
<br />
 +
* Windows 7
 +
* PhpRunner 9.8
 +
* Blank Project
 +
* MySQL 192.168.1.139 (whatever ifconfig returns on Mac)
 +
* Tables
 +
::* originals
 +
::* reproduced
 +
::* Master - Details relationship
 +
:::* [Master] Reproduced:originalId &lt;===&gt; [Details] Originals:Id
 +
* SQL Query
 +
:* Add CONCAT fields to queries for original and reproduced:
 +
:<source lang="mysql">
 +
  CONCAT( `widthP`, ' x ', `heightP` ) as wxh_p,
 +
  CONCAT( `widthIn`, ' x ', `heightP` ) as wxh_In,
 +
  CONCAT( `width`, 'x', `height` ) as wxh,
 +
</source>
 +
* Fields
 +
::* unselect individual width and height fields, and select CONCAT fields
 +
* Fields Order and Totals
 +
::* Put Details:Original at the top in pages showing reproduced records
 +
* Miscellaneous
 +
::* Change the labels to use when displaying all the fields
 +
* Security
 +
::* Add login using '''users''' table
 +
* Style Editor
 +
::* Boostrap1/Darkly
 +
* Output Directory
 +
::* Z:Documents\PHPRunnerOutput\
 +
::* Server Database Connections
 +
::* Create new connection
 +
:::*$host="localhost";
 +
:::*$user="nohoSkies";
 +
:::*$pwd="xxxxxxxxxxx"
 +
:::*$port="";
 +
:::*$sys_dbname="NohoSkies";
 +
::* User new connection made
 
<br />
 
<br />
 +
==Setup Server==
 +
* Make sure to create a '''files''' subdirectory and set its privileges for g+w
 +
==Setup PHPRunner Project on AWS==
 +
* Connect to AWS.amazon.com
 +
* Connect to EC2
 +
* Verify that can connect to running EC2 using PEM key in .ssh
 +
* create directory in /data/html: '''photos'''
 +
* chown '''photos''' to '''ubuntu:www-data'''
 +
* create '''files''' directory in photos
 +
* chmod '''files''' to '''og+w'''
 +
* rsync all files to /data/html/photos/ directory:
 +
 +
cd ~/Documents/PHPRunnerOutput/
 +
fullDir=/data/html/photos/
 +
rsync -az --progress -e "ssh -i ~/.ssh/mykeyDFT.pem" \
 +
      ~/Documents/PHPRunnerOutput/*                \
 +
      ubuntu@dominiquefthiebaut.com:$fullDir
 +
 +
* chown all the files to www-data:www-data:
 +
 
 +
fullDir=/data/html/photos/
 +
ssh -i "~/.ssh/mykeyDFT.pem" -t ubuntu@dominiquefthiebaut.com \
 +
      sudo chown -R www-data:www-data $fullDir 2> /dev/null
 +
 +
* Create MYSQL User and DB.  On EC2
 +
 +
mysql -u root -p
 +
create database NohoSkies;
 +
CREATE USER 'nohoSkies'@'localhost' IDENTIFIED BY 'xxxxxxxx';
 +
grant all privileges on NohoSkies . * to 'nohoSkies'@'localhost' ;
 +
FLUSH PRIVILEGES;
 +
quit
 +
 +
* Migrate MySQL database from MacBook to EC2
 +
 +
cd ~/Downloads/
 +
echo "USE NohoSkies;" > NohoSkies.sql
 +
mysqldump -u root -pvoidm%20  NohoSkies >> NohoSkies.sql
 +
 +
echo "rsyncing MySqlDump to EC2"
 +
rsync -az -e "ssh -i ~/.ssh/mykeyDFT.pem" \
 +
      NohoSkies.sql ubuntu@dominiquefthiebaut.com:Downloads/
 +
 +
echo "loading up MySQL dump in EC2 MySQL DB"
 +
ssh -i "~/.ssh/mykeyDFT.pem" -tt ubuntu@dominiquefthiebaut.com <<EOF
 +
mysql -u root -pvoidm%20 < ~/Downloads/NohoSkies.sql
 +
exit
 +
EOF
 +
 +
*
 +
 +
==Cron Script to Backup S2 Photos directory+MySql to S3==
 
<br />
 
<br />
 +
::<source lang="bash">
 +
#! /bin/bash
 +
# ~/bin/backupNohoSkies.sh
 +
# D. Thiebaut
 +
# --------------------------------------------------------------------------------
 +
 +
# --------------------------------------------------------------------------------
 +
# BACKUP MYSQL
 +
# --------------------------------------------------------------------------------
 +
#
 +
echo mysqldump
 +
mysqldump --user=nohoSkies --password=voidm%20 NohoSkies > /home/ubuntu/backups/NohoSkies/NohoSkies.sql
 +
# 2> /dev/null
 +
# copy to S3
 +
cd /home/ubuntu/backups/NohoSkies
 +
gzip -f NohoSkies.sql
 +
echo uploading sql file to S3
 +
s3cmd  put  NohoSkies.sql.gz  s3://backup-dft-hadoop02/NohoSkies/
 +
 +
# --------------------------------------------------------------------------------
 +
# BACKUP PHP FILES (ON SUNDAYS ONLY)
 +
# --------------------------------------------------------------------------------
 +
cd /data/html/photos/
 +
_DATE="$(LC_ALL=C date +%A)"
 +
if test "$_DATE" = "Sunday"
 +
then
 +
  echo tar-zipping php files
 +
  tar --exclude='./files' -czf /home/ubuntu/backups/NohoSkies/NohoSkiesPhp.tgz *
 +
  echo uploading php files to s3
 +
  s3cmd put /home/ubuntu/backups/NohoSkies/NohoSkiesPhp.tgz s3://backup-dft-hadoop02/NohoSkies/
 +
fi
 +
 +
# --------------------------------------------------------------------------------
 +
# SYNC PHOTOS ONLY
 +
# --------------------------------------------------------------------------------
 +
cd /data/html/photos/files/
 +
s3cmd sync ./ s3://backup-dft-hadoop02/NohoSkies/files/
 +
 +
 +
</source>
 
<br />
 
<br />
 +
</onlydft>
 +
 
<br />
 
<br />
 
<br />
 
<br />

Latest revision as of 14:59, 8 June 2018

D. Thiebaut (talk) 10:38, 25 May 2018 (EDT)



...