How to assign the correct permissions to my PrestaShop files and folders?

Published : 10/30/2018 10:28:20
Categories : Tips PrestaShop

How to assign the correct permissions to my PrestaShop files and folders?

The problem

"I have changed my hosting and my Back Office does not let me authenticate", "I can not upload images to my products", "the images of my products do not load correctly in the Front Office", "the update module does not work in 1 -Clic "... These and many others are the first indications that we have an incorrect assignment of the permissions to the files and folders of our online store with PrestaShop. This problem especially appears when we have made a change in the environment where we had running our store, say a migration from local server to productive or simply a change of hosting.

The cause

In order for a web server to resolve the requests made from our clients' web browsers, it needs to read and execute certain files or files, mainly those with the .php extension. The person in charge of executing the content of these files is a process (commonly the Apache web server) that runs in an operating system (often Linux for standard hosting servers) under a user with certain permissions. When the permissions to our files or folders do not allow that process to read and execute them correctly, errors appear on our site that may be HTTP 500 or similar.

The solution

The problem may seem complex but the solution is really simple. With the exception of a few hosting our files need permissions 0644 (reading) and our folders 0755 (reading and execution). The assignment of these permissions must be recursive, that is, that covers all the folders and subfolders of the site.

There are several ways to undertake the allocation of permits recursively. Here's how to do it:

  • Assignment of permissions from an FTP client: we can assign the necessary permissions using any FTP connection client. The task is long because the client will go through each file and folder of our site assigning the indicated permissions. If we are not in a hurry this is the first option. After establishing the connection, we locate the main folder, right click on it, click on "File Permissions" and a configuration window will appear where we must indicate the permissions and apply them recursively.

    Asignacion recursiva de permisos a ficheros con cliente FTP Filezilla

    Asignacion recursiva de permisos a carpetas con cliente FTP Filezilla

  • Assignment of permissions through an SSH connection: this is the fastest way to assign permissions since it allows executing a command directly in the server console which is executed in a few seconds. The bad news is that not all servers have this type of connection active. Commonly only available on VPS and dedicated servers.

    Asignacion recursiva de permisos a ficheros y carpetas desde consola SSH

    Once connected to the server console and positioned in the main route of the store (commonly "public_html") we must execute the commands:

    find . -type f -exec chmod 0644 {} +

    find . -type d -exec chmod 0755 {} +

  • Assignment of permits through cPanel or similar: this is the option that most of us will have access to more easily. The bad thing is that from cPanel we can not assign the permissions recursively, therefore we will have to go one by one for each file (or group of files). Otherwise we will have to ask for technical support from our hosting to see if they can help us.

    Asignacion de permisos a ficheros desde cPanel

    To not complicate life so much, there is a little trick that should normally work and is to assign the permissions only to a small priority group of files and folders. This way we could solve specific problems of operation of our site. Although it might work, this is not the recommended solution. To make the change of permissions we must only select the files and click on the "Permissions" option.

    To eliminate problems with the upload of images or authentication in the Back Office this would be the list of folders and files that should be checked first:

    /admin_folder/
    /admin_folder/ajax.php
    /admin_folder/ajax_products_list.php
    /admin_folder/ajax-tab.php
    /admin_folder/backup.php
    /admin_folder/cron_currency_rates.php
    /admin_folder/displayImage.php
    /admin_folder/drawer.php
    /admin_folder/footer.inc.php
    /admin_folder/functions.php
    /admin_folder/get-file-admin.php
    /admin_folder/grider.php
    /admin_folder/header.inc.php
    /admin_folder/index.php
    /admin_folder/init.php
    /admin_folder/login.php
    /admin_folder/password.php
    /admin_folder/pdf.php
    /admin_folder/searchcron.php
    /admin_folder/filemanager/
    /admin_folder/filemanager/ajax_calls.php
    /admin_folder/filemanager/dialog.php
    /admin_folder/filemanager/execute.php
    /admin_folder/filemanager/force_download.php
    /admin_folder/filemanager/index.php
    /admin_folder/filemanager/upload.php
    /admin_folder/filemanager/uploader/
    /admin_folder/filemanager/uploader/success.php
    /admin_folder/autoupgrade/
    /admin_folder/autoupgrade/ajax-upgradetab.php

    To eliminate problems with the display of the Front Office or the Ajax requests associated with the shopping cart:

    /footer.php
    /header.php
    /images.inc.php
    /index.php
    /init.php

    To eliminate problems with viewing images in the Front Office:

    /img/*.jpg
    /img/*.png
    /img/*.gif

    To eliminate problems with the execution of Ajax calls from a particular module:

    /modules/module_folder/*.php

IMPORTANT: Always remember, permissions 0644 for files and 0755 for folders.

NOTE: there are some folders that additionally need write permissions such as the one of images of our site.

Share this content