Website Vidya
Linux & ServersStep-by-Step Guide

How to Install OpenCart on Ubuntu 24.04

Learn how to install OpenCart on Ubuntu 24.04 LTS with Apache, MariaDB, PHP 8.x, and Let's Encrypt SSL. Complete eCommerce store deployment tutorial.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install OpenCart on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Learn how to install OpenCart on Ubuntu 24.04 LTS with Apache, MariaDB, PHP 8.x, and Let's Encrypt SSL. Complete eCommerce store deployment tutorial.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Updating System Repositories and Installing Apache and MariaDB
  • Step 2: Installing PHP and Required OpenCart Extensions
Grounded in full engineering runbookWebsiteVidya AI Engine

OpenCart is a lightweight, turn-key open-source eCommerce platform engineered for merchants and digital entrepreneurs who require a complete online store management system without the heavy hardware overhead of platforms like Magento. Featuring a responsive administrative dashboard, built-in multi-store functionality, granular product options, integrated shipping modules, and support for over thirty payment gateways out of the box, OpenCart powers hundreds of thousands of active online stores worldwide.

Unlike hosted SaaS store builders that charge monthly platform fees and transaction commissions, hosting OpenCart on your own Ubuntu Linux server guarantees 100% data ownership, custom database tuning, and full control over your customer checkout experience. Learning how to install opencart on ubuntu 24.04 gives you a modern digital storefront built on a fast, production-hardened LAMP stack.

In this step-by-step tutorial, we demonstrate how to install OpenCart on Ubuntu 24.04 LTS (Noble Numbat). We cover installing Apache, MariaDB, and required PHP extensions, provisioning a dedicated database, extracting OpenCart source files into /var/www/opencart, configuring configuration files, enabling Apache Virtual Hosts with URL rewrites, and securing your store with Let's Encrypt SSL.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A virtual private server (VPS) or cloud instance running Ubuntu 24.04 LTS.
  • A non-root user account configured with sudo administrative privileges.
  • A registered domain name (e.g., store.example.com) pointed to your server's public IP address.
  • At least 2 GB of RAM (4 GB recommended for busy online storefronts and caching).

Step 1: Updating System Repositories and Installing Apache and MariaDB

OpenCart operates on the classic LAMP stack architecture. First, update your local APT repository index and install the Apache HTTP web server and MariaDB relational database engine.

Run the following command to update package lists and install apache2, mariadb-server, and essential file extraction utilities using APT.

Advertisement

Verify that both services start successfully and are configured to launch automatically at system boot.

# Refresh package index and upgrade packages
sudo apt update && sudo apt upgrade -y

# Install Apache web server and MariaDB database server
sudo apt install -y apache2 mariadb-server mariadb-client curl wget unzip

# Enable and verify services
sudo systemctl enable --now apache2 mariadb
sudo systemctl status apache2 mariadb --no-pager

Step 2: Installing PHP and Required OpenCart Extensions

OpenCart requires PHP along with specialized modules for image resizing, encryption, cURL requests, ZIP archive processing, and database communication.

Install PHP and the required extensions: libapache2-mod-php, php-mysql, php-curl, php-gd, php-intl, php-mbstring, php-xml, and php-zip.

Tune your PHP configuration in /etc/php/8.3/apache2/php.ini (or your active PHP version): ensure file_uploads = On, set upload_max_filesize = 32M, post_max_size = 32M, and set memory_limit = 256M.

Advertisement

Restart Apache to load the new PHP runtime configuration.

# Install PHP and necessary extensions
sudo apt install -y php libapache2-mod-php php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip

# Restart Apache
sudo systemctl restart apache2

Step 3: Creating the OpenCart Database and Dedicated User

OpenCart stores your product catalog, customer records, order histories, and store settings in a relational database.

Log into the MariaDB shell as the administrative root user.

Create a database named opencart_db with utf8mb4 encoding, create an unprivileged user opencart_user, grant full privileges on the database, and flush privileges.

Replace StrongOpenCartPass123! with a strong, randomized password.

-- Access MariaDB root prompt
sudo mariadb

-- Create OpenCart database with utf8mb4 encoding
CREATE DATABASE opencart_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create dedicated user
CREATE USER 'opencart_user'@'localhost' IDENTIFIED BY 'StrongOpenCartPass123!';

-- Grant database privileges
GRANT ALL PRIVILEGES ON opencart_db.* TO 'opencart_user'@'localhost';

-- Apply changes and exit
FLUSH PRIVILEGES;
EXIT;

Step 4: Downloading and Extracting OpenCart

Download the latest stable release zip archive of OpenCart directly from the official OpenCart GitHub repository into your /tmp directory.

Create the web root directory at /var/www/opencart and extract the archive into it.

The downloaded zip archive contains an upload/ folder that holds the actual storefront files. Move the contents of upload/ to the root of /var/www/opencart.

# Create web root directory
sudo mkdir -p /var/www/opencart

# Download latest stable OpenCart release
cd /tmp
wget https://github.com/opencart/opencart/releases/download/4.0.2.3/opencart-4.0.2.3.zip -O opencart.zip

# Extract archive
sudo unzip -q opencart.zip -d /tmp/opencart_src

# Move upload contents to /var/www/opencart
sudo cp -r /tmp/opencart_src/upload/* /var/www/opencart/

# Clean up temporary files
rm -rf /tmp/opencart.zip /tmp/opencart_src

Step 5: Renaming Configuration Files and Setting Permissions

OpenCart distributes template configuration files named config-dist.php in both the root directory and the administrative admin/ directory. You must rename these to config.php before running the web installer.

Rename both files as required by the setup wizard.

Assign ownership of the web root to the www-data user so that Apache can write configuration settings and process product image uploads.

Set secure file and directory permissions.

# Rename configuration templates to config.php
sudo mv /var/www/opencart/config-dist.php /var/www/opencart/config.php
sudo mv /var/www/opencart/admin/config-dist.php /var/www/opencart/admin/config.php

# Set ownership to web server user
sudo chown -R www-data:www-data /var/www/opencart
sudo find /var/www/opencart -type d -exec chmod 755 {} \;
sudo find /var/www/opencart -type f -exec chmod 644 {} \;

Step 6: Configuring Apache Virtual Host for OpenCart

Create an Apache Virtual Host configuration for your OpenCart domain name to enable clean URLs and directory security.

Create /etc/apache2/sites-available/opencart.conf and define the document root, domain name, and directory overrides.

Enable the Apache rewrite and headers modules, activate the site, and restart Apache.

# Create Apache Virtual Host configuration
sudo bash -c 'cat <<EOF > /etc/apache2/sites-available/opencart.conf
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/opencart
    ServerName store.example.com

    <Directory /var/www/opencart>
        Options -Indexes +FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/opencart_error.log
    CustomLog ${APACHE_LOG_DIR}/opencart_access.log combined
</VirtualHost>
EOF'

# Enable rewrite module and site
sudo a2enmod rewrite headers
sudo a2ensite opencart.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2

Step 7: Securing OpenCart with Let's Encrypt SSL

Securing your online storefront with an SSL/TLS certificate is mandatory for protecting customer credit card data and customer accounts.

Install Certbot and the Apache plugin, then issue a free Let's Encrypt SSL certificate for your storefront domain.

Certbot will automatically configure HTTPS redirects and renew certificates via systemd timers.

# Install Certbot and Apache plugin
sudo apt install -y certbot python3-certbot-apache

# Obtain and bind SSL certificate
sudo certbot --apache -d store.example.com

Step 8: Completing the Web Wizard and Moving the Storage Directory

Open your web browser and navigate to https://store.example.com to launch the graphical installation wizard.

1. License Agreement: Accept the GNU General Public License.

2. Pre-Installation: Confirm that all PHP settings, extensions, and file write permissions display green checkmarks.

3. Configuration: Enter database connection parameters (Driver: MySQLi, Host: localhost, User: opencart_user, Password: StrongOpenCartPass123!, Database: opencart_db) and set up your administrative username, password, and email address.

Click Continue to finish setup. Afterward, delete the install directory and follow the admin prompt to move the system/storage directory outside the web root for enhanced security.

# Delete install directory for security
sudo rm -rf /var/www/opencart/install

# Lock down config.php permissions
sudo chmod 644 /var/www/opencart/config.php /var/www/opencart/admin/config.php

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Installer warns 'config.php or admin/config.php does not exist'

Resolution: Make sure you renamed the template files: sudo cp /var/www/opencart/config-dist.php /var/www/opencart/config.php and sudo cp /var/www/opencart/admin/config-dist.php /var/www/opencart/admin/config.php, and ensure www-data has write permissions during installation.

Storage directory security popup in OpenCart admin

Resolution: OpenCart recommends moving the system/storage/ directory outside the public web root (e.g. to /var/www/storage/). Click the automated 'Move' button in the admin notification dialog, or update paths manually in config.php.

SEO URLs return 404 Not Found on product pages

Resolution: Rename the distributed .htaccess.txt file to .htaccess: sudo mv /var/www/opencart/.htaccess.txt /var/www/opencart/.htaccess and ensure mod_rewrite is enabled in Apache.

Security Best Practices and Hardening

Always delete the /var/www/opencart/install directory immediately after completing setup to prevent malicious store overwrites.

Move the system/storage directory outside of the public document root (to /var/www/storage) to prevent direct browser execution of uploaded files.

Protect your admin directory with HTTP Basic Authentication or by renaming the admin folder in both admin/config.php and root config.php.

Enforce HTTPS across all pages and enable HSTS in Apache to safeguard checkout customer data.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
OpenCart is significantly lighter and easier to host than Magento, while offering dedicated out-of-the-box multi-store and multi-currency management that requires complex third-party plugins in WooCommerce.
Yes! OpenCart runs smoothly on Nginx with PHP-FPM. However, Apache is the standard recommended server because OpenCart ships with pre-configured .htaccess rewrite rules.
To upgrade, backup your database and system/storage directory, upload the new files over the existing web root (except config.php), and navigate to https://store.example.com/install to run the database upgrade script.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout