PrestaShop est une plateforme Web Open Source de e-commerce créee en 2007 par les français Bruno Lévêque et Igor Schlumberger. Elle est sous licence Open Software 3.0 et sa dernière version stable est la 1.7.3.2. D’après Wikipedia, « Elle ne représente pas moins de 50 % des sites Internet de vente en ligne en France« .
Alternatives Open Source à PrestaShop:
Objectif
L’objectif de cet article est l’installation et la configuration d’un serveur LAMP7 (Linux Apache MariaDB PHP7) auto-hébergé PrestaShop en version 1.7.3.2 sur une distribution Linux Debian Stretch 9.4 64bits.
Schéma logique

Pré-requis
1. Pré-requis avant réalisation
- Un serveur Debian Jessie 9.4 64 bits fonctionnel (installation basique avec utilitaires usuels du système et service SSH)
- Packages de base supplémentaires : sudo, resolvconf, tree, dnsutils
- Domaine utilisé : opensharing.priv
2. Configuration réseau initiale
Serveur PrestaShop | |
FQDN | prestashop-test.opensharing.priv |
Adresse IP | 192.168.1.35 |
Réseau | 192.168.1.0/24 |
Passerelle | 192.168.1.1 |
dns-nameservers | 192.168.1.11 192.168.1.12 |
dns-search | opensharing.priv |
Contenu initial du fichier /etc/network/interfaces :
auto lo iface lo inet loopback allow-hotplug enp0s3 iface enp0s3 inet static address 192.168.1.35 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-search opensharing.priv dns-nameservers 192.168.1.11 192.168.1.12
Contenu initial du fichier /etc/hosts :
127.0.0.1 localhost.localdomain localhost 192.168.1.35 prestashop-test.opensharing.priv prestashop-test 192.168.1.35 prestashop.opensharing.priv prestashop
Rmq : L’adresse 127.0.1.1 doit être retirée sur un serveur à IP fixe et remplacée par cette dernière, tel que l’exemple ci-dessus.
Contenu initial du fichier /etc/host.conf :
order hosts, bind multi on
Contenu initial du fichier /etc/resolv.conf :
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 192.168.1.11 nameserver 192.168.1.12 search opensharing.priv
Rmq :
Le fichier /etc/resolv.conf ne doit pas être édité dès lors que le paquet resolvconf a été installé.
Pour prendre en compte les modifications des fichiers de configuration relatifs au réseau, redémarrage du service réseau :
# systemctl restart networking # ifup enp0s3
Optionnel : Création d’un alias global reprenant la commande ifconfig disparue sous Debian Stretch
# nano /etc/bash.bashrc
alias ifconfig='ip addr'
# source /etc/bash.bashrc
Réalisation
1. Installation de Apache
# apt-get install apache2 apache2-doc
Installe les paquets suivants par dépendances :
apache2 | apache2-data | apache2-doc | apache2-utils |
apache2-bin | libapr1 | libaprutil1 | libaprutil1-dbd-sqlite3 |
libaprutil1-ldap | ssl-cert |
2. Installation de MariaDB
# apt-get install mariadb-server mariadb-client
Installe les paquets suivants par dépendances :
galera-3 | gawk | libcgi-fast-perl | libcgi-pm-perl |
libdbd-mysql-perl | libdbi-perl | libfcgi-perl | libhtml-template-perl |
libsigsegv2 | libterm-readkey-perl | mariadb-client | mariadb-client-10.1 |
mariadb-server | mariadb-server-10.1 | psmisc | rsync |
3. Configuration de MariaDB
On peut, pour le moment, se loguer sans mot de passe (la touche entrée sur une chaîne vide suffit). C’est donc la première chose à corriger.
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> quit; Bye
Il faut maintenant définir un mot de passe pour root et corriger quelques paramètres de sécurité par défaut.
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Maintenant connectons-nous avec le mot de passe root système et créons la base de données qui accueillera PrestaShop.
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS prestadb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> CREATE USER prestadmin@localhost IDENTIFIED BY "prestadminpw"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestadb.* TO prestadmin@localhost; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | prestadb | +--------------------+ 4 rows in set (0.00 sec) MariaDB [(none)]> quit; Bye
4. Installation de PHP7 et de ses dépendances
Sous Debian 9 Stretch, PHP 7 est la version par défaut des dépôts de base.
# apt-get install php php-mysql php-curl php-xml php-mcrypt php-gd php-soap php-zip php-intl memcached
Installe les paquets suivants par dépendances :
libapache2-mod-php7.0 | php | php-common | php7.0 |
php7.0-cli | php7.0-common | php7.0-json | php7.0-opcache |
php7.0-readline | php-mysql | php7.0-mysql | libcurl3 |
php-curl | php7.0-curl | php-xml | php7.0-xml |
libmcrypt4 | php-mcrypt | php7.0-mcrypt | php-gd |
php7.0-gd | php-soap | php7.0-soap | php-zip |
php7.0-zip | php-intl | php7.0-intl | memcached |
On peut vérifier les modules PHP installés avec la commande suivante :
# php -m
5. Configuration de PHP
# nano -c /etc/php/7.0/apache2/php.ini
Ligne 389 :
memory_limit = 128M
Ligne 809 :
upload_max_filesize = 16M
Ligne 820 :
allow_url_fopen = On
Configuration du moteur de cache Opcache permettant le stockage en mémoire des scripts PHP précompilés pour un gain de performance :
# nano /etc/php/7.0/mods-available/opcache.ini
Ajouter les lignes suivantes en fin de fichier :
opcache.memory_consumption=512 opcache.revalidate_freq=60 opcache.validate_timestamps=1 opcache.max_accelerated_files=5000
5. Installation de PrestaShop
Télécharger l’archive prestashop_1.7.3.2.zip sur la page officielle.
# wget https://download.prestashop.com/download/releases/prestashop_1.7.3.2.zip # mkdir /var/www/prestashop/ # unzip prestashop_1.7.3.2.zip -d /var/www/prestashop/ # chown -R www-data:www-data /var/www/prestashop
6. Configuration de Apache
# nano /etc/apache2/sites-available/prestashop.conf
<VirtualHost *:80> DocumentRoot /var/www/prestashop/ ServerName prestashop.opensharing.priv <Directory /var/www/prestashop/> Options +FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/prestashop.error.log CustomLog /var/log/apache2/access.log combined </VirtualHost> <VirtualHost *:443> DocumentRoot /var/www/prestashop/ ServerName prestashop.opensharing.priv <Directory /var/www/prestashop/> Options +FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/prestashop.error.log CustomLog /var/log/apache2/access.log combined SSLEngine On SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire SSLCertificateFile /etc/ssl/certs/prestaperso.crt SSLCertificateKeyFile /etc/ssl/private/prestaperso.key </VirtualHost>
Génération de la clef privée :
# openssl genrsa -out /etc/ssl/private/prestaperso.key 1024
Generating RSA private key, 1024 bit long modulus
.................++++++
......++++++
e is 65537 (0x010001)
Demande de certificat à partir de la clef :
# openssl req -new -key /etc/ssl/private/prestaperso.key -out /etc/ssl/certs/prestaperso.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, if you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:FR State or Province Name (full name) [Some-State]:Ile-de-France Locality Name (eg, city) []:Paris Organization Name (eg, company) [Internet Widgits Pty Ltd]:OpenSharing Organizational Unit Name (eg, section) []:Service Informatique Common Name (e.g. server FQDN or YOUR name) []:prestashop.opensharing.priv Email Address []:admin@opensharing.priv Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:prestacertificate An optional company name []:OpenSharing
Construction du certificat :
# openssl x509 -req -days 365 -in /etc/ssl/certs/prestaperso.csr -signkey /etc/ssl/private/prestaperso.key -out /etc/ssl/certs/prestaperso.crt Signature ok subject=C = FR, ST = Ile-de-France, L = Paris, O = OpenSharing, OU = Service Informatique, CN = prestashop.opensharing.priv, emailAddress = admin@opensharing.priv Getting Private key
Activation du site et des modules et vérification de la syntaxe du VirtuaHost :
# a2ensite prestashop # a2dissite 000-default.conf # a2enmod rewrite # a2enmod ssl # apachectl configtest Syntax OK
# systemctl restart mysql apache2 # systemctl status mysql apache2
7. Configuration de PrestaShop par le navigateur Web
Saisir, dans la barre d’adresses, l’adresse suivante :
http://prestashop.opensharing.priv
Chargement du programme d’installation.
Le processus d’installation commence par le choix de la langue, puis Suivant.
On continue avec l’acceptation des licences OSL3.0 et AFL3.0 puis Suivant :
On poursuit avec la vérification de la compatibilité système. Si tous les prérequis sont remplis, continuer avec Suivant :
Les informations relatives à la boutique sont ensuite demandées, puis Suivant :
Puis le test de connexion à la base de données créée précédemment, puis Suivant :
Le processus d’installation de la boutique et le remplissage de la base de données se lance alors :
L’installation est maintenant terminée et, comme suggéré, nous allons supprimer le dossier install pour des raisons de sécurité :
# rm -rf /var/www/prestashop/install/
Supprimons également le dossier docs :
# rm -rf /var/www/prestashop/docs/
Enfin on renomme le dossier admin pour des raisons de sécurité :
# mv /var/www/prestashop/admin/ /var/www/prestashop/12admin34/
On peut maintenant se lancer dans l’administration de la boutique en suivant l’URL suivante :
http://prestashop.opensharing.priv/12admin34/
Il n’y a plus qu’à s’identifier :
Le tableau de bord s’affiche enfin :
La première modification consiste à activer la connexion HTTPS. Pour cela suivre le chemin suivant :
CONFIGURER > Paramètres de la boutique > Paramètres généraux
En regard de Activer le SSL, cliquer sur Veuillez cliquer ici pour vérifier que votre boutique supporte le protocole HTTPS.
Le répondeur OCSP nous signifie que le certificat n’émane pas d’une autorité de certification reconnue, un message d’avertissement est donc émis.
Cliquer sur Avancé puis Ajouter une exception…
Il suffit ensuite de Confirmer l’exception de sécurité.
On se retrouve à nouveau sur la page des paramètres généraux de la boutique. L’option Activer SSL est maintenant activable.
Pour l’option Activer le SSL, cliquer sur OUI puis valider en cliquant sur Enregistrer en bas à droite de la page.
Faire la même chose pour l’option Activer le SSL pour tout le site puis valider en cliquant sur Enregistrer en bas à droite de la page.
Pour aller plus loin
1. Correction de la sécurité et configuration de la connectivité FTP pour l’administration du site
# find /var/www/prestashop/ -type f -print0 | xargs -0 chmod 0660 # find /var/www/prestashop/ -type d -print0 | xargs -0 chmod 0770 # chown www-data:www-data /var/www/prestashop/ # chmod 2770 /var/www/prestashop/
# apt-get install proftpd # adduser prestaftp --home /var/www/prestashop/ # usermod prestaftp -g www-data
# nano -c /etc/proftpd/proftpd.conf
UseIPv6 off ServerName "PrestaShop" DefaultRoot ~ RequireValidShell on Umask 007 007 AuthOrder mod_auth_pam.c* mod_auth_unix.c
# systemctl restart proftpd
2. Effectuer une sauvegarde manuelle complète
# mkdir -p /home/adminsys/backup/1.7.3.2/ # cd /home/adminsys/backup/1.7.3.2/ # tar -czvf backup-prestashop-20180516.tar.gz -C /var/www/ prestashop/ # mysqldump --user=prestadmin --password=prestadminpw --databases prestadb > prestashop-20180516.sql
3. Effectuer une restauration manuelle complète
# cd /home/adminsys/backup/1.7.3.2/ # tar -xzvf backup-prestashop-20180516.tar.gz -C /var/www/ # mysql --user=prestadmin --password=prestadminpw prestadb < prestashop-20180516.sql
Références
- Download PrestaShop
- System Requirements
- PrestaShop 1.7 – What you need to get started
- PrestaShop 1.7 – Procédure d’installation
- Demo en ligne de PrestaShop
- Youtube – Comment installer PrestaShop sur votre serveur – Version 1.7