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
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.