Prestashop | Copy an Online “production” to a “local” VM/Server

How-to move a “production” Prestashop online shop to another Server (here a Local VM) for dev or upgrade tests purpose.

The Online setup :

  • Prestashop is hosted on OVH
  • Prestashop version is 1.4.4.1
  • url : http://myshop.pretendco.com

The Local Setup :

  • host System : Mac Os X 10.6+ for dev/coding (Coda,TextWrangler,Transmit)
  • VM (parallels) : Debian 7 – with php-mySQL-apache
  • url : http://shopdev.intra.pretendco.com

I’ll assume here you don’t have internal DNS, or you don’t have admin rights on it,
or… well you know you won’t have all you want from the admin in charge because he is really too “busy”.

Before beginning you have to :

  • download your online FTP shop directory (datas) on your dev Machine (My Mac here)**
  • get a dump of the sql database of your shop (if you’re on ovh just go to the phpmyadmin from your Manager) – you can also get this from the BackOffice.

Steps

  • Step0 : create local working directory with PS 1.4.4.1 / and git init
  • Step1A : edit apache2 config on the VM
  • Step1B : create folder for the website on the VM & on Dev Machine ; apply permissions
  • Step2 : edit /etc/host on VM & on Dev Machine
  • Step3 : add site(s) to sites-enable and reload apache or restart apache
  • Step4 : test connection
  • Step5 : create empty db shopdev on zeus
  • Step6 : Search and replace from ovh dump to new dump (hostname, etc)
  • Step7 : Create Bookmark in CODA and Transmit
  • Step8 : Upload new SQL dump to shopdev db
  • Step9 : Move (copy) datas (like imgs etc… to new fresh shopdev) from prod server to local (for zeus – from ovh)
  • Step10 : Search and replace on hard coded url in files (themes and modules)
  • Step11 : go to shopdev.intra.pretendco.com
Step0 – I do this on the Dev Machine
-get http://www.prestashop.com/download/old/prestashop_1.4.4.1.zip

Create the folder where you’ll put the files and work.
Create a new git repo in it
Unzip and move content of the prestashop folder to your working directory.

-Make your 1st Commit - fresh Prestashop
Step1A /etc/apache2/sites-available/shopdev

On the VM / Server

nano /etc/apache2/sites-available/shopdev

and add

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/shopdev
ServerName shopdev.intra.pretendco.com
ServerAlias shopdevms1.intra.pretendco.com
ServerAlias shopdevms2.intra.pretendco.com
ServerAlias shopdevms3.intra.pretendco.com
ServerAlias shopdevms4.intra.pretendco.com

<Directory /var/www/shopdev>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

#ErrorLog ${APACHE_LOG_DIR}/shopdev.error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

#CustomLog ${APACHE_LOG_DIR}/shopdev.access.log combined
</VirtualHost>
Step1B : create folder for the website ; apply permissions
mkdir /var/www/shopdev
chown -R www-data:www-data /var/www/shopdev
chmod 755 /var/www/shopdev
Step2 : Edit /etc/hosts

On the VM / Webserver itself

nano /etc/hosts

add

127.0.0.1   localhost
127.0.0.1   shopdev.intra.pretendco.com
127.0.0.1   shopdevms1.intra.pretendco.com
127.0.0.1   shopdevms2.intra.pretendco.com
127.0.0.1   shopdevms3.intra.pretendco.com

on your webdev machine

either you have control on your dns, or the Admin is not too picky

either you edit your /etc/hosts and change 127.0.0.1
with the correct IP address of the server !

sudo nano /etc/hosts

add

192.168.1.110   shopdev.intra.pretendco.com shopdev
192.168.1.110   shopdevms1.intra.pretendco.com
192.168.1.110   shopdevms2.intra.pretendco.com
192.168.1.110   shopdevms3.intra.pretendco.com

don’t forget to do this or you just won’t access
shopdev.intra.pretendco.com from any other host than the VM server itself. (unless you have a DNS server that you can change or a nice admin)

Step3 : add site(s) to sites-enable and reload apache or restart apache
a2ensite shop1

don’t forget this step to add your new website !

service apache2 reload

or

service apache2 restart
Step4 : test

Create a file like phpinfo for instance, so that it is also usefull…

nano /var/www/shopdev/phpinfo.php

add

<?php
    phpinfo();
?>

or copy it if you have one already

cp /var/www/phpinfo.php /var/www/shopdev/phpinfo.php

in case you weren’t www-data, apply ownership

chown -R www-data:www-data /var/www/shopdev/*

or we could have done

sudo su - www-data
nano /var/www/shopdev/phpinfo.php

go to : http://shopdev.intra.pretendco.com

You should see your php info.


So you now have a running website for your upcomming dev prestashop.


Step5 : create empty db shopdev on zeus
creating shopdev db on zeuserv

done via phpmyadmin.

Step6 SQL dump _ Search&Replace 20131127.1542

add dump file to working directory (_sql_dump directory)
Commit the file with git !
file : 20140426.myshop_to_shopdev.dump.sql

Search&Replace 1

http://myshop.pretendco.com => http://shopdev.intra.pretendco.com

done : 18945 occurences of “http://myshop.pretendco.com” where replaced with “http://shopdev.intra.pretendco.com”

Search&Replace 2

myshop.pretendco.com => shopdev.intra.pretendco.com

done : 89122 occurences of “myshop.pretendco.com” where replaced with “shopdev.intra.pretendco.com”

Search&Replace 3

mediaserver stuff

3a
myshopms1.pretendco.com => shopdevms1.intra.pretendco.com

5660 occurences of “myshopms1.myshop.pretendco.com” where replaced with “shopms1.intra.pretendco.com”

3b

myshopms2.pretendco.com => shopdevms2.intra.pretendco.com

6553 occurences of “myshopms2.myshop.pretendco.com” where replaced with “shopms2.intra.pretendco.com”

3c

myshopms3.pretendco.com => shopdevms3.intra.pretendco.com

4338 occurences of “myshopms3.myshop.pretendco.com” where replaced with “shopms3.intra.pretendco.com”

DONE

Commit the file with git !
Step7 : Create Bookmark in CODA and Transmit
  • Transmit &Coda :

Done

Step8 : Upload new SQL dump to shopdev db

ftp upload via transmit (FTP)

Upload 20140426.myshop_to_shopdev.dump.sql to shopdev (transmit)

done

Mysql import via phpmyadmin

Import 20140426.myshop_to_shopdev.dump.sql to shopdev db (phpmyadmin)
Import has been successfully finished, 1742 queries executed. (20140426.myshop_to_shopdev.dump.sql)

done

WARNING !
to prevent SQL error need to do :
cf : http://forge.prestashop.com/browse/PSCFV-5631
run this SQL QUERY
ALTER TABLE dclps_category_product ADD PRIMARY KEY (id_category, id_product)
OK did the trick on my previous tests, I’m doing it ealier. => ERROR => ALREADY EXISTS !!

I had to do it on one test, had not on others

Step 9 : Move (copy) datas (like imgs etc… to new fresh shop0) from prod server to local (for zeus – from ovh)

NOTE :
even if you use git, you may duplicate and rename with ending .orig any files or folder you may want and add eventually *.orig to your .gitignore.

Les dossiers suivants doivent être copiés depuis votre dossier "prestashop-prod" vers le dossier "prestashop-prep" :

/mails Contient tous les modèles de mails, dont ceux que vous avez modifiés.
Si vous n’avez jamais modifié vos modèles de mails, ne copiez pas ce dossier.

files moded
account.html
order_conf.html
order_conf.back.html

OK, only /mails/en, we’ll copy entire /mails/fr folder !

/mails/fr

Note IMPORTANT : move all files and/or dir to *.orig for backup purpose. => no need here, nada before.

done

/img Contient votre logo et toutes les images de votre boutique (catégories, produits, etc.). Prenez surtout soin de copier ces fichiers et dossiers :

files moded or directories to copy

prest.orig.moded => to copy

logo.jpg *le logo de votre boutique*
favicon.ico *le favicon de votre boutique*
logo_stores.gif *le logo de votre boutique pour la carte de l'outil de découverte de magasins*

done

/c *les images de vos catégories*
/p *les photos de vos produits*

Note IMPORTANT : move all files and/or dir to *.orig for backup purpose.
done

prest.not_orig.added => to copy

bdc_background_201001.png
icn_jpg.png
icn_pdf.png
infospratiques_background.png
lcr-rib-700px.jpg
WP_dclpro_infospratiques.jpg
logo_invoice.jpg
logo_mail.jpg

done

prest.not_orig.added => copy later, not sure

prest.orig no moded => NO copy

/cms *les images de vos pages CMS*
/co *les textures de couleur de vos attributs*
/m *les logos de vos marques/fabricants*
/scenes *les image-maps/scènes de vos catégories*
/st *les photos de vos magasins physiques*
/su *les logos de vos fournisseurs*

not-done

…en définitive, copiez tous les dossiers du dossier /img, sauf /img/admin et /img/jquery-ui.

Note IMPORTANT : move all files and/or dir to *.orig for backup purpose.

/modules

Ne copiez que les modules que vous avez ajoutés depuis que vous avez installé PrestaShop la première fois (et qui ne font donc pas partie de l’installation par défaut). Certains de ces modules peuvent ne plus être actuellement activés ou installés : à vous de déterminer s’il peut vous être utile de les avoir sur votre installation mise à jour. Notez également qu’il vous faudra peut-être mettre à jour les modules qui n’ont pas été conçus pour cette nouvelle version.

at the time of writing :

Those needed Search & Replace in 1st shot ovh to zeusdclshopdev

presta.orig moded

/modules/blocktopmenu --> needed for phrase defilement

not presta.orig added

/modules/blockheaderlogos --> note: mods for connection alternative for the cat_online
/modules/blockadhome --> note: I think not needed
/modules/jbxquote --> strange : module "devis"

copy modules not.orig: done

/themes/votreTheme.

Ne copiez que votre propre thème.
Si vous utilisez une version modifiée du thème par défaut, copiez son dossier.

/themes/prestashop_mod

Needs Search&Replace (in Coda)

/themes/prestashop_mod/modules/editorial

will need S&R too (of course -> Hard coded urls)

/download et /upload. Contiennent vos produits téléchargeables, les fichiers attachés, et les produits personnalisables. Si vous n’utilisiez pas ces fonctionnalités, ne copiez pas ces dossiers.

nada

/classes. Dans le cas où vous avez ajouté des classes personnalisées dans ce dossier, copiez-les vers le nouveau dossier /classes.

/config. Ne copiez que le fichier settings.inc.php.

Note IMPORTANT : move all files and/or dir to *.orig for backup purpose

done

edit with settings from the VM

/translations – si vous utilisez une autre langue que celles disponibles par défaut, vous devrez copier le dossier de votre langue dans le dossier /translations de votre nouvelle installation. Sans cela, la mise à jour ne fonctionnera pas.

no translations

Note: move all files and dir to *.orig for backup purpose.

Renamed directory install -> install.done

Step10 : Search and replace on hard coded url in files (themes and modules)

Search and replace with CODA.

Search&Replace 1 on Theme files

Replace http://myshop.pretendco.com with http://shopdev.intra.pretendco.com

/themes/prestashop_mod/authentication.tpl
/themes/prestashop_mod/inscriptionprive.tpl
/themes/prestashop_mod/modules/editorial/archives/editorial_prepa.tpl
/themes/prestashop_mod/modules/editorial/editorial.tpl
/themes/prestashop_mod/newsletter.tpl
/themes/prestashop_mod/page_catalogue.tpl
/themes/prestashop_mod/product-list copy.tpl
/themes/prestashop_mod/product-list.tpl

done : 86 occurences

Search&Replace 2 on Theme files

replace myshop.pretendco.com with shopdev.intra.pretendco.com

/themes/prestashop_mod/header.tpl

done : 3 occurences

Search&Replace 3 on /cat_online files

replace myshop.pretendco.com with shopdev.intra.pretendco.com
done

Search&Replace 4 on /modules

/modules/blockadhome/blockadhome.tpl
/modules/blockheaderlogos/blockheaderlogos.orig.tpl
/modules/blockheaderlogos/blockheaderlogos.tpl
/modules/jbx_quote/new.tpl
Step11 : go to

Front Office

http://shopdev.intra.pretendco.com

Back Office

http://shopdev.intra.pretendco.com/supersecretadmin

ALL GOOD !

OK I have now transfered my online Production prestashop to local directory on my Dev Computer And successfully uploaded it on my VM.

Step12 :
Create a Snapshot on the VM

I here do 3 more things :

Locally
I duplicate the entire “/shopdev” directory for a Backup purpose, let’s say /shopdevready

ON the VM
I duplicate the entire “/shopdev” directory for a Backup purpose, let’s say /shopdevready
I duplicate the shopdev db let’s say shopdevready (phpmyadmin) or dump it on the VM.

So with those duplicates, I now can test Updates from the VM. if anything fails or goes wrong, I erase and duplicate back the directory and the db. even if I do use git.

I now can test the Upgrade from 1.4.4.1 to 1.5.x and 1.4.4.1 to 1.6.0.5
Problem I’m facing : theme and core modules have been hugely hacked and tweaked by predecessors…. SO I need to see how the content will do when upgrading, ths is my main concern. For the theme I’ll start from scratch by cloning the default ps theme.

Since first writing of this post, I’ve done it many times.
to test updates from 1.4.x to 1.5.x, manually then with 1-Clic update module.

I have now duplicated this shopdev more than 10 times on the same VM with success (and some failures).

I now only focus on Updating to 1.6.0.5.

So far I’ve succeeded with 1.6.0.4, 1.6.0.5, and have a mitigate success with late 1.6.0.6.

I’ll make another post specific to the Update itself.

Olivier
About

Product and graphic designer turned to be a Mac SysAdmin.

Posted in Development, Linux, Mac, tips tricks scripts Tagged with: , , , ,
0 comments on “Prestashop | Copy an Online “production” to a “local” VM/Server
1 Pings/Trackbacks for "Prestashop | Copy an Online “production” to a “local” VM/Server"

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>