DEV Community

Full Stack Hacker
Full Stack Hacker

Posted on • Edited on

1 1

Install OpenCart on Ubuntu with LAMP Stack

Prerequisites

Step 1 — Creating a MySQL Database and User for OpenCart

To get started, log into the MySQL root (administrative) account by issuing the following command: sudo mysql -u root -p To create a database, database user, and grant all privileges to the database user run the following commands:

mysql> CREATE DATABASE opencart DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> CREATE USER 'opencartuser'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password';
mysql> GRANT ALL ON opencart.* TO 'opencartuser'@'%';
mysql> FLUSH PRIVILEGES;
mysql> \q

Step 2 - Downloading OpenCart

With the database configured, now we need to download the OpenCart zipped file. First, navigate to /tmp directory:

cd /tmp
wget https://github.com/opencart/opencart/releases/download/4.0.0.0/opencart-4.0.0.0.zip

Once downloaded, unzip the OpenCart zip file as shown extract the zipped file and move this directory to the webroot directory – /var/www/html

unzip opencart-4.0.0.0.zip
sudo mv upload/ /var/www/html/opencart

Step 3 - Configure the OpenCart directory

The next step is to copy a few configuration files as shown in the commands below:

cp /var/www/html/opencart/config-dist.php /var/www/html/opencart/config.php
cp /var/www/html/opencart/admin/config-dist.php /var/www/html/opencart/admin/config.php

Step 4 - Change file permissions of the OpenCart directory

Next, we need to modify file permissions of the OpenCart directory to make it writable to the Apache web server as shown

chmod -R 777 /var/www/html/opencart/

Next, change ownership of the OpenCart directory to www:data

chown -R www-data:www-data /var/www/html/opencart/

Step 5 - Configure Apache Web Server for OpenCart

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your installation:

sudo nano /etc/apache2/sites-available/opencart.conf

Add the following content:

<VirtualHost *:80>

ServerAdmin webmaster@your-domain.com

ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/html/opencart/upload/

<Directory /var/www/html/opencart/upload/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Enable the OpenCart virtual host: sudo a2ensite opencart.conf

Restart the Apache web server: sudo systemctl restart apache2

Step 5 - Enable the rewrite module

Since OpenCart requires mod_rewrite to rewrite URLs, we shall enable the module and restart the Apache webserver.

a2enmod rewrite

Restart the Apache web server: sudo systemctl restart apache2

Step 6 - Setting up OpenCart on a browser

Having finalized all configurations, head out to your browser and browse your server’s IP address of domain name The next page will require you to fill in the database details. Enter the details you defined in the MySQL database and click Continue. This completes the setup and Now you can click the Login to your Administration to login to the admin dashboard.

Top comments (1)

Collapse
 
ibtisam021 profile image
Ibtisam021

This is a fantastic guide for anyone looking to set up an e-commerce store using OpenCart on an Ubuntu server! The step-by-step instructions and detailed explanations make it easy to follow, even for beginners. I appreciate how the article covers everything from installing the LAMP stack to configuring Apache and setting up the OpenCart database. It's a comprehensive resource that ensures a smooth installation process.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more