Ricerca nel sito web

Come installare Shopware 6 con NGINX e consente di crittografare su CentOS 8


Questo tutorial esiste per queste versioni del sistema operativo

  • CentOS 8
  • CentOS 7.6

Su questa pagina

  1. Prerequisiti
  2. Installa il server LEMP
  3. Configura PHP-FPM
  4. Crea un database per Shopware
  5. Scarica Shopware
  6. Configura Nginx per Shopware
  7. Configura SELinux e Firewall
  8. Accedi all'interfaccia web di Shopware
  9. Shopware sicuro con Lets Encrypt SSL
  10. Conclusione

Shopware è una piattaforma gratuita e open source che ti aiuta ad avviare il tuo sito Web di e-commerce per potenziare il tuo business online. Fornisce molti strumenti utili che ti aiutano a creare e personalizzare un negozio online completamente reattivo. È molto simile a Magento. Rispetto a Magento, Shopware è un'applicazione molto potente, facile da usare e flessibile. Ti aiuta a creare e gestire facilmente contenuti e prodotti da qualsiasi dispositivo con la sua moderna interfaccia utente.

In questo tutorial, ti mostreremo come installare Shopware con Nginx e Lets Encrypt SSL su CentOS 8.

Prerequisiti

  • Un server che esegue CentOS 8.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Una password di root è configurata sul tuo server.

Installa il server LEMP

Shopware funziona su un server Web e si basa su PHP con componenti Symfony e Zend e utilizza MySQL o MariaDB come database back-end. Quindi dovrai installare Nginx, MariaDB, PHP e altre estensioni sul tuo server. Puoi installarli tutti con il seguente comando:

dnf install nginx mariadb-server php php-cli php-intl php-fpm php-common php-mysqli php-curl php-json php-zip php-gd php-xml php-mbstring php-opcache unzip -y

Una volta installati tutti i pacchetti, avviare il servizio Nginx, MariaDB e PHP-FPM e abilitarli all'avvio al riavvio del sistema con il seguente comando:

systemctl start mariadb
systemctl enable mariadb
systemctl start nginx
systemctl start php-fpm
systemctl enable nginx
systemctl enable php-fpm

Una volta terminato, puoi procedere al passaggio successivo.

Configura PHP-FPM

Per impostazione predefinita, PHP-FPM è configurato per essere eseguito come utente e gruppo Apache. Quindi dovrai configurarlo per funzionare come utente e gruppo Nginx. Puoi farlo modificando il file /etc/php-fpm.d/www.conf:

nano /etc/php-fpm.d/www.conf

Modifica le seguenti righe:

user = nginx 
group = nginx 

Salva e chiudi il file, quindi crea una directory di sessione e imposta la proprietà corretta con il seguente comando:

mkdir -p /var/lib/php/session 
chown -R nginx:nginx /var/lib/php/session

Successivamente, modifica il file php.ini e modifica alcune impostazioni consigliate:

nano /etc/php.ini

Modifica le seguenti righe:

memory_limit = 512M
upload_max_filesize = 20M
date.timezone = Asia/Kolkata

Salva e chiudi il file, quindi riavvia il servizio PHP-FPM per applicare le modifiche:

systemctl restart php-fpm

Creare un database per Shopware

Successivamente, dovrai creare un database e un utente per Shopware. Innanzitutto, connettiti a MariaDB usando il seguente comando:

mysql

Una volta connesso, crea un database e un utente con il seguente comando:

MariaDB [(none)]> CREATE DATABASE shopware;
MariaDB [(none)]> GRANT ALL ON shopware.* TO 'shopware' IDENTIFIED BY 'password';

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

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

Una volta terminato, puoi procedere al passaggio successivo.

Scarica Shopware

Successivamente, dovrai scaricare l'ultima versione di Shopware per il suo sito Web ufficiale. Innanzitutto, crea una directory per Shopware all'interno della directory principale di Nginx:

mkdir /var/www/html/shopware

Successivamente, scarica lo Shopware con il seguente comando:

wget https://www.shopware.com/en/Download/redirect/version/sw6/file/install_v6.3.5.0_ba08dbfc07784b5cefe7837f2abbda69dbf5b8b7.zip -O shopware.zip

Una volta completato il download, estrai il file scaricato nella directory shopware:

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

Quindi, imposta l'autorizzazione e la proprietà appropriate con il seguente comando:

chown -R nginx:nginx /var/www/html/shopware
chmod -R 775 /var/www/html/shopware

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx per Shopware

Successivamente, crea un file di configurazione dell'host virtuale Nginx per Shopware con il seguente comando:

nano /etc/nginx/conf.d/shopware.conf

Aggiungi le seguenti righe:

server {
    listen 80;

    # Handle / to index.php
    index index.php;

    # Our server name
    server_name shopware.example.com;

    # Where the code is located
    root /var/www/html/shopware/public;

    # Needed for Shopware install / update
    location /recovery/install {
        index index.php;
        try_files $uri /recovery/install/index.php$is_args$args;
    }

    location /recovery/update/ {
        if (!-e $request_filename){
            rewrite . /recovery/update/index.php last;
        }
    }

    # Forward any not found file to index.php. Also allows to have beautiful urls like /homemade-products/
    location / {
        try_files $uri /index.php$is_args$args;
    }

    # Let php-fpm handle .php files
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi.conf;
        fastcgi_param HTTP_PROXY "";
        fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_read_timeout 300s;
        client_body_buffer_size 128k;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        http2_push_preload on;
    }
}

Salva e chiudi il file, quindi verifica Nginx per eventuali errori di sintassi con il seguente comando:

nginx -t

Dovresti ottenere il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Successivamente, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche verificare lo stato di Nginx usando il comando seguente:

systemctl status nginx

Dovresti ottenere il seguente output:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           ??php-fpm.conf
   Active: active (running) since Tue 2021-02-02 00:40:04 EST; 19s ago
  Process: 76059 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 76057 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 76054 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 76060 (nginx)
    Tasks: 3 (limit: 12523)
   Memory: 5.5M
   CGroup: /system.slice/nginx.service
           ??76060 nginx: master process /usr/sbin/nginx
           ??76061 nginx: worker process
           ??76062 nginx: worker process

Feb 02 00:40:04 centos8 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Feb 02 00:40:04 centos8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 02 00:40:04 centos8 nginx[76057]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 02 00:40:04 centos8 nginx[76057]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 02 00:40:04 centos8 systemd[1]: Started The nginx HTTP and reverse proxy server.

Configura SELinux e Firewall

Per impostazione predefinita, SELinux è abilitato in CentOS 8. Quindi dovrai configurare il contesto SELinux per Shopware. Puoi configurarlo con il seguente comando:

setsebool httpd_can_network_connect on -P
chcon -R -u system_u -t httpd_sys_rw_content_t -r object_r /var/www/html/shopware

Successivamente, consenti la porta 80 e 443 attraverso il firewalld con il seguente comando:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Una volta terminato, puoi procedere al passaggio successivo.

Accedi all'interfaccia web di Shopware

Ora apri il tuo browser web e digita l'URL http://shopware.example.com.

Seleziona la tua lingua e fai clic sul pulsante Avanti. Assicurati che tutti i requisiti siano stati soddisfatti, quindi fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Accetta le CGC e fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Fornisci il tuo database, nome utente, password e fai clic sul pulsante Avvia installazione. Una volta completata l'installazione, dovresti vedere la seguente pagina:

Fare clic sulla pagina successiva. Ti verrà chiesto di fornire il nome del negozio, l'indirizzo e-mail, la valuta, il paese, il nome utente dell'amministratore, la password e fare clic sul pulsante Avanti. Verrai reindirizzato alla dashboard di Shopware:

Fornire tutte le informazioni e fare clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Installa i plug-in della lingua desiderata e fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Installa i dati demo o salta questo e fai clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Fare clic su Configura più tardi. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Salta. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Avanti. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Salta. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Fine. Dovresti vedere la pagina di benvenuto di Shopware:

Shopware sicuro con Lets Encrypt SSL

Successivamente, dovrai installare l'utilità Certbot nel tuo sistema per scaricare e installare Lets Encrypt SSL per il dominio Lets Chat.

Puoi installare il client Certbot con il seguente comando:

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

Successivamente, ottieni e installa un certificato SSL per il tuo dominio let con il seguente comando:

certbot-auto --nginx -d shopware.example.com

Il comando precedente installerà prima tutte le dipendenze richieste sul tuo server. Una volta installato, ti verrà chiesto di fornire un indirizzo e-mail e di accettare i termini di servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
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 shopware.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/shopware.conf

Successivamente, seleziona se reindirizzare o meno il traffico HTTP su HTTPS come mostrato di seguito:

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

Digita 2 e premi Invio per continuare. Al termine dell'installazione, dovresti vedere il seguente output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/shopware.conf

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/shopware.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/shopware.example.com/privkey.pem
   Your cert will expire on 2021-04-2. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Ora puoi accedere a Shopware in modo sicuro utilizzando l'URL https://shopware.example.com.

Conclusione

Congratulazioni! hai installato e configurato correttamente Shopware con Nginx e Lets Encrypt SSL su CentOS 8. Ora puoi facilmente ospitare il tuo negozio online con Shopware. Non esitate a chiedermi se avete domande.