Ricerca nel sito web

Come installare Prestashop con Apache e crittografare SSL su Debian 11


Questo tutorial esiste per queste versioni del sistema operativo

  • Debian 11 (Bullseye)
  • Debian 9 (Stretch)

Su questa pagina

  1. Prerequisiti
  2. Installa Apache, MariaDB e PHP
  3. Crea un database per PrestaShop
  4. Scarica PrestaShop
  5. Configura Apache per PrestaShop
  6. Accedi all'interfaccia utente Web di PrestaShop
  7. Proteggi PrestaShop con Lets Encrypt SSL
  8. Conclusione

PrestaShop è una soluzione di e-commerce gratuita, open-source, efficiente e innovativa che ti aiuta a vendere i tuoi prodotti online. È un CMS di e-commerce potente e adattabile che fornisce tutte le funzionalità necessarie per creare un negozio online. Con PrestaShop puoi gestire l'inventario, i cataloghi dei prodotti, la spedizione, la fatturazione e molto altro. Fornisce oltre 5000 moduli, temi e supporta molti diversi sistemi di gateway di pagamento come PayPal, Google Checkout, ecc.

In questo post, ti mostreremo come installare PrestaShop con il server web Apache e Lets Encrypt SSL su Debian 11.

Prerequisiti

  • Un server che esegue Debian 11.
  • Un nome di dominio valido viene indirizzato all'IP del tuo server.
  • Sul server è configurata una password di root.

Installa Apache, MariaDB e PHP

Innanzitutto, dovrai installare Apache, MariaDB, PHP e altre estensioni PHP sul tuo server. Puoi installarli tutti con il seguente comando:

apt-get install apache2 mariadb-server libapache2-mod-php php php-gd php-mbstring php-mysql php-curl php-xml php-cli php-intl php-zip unzip -y

Una volta installati tutti i pacchetti, modifica il file php.ini e modifica alcune impostazioni:

nano /etc/php/7.4/apache2/php.ini

Modifica le seguenti righe:

memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 32M
date.timezone = UTC

Salva e chiudi il file, quindi riavvia il servizio Apache per applicare le modifiche:

systemctl restart apache2

Crea un database per PrestaShop

Innanzitutto, dovrai proteggere l'installazione di MariaDB e impostare una password di root MariaDB. Puoi farlo eseguendo lo script mysql_secure_installation:

mysql_secure_installation

Rispondi a tutte le domande come mostrato di seguito:

Enter current password for root (enter for none): 
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Successivamente, accedi alla shell MariaDB con il seguente comando:

mysql -u root -p

Fornisci la tua password root MariaDB, quindi crea un utente e un database per PrestaShop utilizzando il seguente comando:

MariaDB [(none)]> CREATE DATABASE prestadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestadb.* TO 'prestauser'@'localhost' IDENTIFIED BY 'yourpass';

Successivamente, scarica i privilegi ed esci da MariaDB con il seguente comando:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Scarica PrestaShop

Successivamente, vai al sito Web di PrestaShop e scarica l'ultima versione di PrestaShop utilizzando il seguente comando:

wget https://download.prestashop.com/download/releases/prestashop_1.7.7.7.zip

Una volta completato il download, decomprimere il file scaricato con il seguente comando:

unzip prestashop_1.7.7.7.zip

Successivamente, decomprimi di nuovo PrestaShop all'interno della directory radice web di Apache utilizzando il seguente comando:

unzip prestashop.zip -d /var/www/html/prestashop

Successivamente, imposta la proprietà e le autorizzazioni appropriate per la directory PrestaShop:

chown -R www-data:www-data /var/www/html/prestashop/ 
chmod -R 755 /var/www/html/prestashop

Una volta terminato, puoi procedere al passaggio successivo.

Configura Apache per PrestaShop

Successivamente, dovrai creare un file di configurazione dell'host virtuale Apache per PrestaShop. Puoi crearlo con il seguente comando:

nano /etc/apache2/sites-available/prestashop.conf

Aggiungi le seguenti righe:

<VirtualHost *:80>
      ServerAdmin 
      ServerName presta.example.com
      DocumentRoot /var/www/html/prestashop


     <Directory /var/www/html/prestashop>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
     CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Salvare e chiudere il file quindi abilitare il modulo di riscrittura Apache e attivare l'host virtuale Apache utilizzando il seguente comando:

a2enmod rewrite
a2ensite prestashop

Infine, riavvia il servizio Apache per applicare le modifiche:

systemctl restart apache2

Puoi anche controllare il servizio Apache con il seguente comando:

systemctl status apache2

Dovresti ottenere il seguente output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-08-27 06:15:23 UTC; 5min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 17540 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 14330 (apache2)
      Tasks: 6 (limit: 2341)
     Memory: 16.5M
        CPU: 332ms
     CGroup: /system.slice/apache2.service
             ??14330 /usr/sbin/apache2 -k start
             ??17544 /usr/sbin/apache2 -k start
             ??17545 /usr/sbin/apache2 -k start
             ??17546 /usr/sbin/apache2 -k start
             ??17547 /usr/sbin/apache2 -k start
             ??17548 /usr/sbin/apache2 -k start

Aug 27 06:15:23 debian11 systemd[1]: Starting The Apache HTTP Server...

Accedi all'interfaccia utente Web di PrestaShop

A questo punto, PrestaShop è installato e configurato. Ora puoi accedervi utilizzando l'URL http://presta.example.com. Dovresti vedere la seguente pagina:

Seleziona la lingua e fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Accetta i termini e le condizioni, quindi fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Fornisci il nome del tuo negozio, i dettagli dell'account amministratore e fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Fornire le impostazioni del database e fare clic sul pulsante Avanti per avviare l'installazione. Una volta completata l'installazione, dovresti vedere la seguente pagina:

Clicca sul pulsante Gestisci il tuo negozio. Dovresti vedere la seguente pagina:

Successivamente, apri il tuo terminale e rimuovi la cartella di installazione:

rm -rf /var/www/html/prestashop/install

Ora accedi all'interfaccia di amministrazione di PrestaShop utilizzando l'URL mostrato nella schermata precedente. Dovresti vedere la schermata di accesso di PrestaShop:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Accedi. Dovresti vedere la dashboard di PrestaShop nella pagina seguente:

Proteggi PrestaShop con Lets Encrypt SSL

Innanzitutto, dovrai installare il client Certbot Lets Encrypt per scaricare e installare il certificato SSL per il tuo dominio.

Puoi installarlo con il seguente comando:

apt-get install python3-certbot-apache -y

Una volta installato, puoi eseguire il seguente comando per installare il certificato Lets Encrypt per il tuo dominio prestashop.example.com.

certbot --apache -d presta.example.com

Durante l'installazione, ti verrà chiesto di fornire il tuo indirizzo email e di accettare i termini di servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for prestashop.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/prestashop-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/prestashop-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/prestashop-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Successivamente, digita 2 e premi Invio per scaricare e installare un certificato SSL gratuito per il tuo dominio. Una volta che l'installazione è stata completata con successo. Dovresti ottenere il seguente output:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/prestashop.conf to ssl vhost in /etc/apache2/sites-available/
prestashop-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://prestashop.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=prestashop.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Conclusione

Nella guida sopra, abbiamo spiegato come installare PrestaShop con Apache e il certificato Lets Encrypt SSL su Debian 11. Ora puoi ospitare facilmente il tuo negozio online con PrestaShop. Non esitate a chiedermi se avete domande.