BlogSelf-Hosted

Install OpenCart on a Raspberry Pi 4

Updated by Adam on August 17th, 2026

Build a small self-hosted OpenCart store on Raspberry Pi OS with Apache, MariaDB, PHP 8, TLS, least-privilege database access, and a security checklist.

OpenCart storefront banner

A Raspberry Pi 4 can run a small OpenCart catalog, lab store, or low-traffic shop. The hard part is not getting the installer to appear; it is keeping a public ecommerce server patched, backed up, encrypted, and recoverable.

This guide uses Raspberry Pi OS or Debian with Apache, MariaDB, and PHP 8. Always check the requirements bundled with the exact OpenCart release you download. OpenCart's current installer requires PHP 8 or newer and checks for database, GD, cURL, OpenSSL, and iconv or mbstring support.

Before you install

  • Use a 64-bit Raspberry Pi OS release.
  • Give the Pi a stable LAN address.
  • Use an SSD rather than a microSD card for a real store.
  • Decide how you will provide HTTPS before collecting credentials or customer information.
  • Do not expose a test store to the public internet.

1. Update the operating system

sudo apt update
sudo apt full-upgrade
sudo reboot

After reconnecting:

cat /etc/os-release
uname -m

2. Install the web stack

Package names vary slightly by Debian release, so let APT select its supported PHP version:

sudo apt install apache2 mariadb-server unzip curl \
  php php-cli php-common php-curl php-gd php-mbstring \
  php-mysql php-opcache php-xml php-zip

Enable Apache modules commonly needed by OpenCart:

sudo a2enmod rewrite headers ssl
sudo systemctl restart apache2
php -v

3. Create a least-privilege database

Run MariaDB's security helper:

sudo mariadb-secure-installation

Then create a dedicated database and user. Replace the example password with a long random value and do not reuse it:

sudo mariadb

At the MariaDB prompt:

CREATE DATABASE opencart CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'opencart'@'localhost' IDENTIFIED BY 'REPLACE_WITH_A_RANDOM_PASSWORD';
GRANT ALL PRIVILEGES ON opencart.* TO 'opencart'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Never give the application the MariaDB root account.

4. Download and stage OpenCart

Download a compiled release from the official OpenCart project. Do not deploy a random archive or the development branch to a live shop.

Assuming the downloaded file is in your home directory:

mkdir -p /tmp/opencart-install
unzip ~/opencart-*.zip -d /tmp/opencart-install
sudo mkdir -p /var/www/opencart
sudo cp -a /tmp/opencart-install/upload/. /var/www/opencart/

Follow the release's INSTALL.md exactly. Current manual installations require the two distributed config files to be renamed:

sudo cp /var/www/opencart/config-dist.php /var/www/opencart/config.php
sudo cp /var/www/opencart/admin/config-dist.php /var/www/opencart/admin/config.php
sudo chown -R www-data:www-data /var/www/opencart

Avoid blanket chmod 777 permissions. Give the web server write access only where the installer or runtime actually needs it.

5. Configure Apache

Create /etc/apache2/sites-available/opencart.conf:

<VirtualHost *:80>
    ServerName shop.example.com
    DocumentRoot /var/www/opencart

    <Directory /var/www/opencart>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/apache2/opencart-error.log
    CustomLog /var/log/apache2/opencart-access.log combined
</VirtualHost>

Enable and validate it:

sudo a2ensite opencart.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

6. Finish in the browser

Browse to the store hostname and complete the installer with:

  • database host: localhost;
  • database name: opencart;
  • database user: opencart;
  • the random database password;
  • a unique admin username and strong admin password.

Immediately after a successful install, remove the install directory as the official instructions require:

sudo mv /var/www/opencart/install /var/www/opencart/install.disabled

After confirming the store works, delete that disabled directory during your next maintenance pass.

Production checklist

Before taking orders:

  • Enable HTTPS and redirect HTTP to HTTPS.
  • Patch Raspberry Pi OS and OpenCart regularly.
  • Back up both /var/www/opencart and the MariaDB database.
  • Restore those backups to a test machine.
  • Protect the admin area with a renamed path, strong credentials, and preferably an IP allowlist or identity-aware access layer.
  • Disable display_errors in production and monitor the Apache and OpenCart logs.
  • Use a supported payment gateway; never build your own card-storage flow.
  • Put the Pi on a UPS if the database matters.

A Raspberry Pi store is best for learning or modest traffic. If uptime and sales become important, move the database and application to infrastructure with monitored storage, tested failover, and a defined recovery time. For another small-server guide, see keeping Proxmox awake with its laptop lid closed.