UbuntuUbuntu Based

How To Install OpenCart on Ubuntu 24.04 LTS

Install OpenCart on Ubuntu 24.04

OpenCart is a widely trusted, open-source e-commerce platform that provides a robust framework for building online stores. Running OpenCart on Ubuntu 24.04 LTS combines the reliability and security of Ubuntu with a flexible, customizable shopping cart system. In this tutorial, you will learn how to install OpenCart step by step, from preparing your server environment to securing your final installation. The methods outlined here will help you create a performant and efficient e-commerce solution that supports various payment gateways, shipping methods, and extensions.

Prerequisites and System Requirements

Before you begin, ensure you have the following:

  • Operating System: Ubuntu 24.04 LTS installed on your server or virtual machine.
  • System Resources: At least 2 GB of RAM (4 GB recommended for high-traffic sites), and 20 GB of available disk space.
  • User Account: A non-root user with sudo privileges for installing and configuring packages.
  • Domain or IP Address: A fully qualified domain name (FQDN) pointed to your server (if you intend to use a custom domain), or a public server IP address.
  • SSH Client: For remote access to the Ubuntu server, such as PuTTY or the Linux/macOS terminal.

To verify your server meets the basic hardware requirements, you can use free -h to check available memory and df -h to confirm available storage. Having these prerequisites in place ensures a seamless and efficient OpenCart installation.

Step 1: Update and Upgrade System Packages

Keeping your Ubuntu 24.04 LTS system up to date lays a solid foundation for any software installation. Regular updates enhance security, fix bugs, and ensure compatibility with new packages.

sudo apt update && sudo apt upgrade -y

This command refreshes the local package index and upgrades all installed packages to the latest version. Reboot your system if necessary to complete any kernel updates. Once the server starts up again, you can proceed.

Step 2: Install and Configure a Web Server

OpenCart requires a reliable web server to respond to client requests. You can choose between Apache and Nginx, two widely adopted web servers known for their performance and stability.

Option A: Apache

Apache is a highly popular choice for hosting OpenCart, partly due to its user-friendly configuration and widespread community support. According to Linux Genie, Apache remains a favorite for new users because of its simplicity in setup and administration tasks.

  1. Install Apache:
    sudo apt install apache2 -y
    
  2. Start and Enable Apache:
    sudo systemctl start apache2
    sudo systemctl enable apache2
    
  3. Adjust Firewall Settings:
    sudo ufw allow 'Apache Full'
    

    By opening ports 80 (HTTP) and 443 (HTTPS), you ensure that web traffic can reach your server seamlessly.

Option B: Nginx (Alternative)

If you prefer a lightweight server that excels in handling high-concurrency connections, Nginx can be just as effective. Nginx is recognized for its efficient management of static content and reduced memory usage. To install Nginx instead of Apache:

sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

The essential steps of opening the firewall and verifying the server status remain the same. If you visit your server’s IP or domain in a browser and see the Nginx welcome page, you are ready to proceed.

Step 3: Install PHP and Required Extensions

OpenCart is built on PHP and depends on multiple PHP extensions to deliver functionalities like database connectivity, image processing, file uploads, and more. Without these extensions, many features may fail to function correctly.

  1. Install PHP:
    sudo apt install php libapache2-mod-php php-mysql php-gd php-curl php-mbstring php-xml php-zip -y
    

    If you are using Nginx, install php-fpm instead of libapache2-mod-php and configure php-fpm accordingly.

  2. Check PHP Version:
    php -v
    

    Ensure your PHP version matches OpenCart’s requirements. Versions 7.4 or higher, such as 8.0 or 8.1, are typically compatible with modern OpenCart releases.

  3. Adjust PHP Settings:Modify php.ini settings to accommodate file uploads and memory requirements for OpenCart. For instance, you can increase the maximum file upload size and memory limit:
    sudo nano /etc/php/8.1/apache2/php.ini
    

    Look for the lines upload_max_filesize and memory_limit, and adjust them as needed, for example:

    upload_max_filesize = 64M
    memory_limit = 256M
    

Step 4: Install MariaDB and Create a Database

A reliable database is vital for storing all product information, user data, and configurations in OpenCart. Most users choose MariaDB or MySQL for this purpose.

  1. Install MariaDB:
    sudo apt install mariadb-server mariadb-client -y
    

    MariaDB provides a stable, drop-in replacement for MySQL. Verify the installation with:

    mysql --version
    
  2. Secure Your MariaDB Installation:
    sudo mysql_secure_installation
    

    You will be prompted to configure the root password and remove test databases or anonymous users. These steps improve the security posture of your setup.

  3. Create a Database and User for OpenCart:
    sudo mysql -u root -p
    
    CREATE DATABASE opencart_db;
    CREATE USER 'opencart_user'@'localhost' IDENTIFIED BY 'strong_password';
    GRANT ALL PRIVILEGES ON opencart_db.* TO 'opencart_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

    Replace strong_password with a robust password. This dedicated database user will manage your OpenCart data securely.

Step 5: Download and Extract OpenCart Files

Downloading the latest OpenCart release ensures you benefit from recent security patches and performance enhancements. Check the official OpenCart GitHub or website for the latest version numbers before proceeding.

  1. Navigate to /tmp and Download:
    cd /tmp
    wget https://github.com/opencart/opencart/releases/download/3.0.4.0/opencart-3.0.4.0.zip
    

    Adjust the link if a newer version is available.

  2. Install Unzip (If Needed) and Unpack:
    sudo apt install unzip -y
    sudo unzip opencart-3.0.4.0.zip -d /var/www/html/opencart/
    

    The files will be extracted into the /var/www/html/opencart/ directory. Ensure this path matches your specific server environment.

Step 6: Configure OpenCart Files and Set Permissions

Proper file configuration and permissions are crucial to ensuring your OpenCart installation can access the required scripts and directories. Additionally, setting the right ownership prevents unauthorized users from altering critical files.

  1. Rename and Copy Configuration Files:
    sudo cp /var/www/html/opencart/upload/config-dist.php /var/www/html/opencart/upload/config.php
    sudo cp /var/www/html/opencart/upload/admin/config-dist.php /var/www/html/opencart/upload/admin/config.php
    

    These config.php files allow OpenCart to store database credentials and define directory settings.

  2. Adjust Ownership and Permissions:
    sudo chown -R www-data:www-data /var/www/html/opencart/
    sudo chmod -R 755 /var/www/html/opencart/
    

    This ensures that the Apache (or Nginx) user can write to the necessary directories, removing potential permission-related errors.

Step 7: Access OpenCart Installation Wizard via Web Browser

After configuring your web server, PHP, and database, you are ready to access the user-friendly OpenCart installation wizard.

  1. Navigate to Your Domain or IP:Open a browser and go to http://your_server_ip/opencart or http://your_domain.com/opencart. You should see the OpenCart installer’s welcome page.
  2. Follow the Installation Steps:
    • Pre-Installation Check: Confirm that all mandatory PHP extensions and file permissions are correctly set.
    • Database Configuration: Enter opencart_db, opencart_user, and the password you created in Step 4.
    • Admin Account Setup: Choose a secure username, password, and email address for the OpenCart administration dashboard.
  3. Finalize the Installation:Click “Continue” to wrap up. If the process completes without errors, you will see a success message confirming your new OpenCart store is ready.

Step 8: Post-Installation Steps for Security

Securing your e-commerce store is crucial, as it handles sensitive customer and transaction data. Several best practices can help you fortify your OpenCart site.

  1. Delete the Installation Directory:
    sudo rm -rf /var/www/html/opencart/install/
    

    This prevents attackers from rerunning the setup wizard or exploiting leftover installer scripts.

  2. Enable SSL Certificates: Implementing SSL/TLS ensures encrypted communication between your customers and server. You can install a free Let’s Encrypt certificate as follows:
    sudo apt install certbot python3-certbot-apache
    sudo certbot --apache
    

    Follow on-screen instructions to secure your domain. If you use Nginx, replace –apache with –nginx and confirm your system’s domain setup.

  3. Configure .htaccess for Added Security: A well-configured .htaccess can protect directories and block unwanted access:
    sudo nano /var/www/html/opencart/.htaccess
    

    Limit directory browsing and deny suspicious requests to reduce your attack surface. For Nginx, use nginx.conf or specific security rules in your server blocks.

Troubleshooting Common Issues

Below are a few common problems you may encounter during the OpenCart setup phase, along with potential solutions:

  • Blank Pages or PHP Errors: Blank pages often stem from missing PHP extensions or incorrect file permissions. Double-check that all required PHP modules listed in the OpenCart documentation are installed. Inspect /var/log/apache2/error.log or /var/log/nginx/error.log for error messages.
  • Database Connection Failures: Ensure you have provided the correct database name, username, and password in OpenCart’s setup. Verify that MariaDB is running:
    sudo systemctl status mariadb
    
  • Insufficient Permissions on config.php: If you cannot proceed with setup or see errors stating inability to write configuration, run the chown and chmod commands from Step 6 again. Also confirm the correct user:group ownership.
  • Issues with SSL Setup: If you face trouble configuring HTTPS, ensure your domain’s DNS settings are correct. Confirm that ports 80 and 443 are open. Tools like sslchecker can confirm if the certificate is successfully installed.

Congratulations! You have successfully installed OpenCart. Thanks for using this tutorial for installing the OpenCart on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the OpenCart website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button