How to Install and Configure OpenCart on VPS for E-commerce

OpenCart is a popular, open-source shopping cart solution designed for online merchants to create and manage their e-commerce websites. It provides a flexible and easy-to-use platform that can be customized and extended with various themes and extensions. In this guide, we will walk you through the process of installing and configuring OpenCart on a Virtual Private Server (VPS).


Prerequisites

Before starting the installation, make sure your VPS has the following requirements:

  • A VPS running a supported operating system (Ubuntu 20.04 or later, CentOS, etc.).
  • Root or sudo privileges to execute system commands.
  • A domain name (optional but recommended for a professional e-commerce site).
  • At least 2 GB of RAM and 1 CPU core (recommended for a smooth experience).
  • PHP 7.3 or later, MySQL, and Apache/Nginx for web server.
  • Access to the internet for downloading required packages.

Step 1: Update Your VPS

Start by ensuring that your VPS is fully updated:

 
sudo apt update && sudo apt upgrade -y

This ensures that all system packages are up to date and secure.


Step 2: Install Apache, PHP, and MySQL

OpenCart requires a web server (Apache or Nginx), PHP, and a database server (MySQL or MariaDB). Let's install Apache, PHP, and MySQL.

Install Apache Web Server:

Apache is the most commonly used web server for OpenCart. To install it:

 
sudo apt install apache2 -y

Install PHP and Required Extensions:

OpenCart requires PHP and a set of PHP extensions. Install PHP 7.3 (or newer) along with necessary extensions:

 
sudo apt install php php-mbstring php-xml php-mysql php-gd php-curl php-zip php-bz2 php-json php-xmlrpc -y

Install MySQL Database Server:

Now, install MySQL to create the database for OpenCart:

 
sudo apt install mysql-server -y

After installation, secure MySQL by running the following command:

 
sudo mysql_secure_installation

Follow the prompts to set a root password and remove insecure default settings.


Step 3: Create a Database for OpenCart

Next, create a database and user for OpenCart.

  1. Log in to MySQL:

     
    sudo mysql -u root -p
  2. Create the OpenCart database:

    sql
     
    CREATE DATABASE opencart;
  3. Create a MySQL user for OpenCart:

    sql
     
    CREATE USER 'opencartuser'@'localhost' IDENTIFIED BY 'strongpassword';
  4. Grant privileges to the OpenCart user:

    sql
     
    GRANT ALL PRIVILEGES ON opencart.* TO 'opencartuser'@'localhost';
  5. Flush privileges and exit:

    sql
     
    FLUSH PRIVILEGES; EXIT;

Step 4: Download and Install OpenCart

Now, let's download the latest version of OpenCart and install it on your VPS.

  1. Navigate to your web root directory:

     
    cd /var/www/html
  2. Download OpenCart:

    Visit the OpenCart download page to get the latest stable release. You can use wget to download the package directly:

     
    sudo wget https://github.com/opencart/opencart/releases/download/3.0.3.8/opencart-3.0.3.8.zip
  3. Install unzip if not already installed:

     
    sudo apt install unzip -y
  4. Extract the downloaded OpenCart archive:

     
    sudo unzip opencart-3.0.3.8.zip
  5. Set the correct permissions for the OpenCart files:

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

Step 5: Configure Apache for OpenCart

Now, you need to configure Apache to serve OpenCart properly.

  1. Create a new Apache configuration file for OpenCart:

     
    sudo nano /etc/apache2/sites-available/opencart.conf
  2. Add the following configuration to the file:

    apache
     
    <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/opencart ServerName yourdomain.com <Directory /var/www/html/opencart> AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
  3. Enable the new site and mod_rewrite module:

     
    sudo a2ensite opencart.conf sudo a2enmod rewrite sudo systemctl restart apache2

Step 6: Complete the OpenCart Installation via the Web Interface

  1. Access OpenCart in your web browser:

    Open a browser and navigate to your server’s IP address or domain name:

     
    http://yourdomain.com

    If you’ve set everything up correctly, you will see the OpenCart installation page.

  2. Choose your language and click Continue.

  3. Database Configuration: On the next screen, input the following database details:

    • Database Type: MySQLi
    • Host: localhost
    • Username: opencartuser
    • Password: strongpassword
    • Database Name: opencart

    Click Continue.

  4. Admin Account Setup: You will be prompted to set up the OpenCart admin account, including:

    • Admin username
    • Admin password
    • Admin email

    Make sure to save this information for later use.

  5. Complete the installation: Once all details are correctly entered, click Finish.


Step 7: Secure Your OpenCart Installation

  1. Remove the installation directory for security reasons:

     
    sudo rm -rf /var/www/html/opencart/install
  2. Set appropriate permissions for the configuration files:

     
    sudo chown -R www-data:www-data /var/www/html/opencart/config.php sudo chown -R www-data:www-data /var/www/html/opencart/admin/config.php
  3. Set up SSL (HTTPS) for secure browsing (optional but recommended). If you’re using Let’s Encrypt, use the following commands to install the SSL certificate:

     
    sudo apt install certbot python3-certbot-apache -y sudo certbot --apache

    This will automatically configure your Apache server with a free SSL certificate from Let’s Encrypt.


Step 8: Access and Configure Your OpenCart Store

Once the installation is complete, you can log in to the OpenCart admin panel:

  1. Admin Panel URL:

     
    http://yourdomain.com/admin

    Use the admin username and password you set during the installation to log in.

  2. Configure your store:

    • Add products: Go to the Catalog section and start adding products to your store.
    • Set up payment gateways: Under the Extensions tab, configure your preferred payment methods (PayPal, Stripe, etc.).
    • Configure shipping options: Set up your shipping methods, including flat rate, weight-based, or free shipping.
    • Install themes and extensions: Browse the OpenCart Extension Store to install custom themes and plugins for added functionality.

Conclusion

You’ve successfully installed and configured OpenCart on your VPS for running an e-commerce website. OpenCart offers a powerful and flexible platform for building online stores, and with its large community and extensions, you can customize it to suit your business needs.

Remember to regularly back up your data, ensure your website is secured with HTTPS, and monitor server performance to provide a smooth shopping experience for your customers.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution