Advertisements

How To Install OpenCart with Let’s Encrypt SSL on a Linux Server

  • Post last modified:October 21, 2023
  • Post category:Linux / Web
  • Post comments:0 Comments
  • Reading time:12 mins read

OpenCart allows businesses to create and manage online stores. In this post, I will show you how to install OpenCart on a Linux server with PHP 8.2 , securing MySQL, and adding a Let’s Encrypt SSL certificate for a secure online store setup.

Table of Contents:

Make sure you have the following:

  • A Linux Server (Ubuntu 20.04 recommended)
  • SSH access to your Server as a root user or a user with sudo privileges
  • A domain name pointed to your Server IP address

Step 1: Log in to Linux Server

Update system’s package:

sudo apt update

Upgrade the existing packages:

sudo apt upgrade

Step 2: Install LAMP Stack with PHP 8.2

follow these steps to install the LAMP (Linux, Apache, MySQL, PHP) stack with PHP 8.2

Advertisements

Install Apache:

sudo apt install apache2

Install MySQL:

sudo apt install mysql-server

You will be prompted to set a root password for your MySQL database during the installation. Make sure to choose a strong password and remember it (if you’re at the root of your Linux Server not getting any prompt to set a password).

(this step is only for root users)Change the password for the ‘root’ user using the ALTER USER command for the ‘mysql_native_password’ plugin:

sudo mysql

If prompted to enter the password for the ‘root’ user. simply hit enter.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
EXIT;

Replace ‘new_password’ with the password you want to set for the ‘root’ user.

Run the MySQL secure installation script:

sudo mysql_secure_installation

Configure the following settings:

  • Enter the MySQL root password you set during installation.
  • Set a new root password? Choose “N” if you want to keep the existing password.
  • Remove anonymous users? Choose “Y” to remove anonymous users.
  • Disallow root login remotely? Choose “Y” to prevent remote root login.
  • Remove test database and access to it? Choose “Y” to remove the test database and access to it.
  • Reload privilege tables now? Choose “Y” to apply the changes immediately.

Create a new MySQL database and user for OpenCart:

mysql -u root -p
CREATE DATABASE opencart;
CREATE USER 'opencartuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON opencart.* TO 'opencartuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

replace your_password with a strong password, this is the password setting into the open cart database.

Install the required packages for adding the PHP repository:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Update the package list again:

sudo apt update

Install PHP 8.2 and required extensions:

sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mysql php8.2-curl php8.2-gd php8.2-zip php8.2-intl php8.2-mbstring php8.2-xml

Step 3: Install Let’s Encrypt SSL Certificate

Install Certbot, a Let’s Encrypt client:

sudo apt install certbot python3-certbot-apache

Generate the SSL certificate for your domain:

sudo certbot --apache -d your_domain.com

replace “your_domain.com” with your actual domain name.

selecting https option
select 2 to redirect HTTPS

Step 4: Download and Configure OpenCart

Navigate to the Apache web directory to install OpenCart.:

cd /var/www/html

Download OpenCart:

wget https://github.com/opencart/opencart/releases/download/4.0.2.1/opencart-4.0.2.1.zip

Note: to find the new release of the open cart go https://github.com/opencart/opencart/releases/ and replace the version number with the new release.

Unzip the downloaded file:

apt install unzip
unzip opencart-4.0.2.1.zip

Move open cart web files:

mv /var/www/html/opencart-4.0.2.1/upload/* /var/www/html

Remove unnecessary files:

rm -r opencart-4.0.2.1 index.html opencart-4.0.2.1.zip

Advertisements

Set the correct file permissions:

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/

Rename Config files:

sudo mv /var/www/html/config-dist.php /var/www/html/config.php
sudo mv /var/www/html/admin/config-dist.php /var/www/html/admin/config.php

Configure OpenCart:

  • Open a web browser and navigate to the domain name with https:// .
  • You will see the OpenCart installation wizard.
  • Follow instructions, providing the information such as database details and administrator credentials.
opencart install
checking opencart server requirement
adding database details
opencart installed
Log in to your admin dashboard after installing opencart
removing install directory
click delete
moving storage directory
click the move button to move the storage directory
opencart  admin dashboard
admin dashboard
opencart store
store

Conclusion

You have successfully installed OpenCart on your Linux server with PHP 8.2 , secured MySQL, and added a Let’s Encrypt SSL certificate to your online store. If you have any issues please leave a comment.

Leave a Reply