Home / How To / How to install OpenCart with Nginx and let's encrypt on Debian 10

How to install OpenCart with Nginx and let's encrypt on Debian 10



Opencart is a popular open source solution that helps you host your own fully functional e-commerce site. Opencart provides a simple and user-friendly interface to sell your products online, such as Amazon and Flipcart. It is specifically designed for SMEs and has all the standard e-commerce features needed for online stores. It offers a rich set of features including multiple currencies, languages, unlimited categories, products, product reviews, multiple stores and many more.

In this tutorial, we will show you how to install OpenCart with Nginx on Debian 10 and secure it with Let & # 39; s Encrypt SSL.

Prerequisites

  • A server running Debian 10.
  • A root password is configured on your server.

Getting Started

First, update your system to the latest version with the following command:

  apt-get update -y 
apt-get upgrade -y

After your server is updated, restart it to apply the changes.

Installing LEMP Server

First install Nginx web server, MariaDB database server, PHP and other necessary PHP extensions by running the following command:

  apt-get install nginx mariadb server php-common php-cli php-fpm php-opcache php-gd php-mysql php-curl php-intl php-xsl php-mbstring php-zip php-bcmath php-soap unzip git-y 

Once all e-packages are installed, edit php.ini- file and make some changes:

  nano /etc/php/7.3/fpm/php.ini tu 1919900900 change the following lines: 

  memory_limit = 256M
upload_max_filesize = 100M
opcache.save_comments = 1
max_execution_time = 300
date.timezone = Asia / Kolkata

Save and close the file when you are done.

Configure the MariaDB database

Next, you must set a MariaDB root password since it is not set in Debian 10.

To do so, log in to the MariaDB shell with the following command:

  mysql 

When logged in, set a MariaDB root password with the following command:

  MariaDB [(none)]> SET PASSWORD FOR & # 39; root & # 39; @ & # 39; localhost & # 39; = PASSWORD ("yournewrootpassword"); 

Then set MariaDB authentication plugin to mysql_native_password with the following command:

  MariaDB [(none)]> SET GLOBAL innodb_fast_shutdown = 0; 
MariaDB [(none)]> UPDATE mysql.user SET plugin = & # 39; mysql_native_password & # 39; WHERE User = & # 39; root & # 39 ;;

Then flush the privileges and exit from the MariaDB shell with the following command:

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

Next, log in to MariaDB with root users: [19659008] mysql -u root -p

Enter your root password and create a database and user for OpenCart with the following command:

  MariaDB [(none)]> CREATE DATABASE opencartdb; 
MariaDB [(none)]> GIVE ALL ON opencartdb. * ON & # 39; opencart & # 39; @ & # 39; localhost & # 39; IDENTIFIED OF & # 39; password & # 39 ;;

Then flush the privileges and exit from the MariaDB shell with the following command: [19659008] MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once MariaDB is configured, you can proceed to the next step.

Download OpenCart

You can download the latest version of OpenCart from the Git layer with the following command:

  wget https://github.com/opencart/opencart/releases/download/3.0.3.2/ opencart-3.0.3.2.zipebrit19659009vardAfter downloading OpenCart, unzip the downloaded file with the following command: 

  unzip opencart-3.0.3.2.zip 

Next, move the upload directory to Ngin x web directory using the following command: [19659037

  etc. upload / var / www / html / opencart 

Next, change the directory to open the map and rename the config-dist. php file:

  cd / var / www / html / opencart / 
mv config-dist.php config.php
mv admin / config-dist.php admin / config.php

Then authorized permissions for the opencart directory with the following command:

  chown -R www-data: www-data / var / www / html / opencart / 
chmod -R 775 / var / www / html / opencart /

When you're done, you can move on to the next step.

Configuring Nginx for OpenCart

Next, you must create an Nginx virtual host configuration file to serve OpenCart. You can create it with the following command:

  nano /etc/nginx/sites-available/opencart.confospel19659009vardAdd the following content:   Ads     

  server {
listen 80;
server name opencart.linuxbuz.com;
root / var / www / html / opencart;
index index.php;
access_log /var/log/nginx/opencart_access.log;
error_log /var/log/nginx/opencart_error.log;

location = /favicon.ico {
log_not_found off;
access_log av;
}

location = /robots.txt {
Allow everyone;
log_not_found off;
access_log av;
}

location / {
try_files $ uri $ uri //index.php?$args;
}

location ~  .php $ {
include excerpt / fastcgi-php.conf;
fastcgi_pass unix: /run/php/php7.3-fpm.sock;
}

location ~ * . (js | css | png | jpg | jpeg | gif | ico | svg) $ {
expires max;
log_not_found off;
}

}

Save and close the file and then check Nginx for syntax errors with the following command:

  nginx -t 

You should get the following output:

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

Then enable the virtual Nginx host file with the following command:

  ln -s /etc/nginx/sites-available/opencart.conf / etc / nginx / sites-enabled / 

Then restart Nginx and PHP-FPM service to apply the changes:

  systemctl restart nginx 
systemctl restart php7.3-fpm

When you are finished, you can proceed to the next step.

Secure OpenCart with Let's # Encrypt SSL

Then you must install a Certbot client to install and configure Let's Encrypt for your site.

By default, Certbot is not available in the Debian 10 repository. So you need to add a Certbot archive to your system.

You can add it with the following command:

  echo "deb http://ftp.debian.org/debian buster-backports main" >> / etc / apt / sources.list 

Then update the repository and install the Certbot client for Nginx with the following command:

  apt-get update -y 
apt-get install python3-certbot-nginx -t buster-backports

Once installed, run the following command to Download Let & # 39; s Encrypt SSL and configure Nginx to use this SSL: Advertising

[19659008] certbot --nginx -d opencart.linuxbuz.com

You will be asked to accept the terms of service and specify your valid email address shown below:

  Saves debug log to / var / log / letsencrypt / letsencrypt .log
Selected plugins: Authenticator apache, Install apache
Enter Email Address (Used for Emergency Renewal and Security Messages) (Enter & # 39; c & # 39; to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Read the terms of use at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree to register on the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A) gree / (C) ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Should you be willing to share your email address with Electronic Frontier
Foundation, a founding partner of Let & # 39; s Encrypt project and the nonprofit
organization developing Certbot? We want to send an e-mail about our work
web encryption, EFF news, campaigns and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y) es / (N) o: Y
Get a new certificate
Perform the following challenges:
http-01 challenge for opencart.linuxbuz.com
Waiting for verification ...
Cleaning of challenges
Created an SSL vhost at /etc/nginx/sites-available/opencart-le-ssl.conf
Activated module Apache socache_shmcb
Enabled Apache ssl module
Distribute certificates to VirtualHost /etc/nginx/sites-available/opencart-le-ssl.conf
Activate available site: /etc/nginx/sites-available/opencart-le-ssl.conf

Choose whether to redirect HTTP traffic to HTTPS or remove HTTP access.

Then you must choose whether to redirect HTTP traffic to HTTPS as shown below:

  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No Redirect - Do not make any further changes to the web server configuration.
2: Redirect - Makes all requests redirect to secure HTTPS access. Select this for
new websites, or if you are sure your site is working on HTTPS. You can undo this
change by editing your web server configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] and then [enter] (press & # 39; c & # 39; to cancel): 2

Type 2 and hit Enter to continue. When the installation is complete, you should get the following output:

  Redirecting vhost in /etc/nginx/sites-enabled/opencart.conf to ssl vhost in / etc / nginx / sites-available / opencart-le-ssl .conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have enabled https://opencart.linuxbuz.com

You should test your configuration on:
https://www.ssllabs.com/ssltest/analyze.html?d=opencart.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved to:
/etc/letsencrypt/live/opencart.linuxbuz.com/fullchain.pem
Your key file has been saved to:
/etc/letsencrypt/live/opencart.linuxbuz.com/privkey.pem
Your certificate expires on 2020-04-30. To get a new or fine tuned
version of this certificate in the future, simply run certbot again
with the "certonly" option. Not to interactively renew * everything * off
your certificates, run "certbot renew"
- Your account details have been saved in your Certbot
configuration directory on / etc / letsencrypt. You should do one
secure backup of this folder now. This configuration directory is coming
also contains certificates and private keys obtained by Certbot
making regular backups of this folder is ideal.
- If you like Certbot, you can consider supporting our work by:

Donate to ISRG / Let & # 39; s Encrypt: https://letsencrypt.org/donate
Donate to EFF: https://eff.org/donate-le

At this point, OpenCart is secured by Let & # 39; s Encrypt SSL.

Access OpenCart Web Interface

Now open your browser and type the URL https://opencart.linuxbuz.com . You will be redirected to the OpenCart License Agreement page:

 OpenCart License / GPL

Click the Continue button to accept the license agreement. You should see the following page:

 Pre-install check

 Additional checks

Make sure all necessary PHP extensions are installed and then click CONTINUE button. You should see the following page:

 Database configuration

Enter your database details, admin username, password and click CONTINUE - button. When the installation is complete, see the following page:

 OpenCart installation completed

Now open your terminal and remove the installation directory with the following command:

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

Then click GO TO YOUR ONLINE SHOP . You should see your OpenCart store on the following page:

 OpenCart store frontend

Then click the LOG IN TO YOUR ADMINISTRATION button. You should see the OpenCart login page:

 OpenCart admin login

Enter your admin username, password and click the Login button. You should see your OpenCart administration panel on the following page:

 OpenCart dashboard

Conclusion

Congratulations! you have installed and secured OpenCart on Debian 10. You can now host your own shopping cart online with OpenCart. Feel free to ask me if you have any questions.


Source link