Business, PrestaShop, Software Development, Technology, Tutorial

How to Overcome a Prestashop 500 Error on Front End

The Background

I upgraded my ubuntu server last week and after I did so, the Prestashop front end went down – but not the back end! Everything seemed fine because no one was checking the front end so after someone changed something in the back and refreshed the front they thought they had killed the site (and so did I!). However, it just so happened that I had taken a backup (thankfully) and then upgraded the ubuntu server which – apparently – took the PHP version from 7.3 to 7.4 which Prestashop wasn’t ready for…

After turning on debug mode in the PS backend to ‘yes’ in Advanced Parameters / Performance (nice tool by the way…), I started getting a lot of this:

Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /var/www/shop/src/Adapter/EntityMapper.php on line 99

and a lof of this:

(1/1) ContextErrorException

Notice: Trying to access array offset on value of type bool

I did all of the following and it took an entire week:

  • Downgraded php to 7.3 at which point I got this error:

[PrestaShopException]

Link to database cannot be established: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
at line 136 in file classes/db/DbPDO.php

  • Downgraded php to 7.2
  • Downgraded mysql to 5.7 with the help of this blog
  • Reversed all of the above
  • Tried creating a brand new mysql database and importing the old one into it with the help of This blog and this command (adjusted accordingly): sudo mysql -u prestshopusername -p prestashop_db_name < location/to/backup/filename.sql
  • Tried every combination of PHP known to man…
    • Wiped server back to a nearly new state: sudo apt-get full-upgrade with

Take-Away Lesson 1

Know the release dates of PHP and MySQL and your Operating system before going down such a road. This would have helped troubleshoot a little…

Take-Away Lesson 2

Another take-away point for ‘later reading’ is the order of workflow I was doing. When moving stuff around servers it was recommended this order which I will consider moving forward:

  1. Move your files (Prestashop files) to the new location / server / whatever
  2. Create a new MySql database (I never did this…)
  3. Import the backup PS database into the new database
  4. Update the config files.

Take-Away Lesson 3

Prestashop has a killer good upgrade module called 1-click upgrade. This blog explains the upgrade options well.

Solution

Fixing the PHP issue was indeed the fix. So here are the steps to save you the total utter pain I went through:

  1. confirm your php version: php -v
    If it’s 7.4 or higher (and your Prestashop is 1.7 or lower), you’ll need to go back to 7.3 (at least).
  2. Go back to 7.3
  3. Install the packages:
    sudo apt install libapache2-mod-php7.3 php7.3 php7.3-common php7.3-curl php7.3-gd php7.3-imagick php7.3-mbstring php7.3-mysql php7.0-json php7.3-xsl php7.3-intl php7.3-zip php7.3-fpm
  4. Downgrade:
    This is a good downgrading blog but it doesn’t include this option which is worth further investigation as it ‘may’ not require all these commands: sudo update-alternatives --config php So do a bit of further study on this part I would recommend. Plus I would consider using my command for installing it since it has the Prestashop modules:
  5. Disable 7.4 (covered in blog above)
  6. Enable 7.3 (covered in blog above)
  7. Restart apache2 (covered in blog above)
  8. Confirm you are back to 7.3 with php -v
  9. Do a fancy-dancy command extracted from this blog in conjunction with this blog:

ALTER USER '---'@'localhost' IDENTIFIED WITH mysql_native_password BY '---';

I believe (although too busy to confirm…) that the above command actually deals with the new way that mysql 8 deals with password encryption. So if you are on a different version of MySQL this command ‘may’ not be required. I just wanted to write this because this one is not related to php by instead mysql and may require a bit more research in your case…

Of course this command above presumes you magically know what to do (which I didn’t) so what you need to do is login to MySql with your secure login stuff (if applicable) (as root) and then run the command updating to your prestashop stuff. Pay attention to the following two notes/tips:

Note 1: Use the same username here as the one controlling your prestashop database
Note 2: use the same password as the one controlling your prestashop database

10. Refresh your browser to see if you can access your back and front end of Prestashop.

Tip 1: Still having problems reaching your admin page even though you are sure you’re going there? Make sure all the ‘stuff’ after index.php in the URL field are removed and try again

Still not working? Try a control + R or control + F5.

Still not working? Try in a new browser tab.

Hope this helps!

Tagged , , , ,

Leave a Reply

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