How to Install OpenCart on CentOS 7: NGINX or Apache, PHP, MariaDB, and Secure Initial Setup

How to Install OpenCart on CentOS 7

OpenCart is a widely used e-commerce platform that gives businesses a relatively lightweight way to launch and manage an online store. It supports product catalogs, order processing, modules, payment integrations, and an administrative dashboard without forcing you into a very heavy application stack. Installing OpenCart on CentOS 7 can be a good fit when you want full control over the web server, PHP version, database configuration, file permissions, and long-term maintenance strategy instead of depending entirely on a managed control panel.

In practical terms, an OpenCart deployment has three main layers: a web server, PHP, and a database. After those layers are ready, you upload the OpenCart files, create the database, configure permissions, and complete the installer in a browser. This type of environment is commonly deployed on Virtual Servers, because a VPS gives you full control over PHP settings, MariaDB, and the web server stack. If your store is expected to handle heavier traffic or larger catalogs, Dedicated Servers may be more suitable. Since online stores should always use HTTPS, SSL Certificates are also a core part of the setup.

Before you begin, it is worth checking the compatibility between your chosen OpenCart version and the PHP version available on CentOS 7. CentOS 7 is an older operating system, and depending on the exact build you use, newer PHP or OpenCart combinations may require extra attention. If you skip this check, you may later run into installer errors, module failures, or admin panel issues that look like application problems but are actually version mismatches underneath.

1) Prepare the system and install base packages

Start by updating CentOS 7 and installing a few base utilities. This creates a cleaner starting point and makes the rest of the process much easier. In addition to the web stack itself, it is helpful to have tools such as wget, unzip, curl, and a text editor available from the beginning.

sudo yum update -y
sudo yum install -y wget curl unzip nano

OpenCart can run on both Apache and NGINX. Both are valid choices, but they differ in configuration style. Apache is often used in tutorials because it works naturally with .htaccess and is familiar to many administrators. NGINX is also common, especially when people want a lighter reverse-proxy style setup. In this tutorial, we will use Apache because it maps well to OpenCart’s common rewrite behavior and keeps the first installation easier to follow.

2) Install MariaDB and create the database

OpenCart stores products, customers, orders, settings, and extensions in a database, so the next step is installing MariaDB or MySQL. On CentOS 7, MariaDB is usually the simplest path. After installation, start the service, enable it on boot, and then create a dedicated database and dedicated user for OpenCart. Avoid using the database root account for application access.

sudo yum install -y mariadb-server mariadb
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

Once the basic security configuration is complete, log into MariaDB and create the OpenCart database and user. A separate database account is safer, easier to audit, and much cleaner operationally than using an administrative account for everything.

mysql -u root -p
CREATE DATABASE opencartdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'opencartuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON opencartdb.* TO 'opencartuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

You will need these values later during the web installer, so it is a good idea to store them safely now instead of trying to reconstruct them later from memory.

3) Install PHP and Apache

OpenCart requires PHP and several PHP extensions. In a typical CentOS 7 setup you will need php, php-mysqlnd, php-gd, php-mbstring, php-xml, php-cli, php-opcache, php-curl, and php-zip. Since this guide uses Apache, install httpd as well and start the service.

sudo yum install -y httpd php php-mysqlnd php-gd php-mbstring php-xml php-cli php-opcache php-curl php-zip
sudo systemctl enable --now httpd

After installation, verify the PHP version and check that Apache is running. This simple validation step saves time because it confirms the basic web stack is alive before you add application files on top of it.

php -v
sudo systemctl status httpd

If SELinux is enabled in enforcing mode, remember that it may affect file access or database connectivity. Many administrators think “OpenCart is broken” when the real problem is file context or access policy. Even if you do not fully tune SELinux at this stage, you should at least keep it in mind as a potential troubleshooting layer.

4) Download OpenCart and set file permissions

The next step is downloading OpenCart and placing it under the web root, for example in /var/www/html/opencart. After extraction, you need to arrange the files, rename the sample configuration files, and set ownership correctly so Apache can read the application and write to the required storage or cache paths.

cd /tmp
wget https://github.com/opencart/opencart/releases/download/VERSION/opencart-VERSION.zip
unzip opencart-VERSION.zip
sudo mkdir -p /var/www/html/opencart
sudo cp -r upload/* /var/www/html/opencart/

OpenCart includes config-dist.php sample files that must be renamed to config.php in both the root directory and the admin directory. If you forget this step, the installer may fail or behave inconsistently. After that, assign the files to the Apache user so the web server can work with them properly.

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

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

In some cases, specific directories such as cache or storage-related locations need writable permissions. Avoid solving this too aggressively with blanket 777 permissions. It is better to grant only the necessary access to the exact directories that need it.

5) Configure Apache virtual host and run the installer

If you are using a dedicated domain or subdomain, create an Apache virtual host. This helps separate the store from other sites and makes HTTPS configuration easier later. The DocumentRoot should point to /var/www/html/opencart, and AllowOverride should be enabled so rewrite rules can work as expected.

sudo nano /etc/httpd/conf.d/opencart.conf

    ServerName shop.example.com
    DocumentRoot /var/www/html/opencart

    
        AllowOverride All
        Require all granted
    

    ErrorLog /var/log/httpd/opencart_error.log
    CustomLog /var/log/httpd/opencart_access.log combined

After saving the virtual host, restart Apache. If your firewall is enabled, allow HTTP and HTTPS traffic. Then open the domain or server IP in a browser and proceed through the OpenCart installer. You will be asked for the database name, database user, password, and the initial admin credentials.

sudo systemctl restart httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Once installation is complete, OpenCart requires you to remove the install directory. This is not optional from a security perspective. Leaving the installer in place is a common oversight and can create unnecessary warnings or exposure.

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

HTTPS, security, and ongoing maintenance

After OpenCart is installed successfully, do not stop at “the site opens in the browser”. A real online store should always use HTTPS, strong admin credentials, and a controlled update process. SSL is not just a technical detail for e-commerce; it is a basic trust and security requirement for customers, sessions, and payment-related flows.

Performance also depends on more than just PHP. Database tuning, caching, image optimization, and the quality of extensions all matter. Many OpenCart stores become slow not because of OpenCart itself, but because too many poorly maintained modules are installed or images are uploaded without optimization. A stable installation is therefore also about disciplined maintenance after day one.

Backups are essential. An online store contains not only product data but also customer records, order history, settings, and media. The simplest reliable model is to back up both the files and the database. Without both parts, a full recovery is incomplete.

mysqldump -u opencartuser -p opencartdb > /tmp/opencartdb.sql
tar -czf /tmp/opencart-files.tar.gz /var/www/html/opencart

If the store will be used long term, document the OpenCart version, PHP version, database settings, domain setup, and backup procedure. That documentation makes future upgrades, migrations, and troubleshooting much easier. A good OpenCart environment is not only one that installs successfully once, but one that can be maintained, secured, and restored cleanly over time.