In this guide, we will explore setting up OpenCart on an Ubuntu server with Apache serving it and MariaDB acting as the database.
OpenCart is an open-source eCommerce platform β everything you need to create, scale and run your business. It is an open source online store management system. It is PHP-based, using a MySQL database and HTML components.
Apache is a popular web server often used to serve PHP content. MySQL/MariaDB is a popular relational database management system used by many large websites.
Updated July 2026 β read this before you start. This guide was originally written for Ubuntu 20.04 and PHP 7.4. Two things have changed since:
- Ubuntu 20.04 “Focal Fossa” left standard support on 31 May 2025. It only receives patches through Ubuntu Pro ESM (until 2030). For a new store use Ubuntu 24.04 LTS or 26.04 LTS.
- Current OpenCart requires PHP 8.1 or newer. The 3.0.5.0 installer refuses to continue on anything older, so the stock PHP 7.4 in Ubuntu 20.04 will not work. See Installing PHP below.
Every command below works unchanged on Ubuntu 22.04, 24.04 and 26.04 β only the package versions you see in the output differ.
Related Content:
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on OpenSUSE Leap 15.3
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on Debian 11
- How to install and set up PHP and Apache (LAMP stack) on Ubuntu 22.04
- How to install and set up PHP and Apache (LAMP stack) on Ubuntu 20.04
- How to install and Configure Mariadb 10 in Ubuntu 22.04
- How to install and Configure Mariadb 10 in Ubuntu 20.04
- Mysql Permissions β Create, Update, Delete Database Users
Prerequisites
To follow along, ensure you have the following:
- An updated Ubuntu server β 24.04 LTS or 26.04 LTS recommended; 20.04 and 22.04 work too, with the PHP caveat noted above
- Root access or a user with sudo access
- Internet access
Ensure that the server is up to date
Before proceeding, it is always a good practice to ensure that the server is up to date. Use these commands to achieve this
sudo apt update
sudo apt upgrade -y
Install some common packages that we will need later
sudo apt install -y vim unzip
Installing MariaDB in Ubuntu
MariaDB is a popular open source relational database management system. It is available in the default repositories as mariadb-server.
Install it with this command:
sudo apt install -y mariadb-server
The version you get depends on your Ubuntu release β 10.3 on 20.04, 10.6 on 22.04, 10.11 on 24.04 and 11.8 on 26.04. Any of them works with OpenCart.
MariaDB will be installed and started by default. Check the status with this
$ sudo systemctl status mariadb
β mariadb.service - MariaDB 10.3.32 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-12-16 18:51:26 UTC; 6s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 35152 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 4631)
Memory: 64.3M
CGroup: /system.slice/mariadb.service
ββ35152 /usr/sbin/mysqld
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: Processing databases
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: information_schema
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: mysql
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: performance_schema
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: Phase 6/7: Checking and upgrading tables
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: Processing databases
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: information_schema
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: performance_schema
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Dec 16 18:51:26 ip-10-2-40-129 /etc/mysql/debian-start[35192]: OK
To ensure that MariaDB starts on boot, enable it with this systemd command:
sudo systemctl enable mariadb
Once the service is running, you need to secure it. MariaDB provides a command line utility that will do that:
sudo mysql_secure_installation
The above command will take you through prompts to secure and set a root password for the database instance.
Check more info on installing and setting up MariaDB in this guide.
Creating a MySQL user for OpenCart
It is always recommended to have a dedicated user for each app that connects to the DB. Check out this guide on managing MySQL permissions. We will set up a database, user and password to be used by OpenCart:
Connect to the database server:
sudo mysql -u root -p
After supplying your password, enter the following at the prompt:
CREATE DATABASE opencart CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'opencart_user'@'localhost' IDENTIFIED BY 'S0mStrongPa$$word';
GRANT ALL PRIVILEGES ON opencart.* TO 'opencart_user'@'localhost';
FLUSH PRIVILEGES;
Bind the user to
localhostrather than'%'. Since Apache, PHP and MariaDB all live on this one server, there is no reason to let the account log in from any host on the network. Use'%'only if your database is on a separate box.
Now that we have configured our database connection, let’s go to the next section where we install and configure PHP.
Installing PHP
OpenCart 3.0.5.0 and 4.x require PHP 8.1 or newer β the installer stops with an error on anything older. That has one practical consequence per release:
| Ubuntu release | Default PHP | Works out of the box? |
|---|---|---|
| 20.04 LTS | 7.4 | No β too old for current OpenCart |
| 22.04 LTS | 8.1 | Yes |
| 24.04 LTS | 8.3 | Yes |
| 26.04 LTS | 8.5 | Yes, but see the note below |
On Ubuntu 22.04 and newer, the distro PHP is fine and you can just install it:
sudo apt install -y \
php \
php-cli \
libapache2-mod-php \
php-mysql \
php-gd \
php-curl \
php-zip \
php-xml \
php-mbstring \
php-intl
php-mysql provides the mysqli/pdo_mysql driver OpenCart connects with, and php-xml covers the DOM and XMLWriter extensions the installer checks for. libapache2-mod-php wires PHP into Apache β installing it will pull in apache2 as a dependency, which the next section covers anyway.
There is no need for php-json any more: JSON has been part of PHP core since 8.0, so the separate package is a no-op.
Confirm the version you ended up with:
php -v
On Ubuntu 20.04, the archive only has PHP 7.4, which current OpenCart rejects. Your options are, in order of preference:
- Upgrade the server to 24.04 LTS or 26.04 LTS. 20.04 is out of standard support anyway, so this is the fix that also gets you security patches.
- Install a newer PHP from a third-party repository such as OndΕej SurΓ½’s PHP packages, then install the
php8.1-*(or newer) variants of the packages above. Check first that the repository still publishes builds forfocalβ third-party archives generally drop a series once Ubuntu does. - Stay on an old OpenCart release that supports PHP 7.4. This leaves you without security fixes and is not recommended.
Ubuntu 26.04 ships PHP 8.5. OpenCart 3.0.5.0’s own test suite runs against PHP 8.1 through 8.4, so 8.5 is newer than what upstream currently tests. It installs and runs, but keep an eye on
/var/log/apache2/for deprecation notices, and pin an 8.4 build from a third-party repository if an extension misbehaves.
For more on setting up PHP and Apache, check out this guide.
Installing Apache on Ubuntu
Apache packages are available in the default Ubuntu repositories as apache2. Install it using this command:
sudo apt install -y apache2
Confirm the installed packages using this command:
$ apt-cache policy apache2
apache2:
Installed: 2.4.41-4ubuntu3.8
Candidate: 2.4.41-4ubuntu3.8
Version table:
*** 2.4.41-4ubuntu3.8 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
100 /var/lib/dpkg/status
2.4.41-4ubuntu3.6 500
500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
2.4.41-4ubuntu3 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 Packages
That output is from Ubuntu 20.04; on 24.04 you will see Apache 2.4.58 instead. The service will be started by default. Check the status using this command:
$ sudo systemctl status apache2
β apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-12-16 18:36:59 UTC; 19min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 33818 (apache2)
Tasks: 7 (limit: 4631)
Memory: 10.9M
CGroup: /system.slice/apache2.service
ββ33818 /usr/sbin/apache2 -k start
ββ33821 /usr/sbin/apache2 -k start
ββ33822 /usr/sbin/apache2 -k start
ββ33823 /usr/sbin/apache2 -k start
ββ33824 /usr/sbin/apache2 -k start
ββ33825 /usr/sbin/apache2 -k start
ββ34419 /usr/sbin/apache2 -k start
Dec 16 18:36:59 ip-10-2-40-129 systemd[1]: Starting The Apache HTTP Server...
Dec 16 18:36:59 ip-10-2-40-129 systemd[1]: Started The Apache HTTP Server.
To enable the service on boot, use this command
sudo systemctl enable apache2
OpenCart’s SEO URLs need mod_rewrite, so enable it now:
sudo a2enmod rewrite
sudo systemctl restart apache2
To confirm that Apache is installed and working fine, please visit the server’s IP address in the browser (http://server_ip). If you don’t know the server IP, get it using this command in your terminal:
curl -4 icanhazip.com
If all is well, you should see the Apache2 Ubuntu Default Page.
Setting up OpenCart
After setting up the database, PHP and Apache, we need to download the OpenCart installation file and put it on the server. We need to create a directory in the server where the content will be hosted.
I am going to be setting up OpenCart to be served from the domain http://opencart.citizix.com. Since Apache serves content from /var/www/html, I will create my site’s directory in that /var/www directory:
sudo mkdir /var/www/opencart.citizix.com
Now let’s download and extract the OpenCart content. OpenCart uses GitHub to track its releases. Head over to the OpenCart releases page and grab the latest release. As of this update the current release is 3.0.5.0 (December 2025); the 4.x branch is at 4.1.0.3. The 3.0.x series remains the better-supported choice for most stores, and is what the commands below use.
Download it with this command:
curl -LO https://github.com/opencart/opencart/releases/download/3.0.5.0/opencart-3.0.5.0.zip
Now that the file has been downloaded, we need to extract it. You need the unzip command to extract it.
unzip opencart-3.0.5.0.zip
The content will be extracted to the upload directory. Let’s move it to our site path with this command:
sudo mv upload/* /var/www/opencart.citizix.com/
Rename config-dist.php to config.php and admin/config-dist.php to admin/config.php. These ship empty β the web installer writes them:
cd /var/www/opencart.citizix.com/
sudo mv config-dist.php config.php
sudo mv admin/config-dist.php admin/config.php
Now hand ownership to the Apache user. The installer has to write both config files and the system/storage tree, so this step is not optional:
sudo chown -R www-data:www-data /var/www/opencart.citizix.com
sudo find /var/www/opencart.citizix.com -type d -exec chmod 755 {} \;
sudo find /var/www/opencart.citizix.com -type f -exec chmod 644 {} \;
Create a virtual host to serve OpenCart
Now that the required software packages have been installed and the OpenCart content has been copied, we need an Apache virtual host to serve the content for our site http://opencart.citizix.com.
Apache virtual host files specify the configuration of each site and tell the Apache web server how to respond to various domain requests.
Please note that the DNS for the domain to be used should already be configured to point to the IP address of the server. Confirm that with:
dig -t A opencart.citizix.com
On Ubuntu, Apache site configurations live in /etc/apache2/sites-available/ and are activated by symlinking them into /etc/apache2/sites-enabled/ with a2ensite. Let’s create a config for our site:
sudo vim /etc/apache2/sites-available/opencart.citizix.com.conf
Add the following content:
<VirtualHost *:80>
ServerName opencart.citizix.com
DocumentRoot /var/www/opencart.citizix.com
DirectoryIndex index.php
<Directory /var/www/opencart.citizix.com>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/opencart.citizix.com.error.log
CustomLog /var/log/apache2/opencart.citizix.com.requests.log combined
</VirtualHost>
AllowOverride All lets OpenCart’s bundled .htaccess take effect, which is what makes SEO URLs work.
Now enable the site, disable the stock default that would otherwise answer first, check the syntax and reload Apache:
sudo a2ensite opencart.citizix.com.conf
sudo a2dissite 000-default.conf
sudo apachectl configtest
sudo systemctl reload apache2
apachectl configtest should print Syntax OK before you reload. If you skip a2ensite, the file in sites-available is never read and your site will not be served.
Going through the OpenCart installation process
Once the above setup is done, we should be ready to start installing OpenCart. Visit the URL defined in the virtual host above to initiate the setup process. In my case when I visit http://opencart.citizix.com, I get a welcome page. Clicking continue, you will need to accept the terms then verify that the server has been set up as expected.
This is the step that catches a wrong PHP version or a missing extension. The installer checks for PHP 8.1+, a database driver (mysqli or pdo), and the gd, curl, openssl, zlib, zip, iconv, mbstring, dom, hash and xmlwriter extensions. If you installed the packages listed above you should see a green check for each of the items. Anything red maps directly to an apt install php-<name> you still owe, followed by sudo systemctl restart apache2.
Finally you will get to the database configuration and admin user. Fill in the database name, user and password you created earlier, then click Continue.
If everything is OK, you will be taken to the final step which tells you that the installation was successful.
Up to this point OpenCart is set up and ready to use.
Final setup
Let’s remove the installation directory on the server as recommended by that warning on the last page:
sudo rm -rf /var/www/opencart.citizix.com/install
Next, move the storage directory outside the web root so its contents β sessions, logs, uploads, cache β cannot be requested over HTTP.
Do this from the admin UI, not by hand. Log in to the admin at
http://opencart.citizix.com/admin, and OpenCart will show a security warning
offering to move the storage folder for you. Give it a path outside the document
root (for example /var/www/) and let it run: it copies the tree and rewrites
the DIR_STORAGE line in both config.php and admin/config.php in one step.
If you would rather do it manually, remember that moving the directory alone will break the site β the two config files still point at the old path. Move it, then update both:
sudo mv /var/www/opencart.citizix.com/system/storage /var/www/storage
sudo chown -R www-data:www-data /var/www/storage
Then edit /var/www/opencart.citizix.com/config.php and /var/www/opencart.citizix.com/admin/config.php, changing this line in each:
define('DIR_STORAGE', DIR_SYSTEM . 'storage/');
to point at the new location:
define('DIR_STORAGE', '/var/www/storage/');
Reload the storefront to confirm it still works.
Securing the site with HTTPS
The virtual host above serves plain HTTP, which is fine for a first run but not for a real store handling logins and payments. Once DNS resolves to the server, Let’s Encrypt will issue a certificate and rewrite the vhost for you:
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d opencart.citizix.com
After the certificate is in place, update the HTTP_SERVER / HTTPS_SERVER (and the matching HTTP_CATALOG / HTTPS_CATALOG) values in config.php and admin/config.php to use https://.
Conclusion
From the above steps, we were able to set up an Ubuntu server to serve OpenCart with Apache, MariaDB and PHP. The same steps apply on 20.04 through 26.04 β just make sure the PHP you end up with is 8.1 or newer, since that is what current OpenCart requires.