4.3 Setting up a configuration file for CMS OpenCart

Main Banner

Universal config for OpenCart 3.x

Transferring an online store to a new hosting in OpenCart often involves the need to make changes to configuration files such as config.php and admin/config.php. These files require updating host addresses, directory paths, and database parameters.

Example: standard content of the file config.php
/var/www/user_name/data/www/site_name/config.php
<?php
// HTTP
define('HTTP_SERVER', 'http://Site_Name/');

// HTTPS
define('HTTPS_SERVER', 'https://Site_Name/');

// DIR
define('DIR_APPLICATION', '/var/www/user_name/data/www/site_name/catalog/');
define('DIR_SYSTEM', '/var/www/user_name/data/www/site_name/system/');
define('DIR_IMAGE', '/var/www/user_name/data/www/site_name/image/');
define('DIR_STORAGE', '/var/www/user_name/data/www/site_name/storage/');
define('DIR_LANGUAGE', '/var/www/user_name/data/www/site_name/catalog/language/');
define('DIR_TEMPLATE', '/var/www/user_name/data/www/site_name/catalog/view/theme/');
define('DIR_CONFIG', '/var/www/user_name/data/www/site_name/system/config/');
define('DIR_CACHE', '/var/www/user_name/data/www/site_name/storage/cache/');
define('DIR_DOWNLOAD', '/var/www/user_name/data/www/site_name/storage/download/');
define('DIR_LOGS', '/var/www/user_name/data/www/site_name/storage/logs/');
define('DIR_MODIFICATION', '/var/www/user_name/data/www/site_name/storage/modification/');
define('DIR_SESSION', '/var/www/user_name/data/www/site_name/storage/session/');
define('DIR_UPLOAD', '/var/www/user_name/data/www/site_name/storage/upload/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php
Example: standard content of the config.php file admin/config.php
/var/www/user_name/data/www/site_name/admin/config.php
<?php
// HTTP
define('HTTP_SERVER', 'http://Site_Name/admin/');
define('HTTP_CATALOG', 'http://Site_Name/');

// HTTPS
define('HTTPS_SERVER', 'https://Site_Name/admin/');
define('HTTPS_CATALOG', 'https://Site_Name/');

// DIR
define('DIR_APPLICATION', '/var/www/user_name/data/www/site_name/admin/');
define('DIR_SYSTEM', '/var/www/user_name/data/www/site_name/system/');
define('DIR_IMAGE', '/var/www/user_name/data/www/site_name/image/');
define('DIR_STORAGE', '/var/www/user_name/data/www/site_name/storage/');
define('DIR_LANGUAGE', '/var/www/user_name/data/www/site_name/admin/language/');
define('DIR_TEMPLATE', '/var/www/user_name/data/www/site_name/admin/view/template/');
define('DIR_CONFIG', '/var/www/user_name/data/www/site_name/system/config/');
define('DIR_CACHE', '/var/www/user_name/data/www/site_name/storage/cache/');
define('DIR_DOWNLOAD', '/var/www/user_name/data/www/site_name/storage/download/');
define('DIR_LOGS', '/var/www/user_name/data/www/site_name/storage/logs/');
define('DIR_MODIFICATION', '/var/www/user_name/data/www/site_name/storage/modification/');
define('DIR_SESSION', '/var/www/user_name/data/www/site_name/storage/session/');
define('DIR_UPLOAD', '/var/www/user_name/data/www/site_name/storage/upload/');
define('DIR_CATALOG', '/var/www/user_name/data/www/site_name/catalog/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');

However, there is a method that allows minimizing the number of actions when transferring a site to a new hosting. Let’s explore the standard content of the config.php file and possible improvements.

Example: universal configuration file config.php
/var/www/user_name/data/www/site_name/config.php
<?php
$host = $_SERVER['HTTP_HOST'];

// HTTP
define('HTTP_SERVER', 'http://'.$host.'/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/');
$dir = dirname(__FILE__);

// DIR
define('DIR_APPLICATION', $dir.'/catalog/');
define('DIR_SYSTEM', $dir.'/system/');
define('DIR_IMAGE', $dir.'/image/');
define('DIR_STORAGE', DIR_SYSTEM . 'storage/');
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/theme/');
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
define('DIR_CACHE', DIR_STORAGE . 'cache/');
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
define('DIR_LOGS', DIR_STORAGE . 'logs/');
define('DIR_MODIFICATION', DIR_STORAGE . 'modification/');
define('DIR_SESSION', DIR_STORAGE . 'session/');
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php

Here and in subsequent examples, user_name is the name of your hosting user, and site_name is your domain name

Example: universal configuration file admin/config.php
/var/www/user_name/data/www/site_name/admin/config.php
<?php
$host = $_SERVER['HTTP_HOST'];

// HTTP
define('HTTP_SERVER', 'http://'.$host.'/admin/');
define('HTTP_CATALOG', 'http://'.$host.'/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/admin/');
define('HTTPS_CATALOG', 'https://'.$host.'/');
$dir = dirname(dirname(__FILE__));

// DIR
define('DIR_APPLICATION', $dir.'/admin/');
define('DIR_SYSTEM', $dir.'/system/');
define('DIR_IMAGE', $dir.'/image/');
define('DIR_STORAGE', DIR_SYSTEM . 'storage/');
define('DIR_CATALOG', $dir.'/catalog/');
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/template/');
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
define('DIR_CACHE', DIR_STORAGE . 'cache/');
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
define('DIR_LOGS', DIR_STORAGE . 'logs/');
define('DIR_MODIFICATION', DIR_STORAGE . 'modification/');
define('DIR_SESSION', DIR_STORAGE . 'session/');
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php

Note: in the simplified approach, the method __DIR__ is used, which automatically determines the path to the current directory. This makes the code more flexible and reduces the need for manual path updates when transferring to another hosting.

Configuration settings for OpenCart 2.x

If you have OpenCart 2.x installed and are planning to move your online store to a new hosting, you may need to make changes to configuration files such as config.php and admin/config.php. These files require updating host addresses, directory paths, and database parameters. However, there is a method that simplifies this process and minimizes the number of necessary actions.

Example: universal configuration file config.php
/var/www/user_name/data/www/site_name/config.php
<?php
$host = $_SERVER['HTTP_HOST'];

// HTTP
define('HTTP_SERVER', 'http://'.$host.'/admin/');
define('HTTP_CATALOG', 'http://'.$host.'/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/admin/');
define('HTTPS_CATALOG', 'https://'.$host.'/');
$dir = dirname(dirname(__FILE__));

// DIR
define('DIR_APPLICATION', $dir.'/admin/');
define('DIR_SYSTEM', $dir.'/system/');
define('DIR_LANGUAGE', $dir.'/admin/language/');
define('DIR_TEMPLATE', $dir.'/admin/view/template/');
define('DIR_CONFIG', $dir.'/system/config/');
define('DIR_IMAGE', $dir.'/image/');
define('DIR_CACHE', $dir.'/system/storage/cache/');
define('DIR_DOWNLOAD', $dir.'/system/storage/download/');
define('DIR_LOGS', $dir.'/system/storage/logs/');
define('DIR_MODIFICATION', $dir.'/system/storage/modification/');
define('DIR_UPLOAD', $dir.'/system/storage/upload/');
define('DIR_CATALOG', $dir.'/catalog/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php

Example: universal configuration file admin/config.php
/var/www/user_name/data/www/site_name/admin/config.php
<?php
$host = $_SERVER['HTTP_HOST'];

// HTTP
define('HTTP_SERVER', 'http://'.$host.'/admin/');
define('HTTP_CATALOG', 'http://'.$host.'/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/admin/');
define('HTTPS_CATALOG', 'https://'.$host.'/');
$dir = dirname(dirname(__FILE__));

// DIR
define('DIR_APPLICATION', $dir.'/admin/');
define('DIR_SYSTEM', $dir.'/system/');
define('DIR_LANGUAGE', $dir.'/admin/language/');
define('DIR_TEMPLATE', $dir.'/admin/view/template/');
define('DIR_CONFIG', $dir.'/system/config/');
define('DIR_IMAGE', $dir.'/image/');
define('DIR_CACHE', $dir.'/system/storage/cache/');
define('DIR_DOWNLOAD', $dir.'/system/storage/download/');
define('DIR_LOGS', $dir.'/system/storage/logs/');
define('DIR_MODIFICATION', $dir.'/system/storage/modification/');
define('DIR_UPLOAD', $dir.'/system/storage/upload/');
define('DIR_CATALOG', $dir.'/catalog/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php

Configuration file for OpenCart 1.5.x

If you have an older version of OpenCart 1.5.x installed and are planning to move your online store to a new hosting, you may need to make changes to configuration files such as config.php and admin/config.php. These files require updating host addresses, directory paths, and database parameters.

Example: universal configuration file config.php
/var/www/user_name/data/www/site_name/config.php
<?php
// HTTP
$host = $_SERVER['HTTP_HOST'];
define('HTTP_SERVER', 'http://'.$host.'/');
define('HTTP_IMAGE', 'http://'.$host.'/image/');
define('HTTP_ADMIN', 'http://'.$host.'/admin/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/');
define('HTTPS_IMAGE', 'https://'.$host.'/image/');

// DIR
$dir = dirname(__FILE__);
define('DIR_APPLICATION', $dir . '/catalog/');
define('DIR_SYSTEM', $dir . '/system/');
define('DIR_DATABASE', $dir . '/system/database/');
define('DIR_LANGUAGE', $dir . '/catalog/language/');
define('DIR_TEMPLATE', $dir . '/catalog/view/theme/');
define('DIR_CONFIG', $dir . '/system/config/');
define('DIR_IMAGE', $dir . '/image/');
define('DIR_CACHE', $dir . '/system/cache/');
define('DIR_DOWNLOAD', $dir . '/download/');
define('DIR_LOGS', $dir . '/system/logs/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php
Example: universal configuration file admin/config.php
/var/www/user_name/data/www/site_name/admin/config.php
<?php
// HTTP
$host = $_SERVER['HTTP_HOST'];
define('HTTP_SERVER', 'http://'.$host.'/');
define('HTTP_IMAGE', 'http://'.$host.'/image/');
define('HTTP_ADMIN', 'http://'.$host.'/admin/');

// HTTPS
define('HTTPS_SERVER', 'https://'.$host.'/');
define('HTTPS_IMAGE', 'https://'.$host.'/image/');

// DIR
$dir = dirname(__FILE__);
define('DIR_APPLICATION', $dir . '/catalog/');
define('DIR_SYSTEM', $dir . '/system/');
define('DIR_DATABASE', $dir . '/system/database/');
define('DIR_LANGUAGE', $dir . '/catalog/language/');
define('DIR_TEMPLATE', $dir . '/catalog/view/theme/');
define('DIR_CONFIG', $dir . '/system/config/');
define('DIR_IMAGE', $dir . '/image/');
define('DIR_CACHE', $dir . '/system/cache/');
define('DIR_DOWNLOAD', $dir . '/download/');
define('DIR_LOGS', $dir . '/system/logs/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_DATABASE', 'your_database_name');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
<?php