Shopware 6 installeren met NGINX en Let’s Encrypt op CentOS 8
Shopware is een gratis en open-source platform dat je helpt je eigen e-commerce website te beginnen om je online business te stimuleren. Het biedt een heleboel handige hulpmiddelen die je helpen een volledig responsieve online winkel te bouwen en aan te passen. Het lijkt erg op Magento. Vergeleken met Magento is Shopware een zeer krachtige, gemakkelijk te gebruiken, en flexibele toepassing. Het helpt je met zijn moderne gebruikersinterface om van elk apparaat gemakkelijk inhoud en producten te maken en te beheren.
In deze handleiding laten we je zien hoe je Shopware met Nginx en Let’s Encrypt SSL op CentOS 8 kunt installeren.
Vereisten
- Een server die CentOS 8 draait.
- Een geldige domeinnaam die wijst naar het IP van je server.
- Een root wachtwoord is op je server ingesteld.
Installeer de LEMP server
Shopware draait op een webserver en is gebouwd op PHP met Symfony en Zend componenten, en gebruikt MySQL of MariaDB als database backend. Je zult dus Nginx, MariaDB, PHP en andere uitbreidingen op je server moeten installeren. Je kunt ze allemaal installeren met het volgende commando:
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
Als alle pakketten geïnstalleerd zijn, start je de Nginx, MariaDB en PHP-FPM dienst en schakel je ze in om te starten bij het herstarten van het systeem met het volgende commando:
systemctl start mariadb
systemctl enable mariadb
systemctl start nginx
systemctl start php-fpm
systemctl enable nginx
systemctl enable php-fpm
Als je klaar bent, kun je verder gaan met de volgende stap.
Configureer PHP-FPM
Standaard is PHP-FPM ingesteld om als apache gebruiker en groep te draaien. Je zult het dus moeten configureren om als Nginx gebruiker en groep te draaien. Je kunt dat doen door het bestand /etc/php-fpm.d/www.conf te bewerken:
nano /etc/php-fpm.d/www.conf
Verander de volgende regels:
user = nginx group = nginx
Bewaar en sluit het bestand en maak dan een sessiemap aan en stel het juiste eigendom in met het volgende commando:
mkdir -p /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session
Bewerk vervolgens het php.ini bestand en pas enkele aanbevolen instellingen aan:
nano /etc/php.ini
Verander de volgende regels:
memory_limit = 512M upload_max_filesize = 20M date.timezone = Asia/Kolkata
Bewaar en sluit het bestand en herstart dan de PHP-FPM dienst om de veranderingen toe te passen:
systemctl restart php-fpm
Maak een databank voor Shopware
Vervolgens moet je een database en gebruiker voor Shopware maken. Maak eerst verbinding met de MariaDB met het volgende commando:
mysql
Eenmaal verbonden maak je een database en gebruiker met het volgende commando:
MariaDB [(none)]> CREATE DATABASE shopware;
MariaDB [(none)]> GRANT ALL ON shopware.* TO 'shopware' IDENTIFIED BY 'password';
Spoel vervolgens de privileges en verlaat de MariaDB met het volgende commando:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Als je klaar bent, kun je verder gaan met de volgende stap.
Shopware downloaden
Vervolgens moet je de nieuwste versie van Shopware downloaden van zijn officiële website. Maak eerst een map voor Shopware binnen de Nginx hoofdmap:
mkdir /var/www/html/shopware
Download vervolgens de Shopware met het volgende commando:
wget https://www.shopware.com/en/Download/redirect/version/sw6/file/install_v6.3.5.0_ba08dbfc07784b5cefe7837f2abbda69dbf5b8b7.zip -O shopware.zip
Als de download voltooid is, pak je het gedownloade bestand uit in de shopware map:
unzip shopware.zip -d /var/www/html/shopware
Stel vervolgens de juiste toestemming en eigendom in met het volgende commando:
chown -R nginx:nginx /var/www/html/shopware
chmod -R 775 /var/www/html/shopware
Als je klaar bent, kun je verder gaan met de volgende stap.
Configureer Nginx voor Shopware
Maak vervolgens een Nginx virtuele host configuratiebestand voor Shopware met het volgende commando:
nano /etc/nginx/conf.d/shopware.conf
Voeg de volgende regels toe:
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; } }
Sla het bestand op en sluit het af, controleer Nginx dan op een eventuele syntaxfout met het volgende commando:
nginx -t
Je zou de volgende uitvoer moeten krijgen:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Herstart vervolgens de Nginx dienst om de veranderingen toe te passen:
systemctl restart nginx
Je kunt ook de Nginx status controleren met het onderstaande commando:
systemctl status nginx
Je zou de volgende uitvoer moeten krijgen:
? 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.
Configureer SELinux en Firewall
Standaard is SELinux ingeschakeld in CentOS 8. Je zult dus SELinux context moeten instellen voor Shopware. Je kunt het instellen met het volgende commando:
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
Sta vervolgens poort 80 en 443 toe via de firewalld met het volgende commando:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
Als je klaar bent, kun je verder gaan met de volgende stap.
Toegang tot de Shopware Web Interface
Open nu je web browser en typ de URL http://shopware.example.com.
Kies je taal en klik op de Next knop. Controleer of aan alle eisen voldaan is en klik dan op de Next knop. Je zou de volgende pagina moeten zien:
Ga akkoord met de AV en klik op de Next knop. Je zou de volgende pagina moeten zien:
Geef je database, gebruikersnaam, wachtwoord op en klik op de start installatie knop. Als de installatie voltooid is, zou je de volgende pagina moeten zien:
Klik op de volgende pagina. Je wordt gevraagd je Shop naam, email adres, valuta, land, admin gebruikersnaam, wachtwoord op te geven en klik op de Volgende knop. Je wordt doorgestuurd naar het Shopware dashboard:
Geef alle informatie op en klik op de knop Volgende. Je zou de volgende pagina moeten zien:
Installeer je gewenste taal plugins en klik op de knop Volgende. Je zou de volgende pagina moeten zien:
Installeer demo gegevens of sla dit over en klik op de knop Volgende. Je zou de volgende pagina moeten zien:
Klik op de knop Configureer later. Je zou de volgende pagina moeten zien:
Klik op de knop Overslaan. Je zou de volgende pagina moeten zien:
Klik op de Next knop.Je zou de volgende pagina moeten zien:
Klik op de Skip knop. Je zou de volgende pagina moeten zien:
Klik op de Finish knop. Je zou de Shopware welkomstpagina moeten zien:
Beveilig Shopware met Let’s Encrypt SSL
Vervolgens moet je het Certbot programma op je systeem installeren om Let’s Encrypt SSL voor het Let’s Chat domein te downloaden en te installeren.
Je kunt de Certbot client installeren met het volgende commando:
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
Verkrijg en installeer vervolgens een SSL certificaat voor je lets domein met het volgende commando:
certbot-auto --nginx -d shopware.example.com
Het bovenstaande commando installeert eerst alle vereiste afhankelijkheden op je server. Eenmaal geïnstalleerd wordt je gevraagd een e-mailadres op te geven en de servicevoorwaarden te accepteren, zoals hieronder:
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): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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
Kies vervolgens of je HTTP verkeer al dan niet naar HTTPS wilt omleiden, zoals hieronder:
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
Typ 2 en druk op Enter om verder te gaan. Als de installatie voltooid is, zou je de volgende uitvoer moeten zien:
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
Je kunt Shopware nu veilig benaderen met de URL https://shopware.example.com.
Conclusie
Gefeliciteerd! Je hebt Shopware met succes geïnstalleerd en geconfigureerd met Nginx en Let’s Encrypt SSL op CentOS 8. Je kunt nu gemakkelijk je eigen online winkel hosten met Shopware. Stel me gerust als je vragen hebt.