How to Fix Outdated OpenCart Extensions and PHP 8 Compatibility Issues
Skip links

How I Fixed an Outdated OpenCart Extension That Stopped Working on PHP 8

One of the most common issues I face while working with OpenCart websites is outdated third party extensions. Many store owners continue using extensions that were developed years ago and are no longer maintained by the original developer. These extensions may work perfectly fine for years until the hosting environment is upgraded, especially when moving to PHP 8.

Recently, I worked on a client website where a product sticker extension suddenly stopped working. The uploaded product stickers were not saving in the admin panel, and because they were not saving correctly, they were not appearing on the frontend either.

At first glance, the issue looked complicated because there were no obvious errors visible inside the extension files. After spending nearly two days debugging the extension, I discovered that the problem was caused by a very small PHP function that had been deprecated in PHP 8. After replacing the outdated function with a supported alternative, the extension started working normally again.

This experience reminded me how important it is to understand how OpenCart extensions modify the system and where developers should look when troubleshooting extension related issues.

Step 1: OAuth Authentication

Dubai Pay requires a Bearer access token before any API call can be made.

Generating Access Token

function getAccessToken($clientId, $clientSecret)
{
$url = “https://ids.qa.dubai.gov.ae/oauth2/token”;
$credentials = base64_encode($clientId . “:” . $clientSecret);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
“Authorization: Basic ” . $credentials, “Content-Type: application/x-www-form-urlencoded” ],
CURLOPT_POSTFIELDS => http_build_query([
“grant_type” => “client_credentials”,
“scope” => “openid”
])
]);
$response = curl_exec($ch);
curl_close($ch); }

Why Old OpenCart Extensions Commonly Break

Many older OpenCart extensions were built for older PHP versions such as PHP 5.6 or PHP 7.0. When websites are upgraded to PHP 8, these extensions often fail because they rely on deprecated or removed PHP functions.

Some common problems include:

In many cases, the extension itself is not completely broken. The issue may only be caused by one small outdated function or syntax problem.

Step 1: OAuth Authentication

Dubai Pay requires a Bearer access token before any API call can be made.

Generating Access Token

function getAccessToken($clientId, $clientSecret)
{
$url = “https://ids.qa.dubai.gov.ae/oauth2/token”;
$credentials = base64_encode($clientId . “:” . $clientSecret);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
“Authorization: Basic ” . $credentials, “Content-Type: application/x-www-form-urlencoded” ],
CURLOPT_POSTFIELDS => http_build_query([
“grant_type” => “client_credentials”,
“scope” => “openid”
])
]);
$response = curl_exec($ch);
curl_close($ch); }

The Biggest Challenge With OpenCart Extensions

One of the most confusing parts of OpenCart development is finding where the actual code is running.

Sometimes you check the controller, model, or view files directly inside the extension folder, but the code you are looking for is not there. This happens because many extensions use OpenCart modifications to override or inject code dynamically.

You may see modified code inside the storage/modification/ folder, but not inside the original files. This confuses many developers and store owners during debugging.

Understanding how OpenCart modifications work can save hours of frustration.

Step 1: OAuth Authentication

Dubai Pay requires a Bearer access token before any API call can be made.

Generating Access Token

function getAccessToken($clientId, $clientSecret)
{
$url = “https://ids.qa.dubai.gov.ae/oauth2/token”;
$credentials = base64_encode($clientId . “:” . $clientSecret);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
“Authorization: Basic ” . $credentials, “Content-Type: application/x-www-form-urlencoded” ],
CURLOPT_POSTFIELDS => http_build_query([
“grant_type” => “client_credentials”,
“scope” => “openid”
])
]);
$response = curl_exec($ch);
curl_close($ch); }

Important Locations to Check When Troubleshooting OpenCart Extensions

Whenever you are debugging or modifying an OpenCart extension, these are the main locations you should inspect.

1. system/library

The system/library folder contains core helper classes and libraries used by extensions.

Sometimes extension developers place custom helper files or third party integrations inside this folder.

Common things to check:

If an extension is throwing fatal errors after upgrading PHP, this folder should always be checked.

2. Extension Controller Files

Controller files usually contain the main business logic of the extension.

Typical path:

catalog/controller/extension/
admin/controller/extension/

In my recent case, the issue initially appeared to come from the controller because the save action was failing.

3. Extension Model Files

Model files handle database queries and data storage.

Typical path:

catalog/model/extension/
admin/model/extension/

Always inspect models when:

Many outdated extensions use old database handling methods that may fail on newer PHP versions.

4. Extension View Files

View files control the frontend and admin appearance.

Typical path:

catalog/view/
admin/view/

These files usually contain:

If the data saves correctly but does not appear visually, the issue may exist inside the view files.

5. Modification XML Code Stored in Database

This is one of the most overlooked areas in OpenCart debugging.

Many developers forget that extensions can modify files dynamically using OCMod XML modifications.

The XML modification code is often stored inside the database rather than physical files.

You can find these modifications inside the modification database table.

The important column is:

xml

This XML code tells OpenCart how to inject or replace code inside controllers, models, and views.

Why This Matters

You may open the original controller or model file and not find the code responsible for the issue because the actual logic is being injected through the modification system.

This is exactly why debugging OpenCart extensions can become frustrating.

How to Check Modification XML Code

You can inspect modification code directly from the database.

Example SQL query:

SELECT * FROM modification;

Inside the xml column, you will find modification instructions such as:

<file path="catalog/controller/product/product.php"><operation><search><![CDATA[$data['price']]]&gt;</search><add position="after"><![CDATA[
            // custom code
        ]]&gt;</add></operation></file>

This helps you understand:

Also Check the Modification Cache Folder

OpenCart generates modified files inside:

storage/modification/

or in older versions:

system/storage/modification/

This folder contains the final compiled version of modified files.

If changes are not reflecting, clear the modification cache from the admin panel:

Extensions > Modifications > Refresh

You may also need to manually clear cache files.

Step 1: OAuth Authentication

Dubai Pay requires a Bearer access token before any API call can be made.

Generating Access Token

function getAccessToken($clientId, $clientSecret)
{
$url = “https://ids.qa.dubai.gov.ae/oauth2/token”;
$credentials = base64_encode($clientId . “:” . $clientSecret);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
“Authorization: Basic ” . $credentials, “Content-Type: application/x-www-form-urlencoded” ],
CURLOPT_POSTFIELDS => http_build_query([
“grant_type” => “client_credentials”,
“scope” => “openid”
])
]);
$response = curl_exec($ch);
curl_close($ch); }

Final Thoughts

OpenCart is still a powerful ecommerce platform, but many websites rely heavily on old third party extensions that were never updated for modern PHP versions.

The good news is that many issues are fixable with proper debugging and understanding of how OpenCart modifications work.

In my recent case, the entire extension failed because of one deprecated PHP function. After identifying and replacing that function, the extension started working perfectly again.

If you are facing issues with outdated OpenCart extensions, do not only check the controller, model, or view files. Always inspect:

Understanding these areas can save hours or even days of debugging time and help you keep older OpenCart stores running smoothly on modern PHP environments.

Step 1: OAuth Authentication

Dubai Pay requires a Bearer access token before any API call can be made.

Generating Access Token

function getAccessToken($clientId, $clientSecret)
{
$url = “https://ids.qa.dubai.gov.ae/oauth2/token”;
$credentials = base64_encode($clientId . “:” . $clientSecret);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
“Authorization: Basic ” . $credentials, “Content-Type: application/x-www-form-urlencoded” ],
CURLOPT_POSTFIELDS => http_build_query([
“grant_type” => “client_credentials”,
“scope” => “openid”
])
]);
$response = curl_exec($ch);
curl_close($ch); }

If you’re setting up a modern and scalable Moodle 4.5 LTS environment on Ubuntu 22.04, this guide will walk you through a clean and production-friendly installation workflow. We’re assuming that Nginx, PHP (8.1 or 8.2), and MySQL are already installed and as well as a database and DB user prepared ahead of time. 

The starting point is cloning Moodle from the official Git repository: 

sudo git clone -b MOODLE_405_STABLE https://github.com/moodle/moodle.git /var/www/html/moodle 

Make sure to update all placeholders marked as <EDIT> before running commands. 

1. Create the moodledata Directory 

Moodle stores all user-generated content in a non-web-accessible directory. Let’s create it with proper permissions: 

I am using /var/www/html for moodle so I will b creating moodledata folder in www folder. 

sudo mkdir -p /var/www/moodledata 

sudo chown -R www-data:www-data /var/www/moodledata 

sudo chmod -R 770 /var/www/moodledata 

2. Prepare a PHP Upload Temp Directory 

This is a very important step, if the temporary upload directory isn’t set up properly, file uploads won’t work correctly. 

sudo mkdir -p /var/www/php-tmp 

sudo chown -R www-data:www-data /var/www/php-tmp 

sudo chmod 733 /var/www/php-tmp 

Update PHP: 

Now go to the php.ini file, search for upload_tmp_dir, and set its value to: 

upload_tmp_dir = /var/www/php-tmp 

Restart PHP-FPM: 

After setting the value, restart PHP-FPM. 

sudo systemctl restart php8.2-fpm 

3. Set Permissions for Moodle Code 

Moodle needs the correct permissions to run properly. These commands give ownership of the Moodle folder to the web server and set safe permissions so directories and files can be read and used correctly while staying secure: 

sudo chown -R www-data:www-data /var/www/html/moodle 

sudo find /var/www/html/moodle -type d -exec chmod 755 {} \; 

sudo find /var/www/html/moodle -type f -exec chmod 644 {} \; 

4. Configure Nginx 

Create the server block in /etc/nginx/sites-available/moodle 

Paste the following (update server name and PHP socket if needed): 

server { 

 listen 80; 

server_name moodle.test; 

root /var/www/html/moodle; 

index index.php; 

client_max_body_size 200M; 

access_log /var/log/nginx/moodle_access.log; 

error_log  /var/log/nginx/moodle_error.log; 

location / { 

try_files $uri $uri/ /index.php?$query_string; 

location ~ ^(.+\.php)(/.+)?$ { 

fastcgi_split_path_info ^(.+\.php)(/.+)$; 

include fastcgi_params; 

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

fastcgi_param PATH_INFO $fastcgi_path_info; 

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 

fastcgi_pass unix:/run/php/php8.2-fpm.sock; 

location /moodledata { deny all; } 

5. Enable the Site and Reload Nginx 

sudo ln -sf /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/moodle 

sudo nginx -t 

sudo systemctl reload nginx 

6. Install Moodle Using CLI 

This command runs Moodle’s built-in installer from the command line. It sets your site URL, data folder, database details, and admin account, and completes the installation automatically without asking questions: 

sudo -u www-data php /var/www/html/moodle/admin/cli/install.php –wwwroot=http://moodle.test –dataroot=/var/www/moodledata –dbtype=mysqli –dbname=<DB_NAME> –dbuser=<DB_USER> –dbpass='<DB_PASS>’ –fullname=’SWA University LMS’ –shortname=’SWA University’ –adminuser=admin –adminpass=’Admin123!’ –agree-license –non-interactive 

7. Post-Install Developer Adjustments 

These commands adjust file permissions after installation. They give you ownership of the Moodle code so you can edit it, set safe permissions for the config.php file, and restore the correct ownership and permissions on the moodledata folder so Moodle can store files properly: 

sudo chown -R $USER:$USER /var/www/html/moodle 

sudo chown $USER:www-data /var/www/html/moodle/config.php 

sudo chmod 664 /var/www/html/moodle/config.php 

sudo chown -R www-data:www-data /var/www/moodledata 

sudo chmod -R 770 /var/www/moodledata 

8. Purge Caches & Enable Cron 

This command clears all Moodle caches to make sure the site loads fresh settings and files after installation or configuration changes: 

sudo -u www-data php /var/www/html/moodle/admin/cli/purge_caches.php 

Cron setup: 

This cron job runs Moodle’s scheduled tasks every minute. It is required for Moodle to function correctly. Without it, many features such as emails, enrollments, cleanups, and background tasks will not work properly: 

* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null 2>&1 

9. Quick Validation Checks 

After installation, run these quick checks to make sure your Moodle site is working correctly and that there are no permission or configuration issues: 

– Visit http://moodle.test 

– curl -I http://moodle.test/pluginfile.php (expect 404 or HTML, not 502/500) 

– If JS/CSS missing, ensure correct PHP regex 

– If upload fails, check permissions on php-tmp and moodledata 

Conclusion 

You now have a clean, fast, and production-ready Moodle 4.5 LTS installation on Ubuntu 22.04 using Git and Nginx. This setup is ideal for universities, enterprises, and organizations aiming for a robust and scalable learning platform. 

This website uses cookies to improve your web experience.
See your Privacy Settings to learn more.
Home
Account
Cart
Search
View
Drag