Category Archives: Prestashop

Prestashop permanentLinks block problem when doing profiling

Sometime when we are trying out new things on the shop all of a sudden the testpage just stops working and refers to an error with the permanent links block.

Up until now I have not been able to understand why. If we look at the page source it is referring to a cms-link that is missing pointing to the smarty cache.

Up until today the only solution has been to restore the last update of the shop. Today however I tried to turn off profiling and then the shop was working again. When turning profiling on again the page still loads ok so it seems are dosing a profiling restart might solve the problem. Keeping this post as a mental note in case it happens again.

Clone_Troopers_Phase_I

Clone Prestashop

Have you ever thought that, “I will just test this module quickly” or “I will just modify this stylesheet” and you end up with more work or more problems than expected.

The proper way is to setup a clone (an exact copy) of your original shop and test the changes first. Once you know that it is working, do the same thing in the live installation.

Step 1: Create a subdomain for your test shop

In my opinion the best way to setup the testshop is to use a separate subdomain (or even a totally different domain. If your hosting provider does not allow you to create more subdomains you will have to put the test site in a normal subfolder on your server.

Creating a subdomain is simple. After logging into Plesk just go to the Websites & Domains and at the bottom of the page you will find these options:
add subdomain in plesk
Select “Add new subdomain” and enter the name of the new subdomain and the folder on the server where you want to put the test site. In our case we call it “perf” which means the testsite will be available in perf.givensa.com. Normally you want to name the subdomain and the folder the same.

Step 2: Copy the files we need for the prestashop clone

We will work through Plesk in this guide since it is much faster than downloading the full shop over ftp just to upload it again.

In the same Website & Domains, click on File Manager:
plesk file manager

and if your Prestashop is installed in the default httpdocs folder, click on that folder and you will see a long list of the Prestashop files.
plesk-prestashop-file-list

Important: Now we must select all files. Find the word “All” to the right on top of the file list and click it.
prestashop-files

Now all files are shown on one page. Select the checkbox to the left in the file manager header:
plesk-filemanager-select-all

Now all files and folders are selected and the file list looks like this:
plesk-prestashop-filemanager-select-all

Click the Copy/Move button:
plesk-copy-move-files

and you are taken to a confirmation screen where you need to also enter the destination directory.
Important: If you are using a subdomain, remember to remove the /httpdocs/ and just enter the folder name like in our example:
plesk-prestashop-copy-files

and when it has completed you will return to the FileManager with a success message.
plesk-file-copy-done

And we are done with the transfer of the Prestashop files.

Step 3: Create a new database for our Prestashop clone

Go back to Websites & Domains and click on the Databases icon.
Choose “Add new database”
plesk-add-new-database

In the next screen just give the database a proper name. We have chosen “perf” to match the name of the subdomain.
plesk-new-db-name

Step 4: Create a user for the database

Now just click on the “add new database user” icon.
plesk-db-add-user

Choose a name and password for the database user. You can pick anything. For simplicity we have chosen givensa_perf to have a prefix “givensa” and a connection to the test site “perf” so we do not risk mixing it up with other databases.
plese-add-dabase-user-set-name

Step 5: Importing the original database

Before importing anything, we would have to export the original database. How to export a database is already explained in How create a Prestashop database backup. Please refer to that article and then come back here for the next step when you are done.

Now ensure that you are back at the page with your newly created database (in our case the one called perf). Then click “Webadmin”
plesk-database-webadmin

and you will enter the phpMyAdmin tool which allows us to import an existing database. In the menu there are not so many options at this time. Simply click “Import”
myphpadmin-import-db

Click choose-file

and choose the database you just Exported. Click “Continue” and wait for a while for the database to be imported.

Wow thats awesome, now we have the files copied and we have a database uploaded. However the database contains some info from the live site that we need to change.

Step 6: Modifying the database to work with the Prestashop copy

One the left side find the table called ps_configuration prestshop-config

and click on it.

Change the Number of Rows field to show 3000 instead of 30 and press Enter so we can easily search the whole database.
filas

Search on the page for the field called PS_SHOP_DOMAIN and when you find it, below you also see PS_SHOP_DOMAIN_SSL. Change both of them to the new url of the test site. In our example we will insert perf in front of the givensa.com domain name.
change-ps-shop-domain

If your prestashop version is 1.5 or higher. You also need to find the table called ps_shop_url and make the same changes so it looks something like this:
ps_shop_url

Step 7: Updating our database settings to match the new database

Now when we have the database imported, we must tell Prestashop which database to use. In the copy we made previously Prestashop still wants to look at the original database and this is definetely not what we want.

So, go back to Websites & Domains and click again on the File Manager. Go inside the folder of our new testsite (in our case it is /perf/) and click on the config folder and locate the file settings.inc.php and click on the pen icon to edit the file.
prestashop-db-config

Change the fields DB_USER and DB_PASSWD to match the credentials we set earlier. In our case we entered givensa_perf for both. If you old settings does not say:
define(‘_DB_SERVER_’, ‘localhost’);
you will have to enter the name of the new database in that field (in our case it would be “perf”).

Now Prestashop will be able to use the correct database.

Step 8: Updating our .htaccess file

In order for things to work we must regenerate the .htaccess. This we do from the Prestashop admin interface so go to http://yoursite.com/admin and under the Preferences tab select SEO & URLs.prestashop_perf_tab

In order to make Prestashop rewrite the .htaccess file, all you have to do is click the Save button.
prestashop-seo-save

Fantastic, if you now go to your test site (in our case it is perf.givensa.com) you should see it working.

Congratulations, you have created an identical copy of your prestashop site. In order to finish up nicely, we would not like for Google to index this site so we add a robots.txt that blocks all search engines from browsing our test installation.

Add blocking robots.txt for the Prestashop test site

Go back to the File Manager in Websites & Domains and find robots.txt in your test site folder. Click on the pen to edit it. Delete all info in the file and add these lines:
User-agent: *
Disallow: /

Now search engines will not crawl your test site.

Finishing up

Now everything should be in order and you are ready to start hacking around in your test installation. I hope you find the tutorial useful and if you have any comments or found errors or things that could be more clear, do not hesitate to let me know by posting a comment below.

backup

How create a Prestashop database backup

Background

Sometimes when making changes in Prestashop I feel that we loose control. You unhook one module and the whole site explodes (or maybe implodes) and it might be hard to understand what happened.

In these scenarios as always the recommendation is to backup the site and the database. However if you are on a standard ftp connection with your hosting provider, downloading the whole shop might take a very long time.

If you are just testing new modules or trying to remove some Prestashop modules to make your site faster, then it might be enough just to make a backup of the database. This way if things go bad, you can just restore this backup and you are back where you started with a working shop.

In this example we will show how to make a backup using Plesk. The good thing with this approach is that it is generic so it applies for any mySQL database, Prestashop, WordPress etc and since we normally do a lot of things like copying files and editing configs through Plesk rather than through ftp it is starting to feel like a familiar environment.

Getting started

Start by logging into Plesk with your username and password provided by your hosting company. You will see a screen of the

Finding the database to backup

If you click on the tab called “Websites and Domains” and then on “Databases” you will get into the Plesk database page. plesk-databases
Find the database that is attached to your Prestashop installation.

Click on the webadmin button

prestashop database for backup

Database for backup


and you will get into the phpMyAdmin tool.
phpMyAdmin prestashop
Where you will see a huge table of database info. You can just ignore all that.

Exporting the database

Now just click the Export button:
myPhpAdmin-export-database
and click Continue.

Now a download of your database will start automatically and you are done.

As long as you only modify things from the Prestashop admin, if anything goes wrong it can usually be restored by simply Importing this Prestashop database again. How to Import a Prestashop database backup is explained in this blogpost.