Setting up an e-commerce OpenCart system
Your Virtual Store
With OpenCart, a free, open source e-commerce system, you can put a store online in a matter of minutes.
If you have a brick and mortar store, it makes sense to expand your business and build some presence on the Internet, today's biggest marketplace.
Merchants have many options when it comes to selling their wares online. A popular option is to sell your products on a third-party platform, like Amazon or eBay. Another alternative is to use specialized hosting, which also involves a third party that sets up an e-commerce instance for you and maintains it for a monthly fee.
If you don't want to be dependent on a service provider, hosting your own e-commerce site might be an attractive option. Hosting your own site has the advantage of not binding you to a hosting provider. If your website is in a data center and they change their terms and conditions, you can migrate it somewhere else. If there is a feature you need, you can include it yourself – as long as you have the foresight to use a free and open source (FOSS) e-commerce system.
While there are many FOSS e-commerce systems available, such as PrestaShop, OsCommerce, and Magento, I am going to focus on OpenCart [1], a solution written in PHP that is easy to configure and comparatively cheap to run.
Installation
OpenCart is available as a Bitnami stack [2]. (For more information on Bitnami, see the June 2019 issue of Linux Magazine [3].) Using a Bitnami stack lets you set an instance in a matter of minutes without complications.
If you want to follow a more conventional approach, you will need a web server with FastCGI support, a suitable PHP version, and a database (see Table 1). In addition, you will need the PHP modules listed in Table 2. Configuring a web server is outside of this article's scope, but the Building a LAMP Server box serves as a starting point. OpenCart also works with OpenBSD's custom httpd server, but the setup is not officially documented.
Building a LAMP Server
LAMP (Linux, Apache, MySQL, PHP/Perl/Python) servers are common service stacks for hosting applications such as OpenCart. In this example, I am using MariaDB, a drop-in replacement for MySQL.
Assuming a Devuan environment, the following command will install the necessary components for a LAMP server:
# apt-get install apache2 libapache2-mod-php php php-cgi php-curl php-zip php-gd php-mcrypt php-mbstring php-mysql php-xml mariadb-server mariadb-client
Since you will be hosting a store, TLS encryption is required to ensure secure communication between the server and the customers.
The following commands will enable TLS:
# a2enmod ssl # a2ensite default-ssl
If Apache does not create a certificate automatically in your distribution, you will have to create it manually [4]. Self-signed certificates are not suitable for production, but they are fine for testing. If you intend to move this server to production, you will need to purchase a certificate from a certificate authority and install it [5]. Alternatively, you can use the Let's Encrypt service to obtain a free certificate [6].
You must configure the database OpenCart will use. The first step is to tighten the database's security by running the following script:
# mysql_secure_installation
Using the above script, enter a root password for MariaDB (keep in mind, it is for MariaDB's root, not the operating system's root user!). Read the prompt carefully and follow the instructions. Disable anonymous database users, remote database root login, and the test database, and then restart the Apache service:
# /etc/init.d/apache2 restart
Next, you create a database and grant OpenCart the privileges necessary to use it. First, open the MariaDB prompt:
# mysql -u root -p <enter password>
Then create a database called opencart and a user of the same name with access rights. Choose a good password, and use it instead of $PASSWORD in the following example:
MariaDB [(none)]> create database opencart; MariaDB [(none)]> grant all privileges on opencart.* TO 'opencart'@'localhost' identified by '$PASSWORD'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> quit;
Table 2
Required PHP modules
cURL |
Zip |
Zlib |
GD library |
Mcrypt |
mbstring |
XML |
Table 1
OpenCart 3.0.3.2 Requirements
Requirement | Comment |
---|---|
Web server |
Apache recommended |
PHP version |
5.4 or above |
Database |
MySQL (MySQLi recommended) |
Assuming you are installing OpenCart on a LAMP server, you need to download and unpack OpenCart to a suitable directory. OpenCart's source code comes with detailed instructions for unpacking. Listing 1 (a condensed summary) assumes a fresh Apache install on a Devuan system.
Listing 1
Unpacking OpenCart 3.0.3.2
# apt-get install curl unzip # cd /var/www/html # rm index.html # curl -LO https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip # unzip opencart-3.0.3.2.zip # rm *.json *.lock *.md *.txt *.xml *.zip # mv upload/* ./ # rm -r upload # find . -exec chmod 777 '{}' \; # mv config-dist.php config.php # mv admin/config-dist.php admin/config.php
The final step is to trigger the OpenCart installation scripts. If you have followed the instructions in Building a LAMP Server, you will have a web server listening on ports 80 and 443 of all network interfaces. Just visit your web server with a web browser and follow the instructions. The wizard will guide you through the installation process (Figure 1). It will check that your web service stack has all the necessary components, request your database access credentials (Figure 2), and let you create an administration account for OpenCart.
For additional pointers on using OpenCart, see the official documentation. In particular, take a look at OpenCart's Basic Security Practices [7]. At the very least, you should remove the install
directory.
# rm -r /var/www/html/install
Exploring Your New Store
By default, the administration interface is available under the admin
directory. It can be reached by visiting https://yourserver/admin, where yourserver is the host's IP address. Once you log in, you will need to complete some additional work in order to have a functional store.
OpenCart's interface is self-explanatory. To get started, go to System | Settings (Figure 3), where you can manage the store's core configuration. Here, the site name can be set, along with email settings and other important parameters. You can also enable Maintenance Mode here. If you select Maintenance Mode, visitors will be prevented from using the site and will see an explanatory message (Figure 4). However, administrators who are logged in can still browse the store during maintenance mode.
System | Localisation is where you configure localization, such as tax information and shipping zones. In the Taxes section, you can create broad categories of taxable items to which you can assign different tax rates.
The Catalog section allows you to upload new products to the store's catalog (Figure 5) and to group them in categories. Go to Catalog | Information to specify your site's terms and conditions, along with other legal information you may want to provide to your users.
Customizing OpenCart
OpenCart offers some basic features by default (see Table 3). However, in practice, OpenCart falls short on many necessary features. Perhaps the biggest roadblock is lack of support for credit card processors. In addition, you may find the custom theme too generic. OpenCart also does not have the capability of charging additional fees for cash on delivery (COD). Finally, EU Cookie warnings are not supported out of the box.
Table 3
OpenCart's Default Functions
Type | Functions Offered |
---|---|
Payment methods |
COD, wire transfer, check, PayPal, BrainTree |
Shipment modules |
Flat rate, weight-dependent rate, free delivery, pick-up at store |
Anti-spam functions |
Basic Captcha(not recommended), Google Captcha |
Marketing |
Discount coupons, affiliate program, gift vouchers, site map |
Consequently, if you want to go into production, you will need to install extensions. The OpenCart marketplace [8] offers a wide array of extensions to power your website (Figure 6). You will have to spend money for some extensions (or build your own), but the good news is that OpenCart is much cheaper than alternatives like PrestaShop in terms of extensions.
OpenCart's default theme is a bit dry (Figure 7), and you will likely want to change it. OpenCart is built around the Model-View-Controller design pattern, so the interface is implemented separately from the system's core functionality. The interface is supported by Twig templates, which can be modified in Design | Theme Editor (Figure 8). While this works for small modifications, you are better off downloading a new theme if you want to make bigger changes.
Use the Extensions tab to install and configure your extensions and themes (Figure 9).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.