Cách cấu hình file config.php để chạy trên hosting trong OpenCart

Trong bài viết  này mình sẽ hướng dẫn các bạn thay đổi lại file config.php để có thể chạy trên mọi domain hosting khác nhau mà không cần thay đổi lại đường dẫn file.

Bước 1: Mở file config.php  tìm đoạn code:

// HTTP
define('HTTP_SERVER', 'http://localhost/opencart/');

// HTTPS
define(‘HTTPS_SERVER’, ‘http://localhost/opencart/’);

// DIR
define(‘DIR_APPLICATION’, ‘D:/wamp/www/opencart/catalog/’);
define(‘DIR_SYSTEM’, ‘D:/wamp/www/opencart/system/’);
define(‘DIR_DATABASE’, ‘D:/wamp/www/opencart/system/database/’);
define(‘DIR_LANGUAGE’, ‘D:/wamp/www/opencart/catalog/language/’);
define(‘DIR_TEMPLATE’, ‘D:/wamp/www/opencart/catalog/view/theme/’);
define(‘DIR_CONFIG’, ‘D:/wamp/www/opencart/system/config/’);
define(‘DIR_IMAGE’, ‘D:/wamp/www/opencart/image/’);
define(‘DIR_CACHE’, ‘D:/wamp/www/opencart/system/cache/’);
define(‘DIR_DOWNLOAD’, ‘D:/wamp/www/opencart/download/’);
define(‘DIR_LOGS’, ‘D:/wamp/www/opencart/system/logs/’);

// DB
define(‘DB_DRIVER’, ‘mysqli’);
define(‘DB_HOSTNAME’, ‘localhost’);
define(‘DB_USERNAME’, ‘root’);
define(‘DB_PASSWORD’, ”);
define(‘DB_DATABASE’, ‘opencart’);
define(‘DB_PREFIX’, ‘oc_’);

Thay bằng đoạn code mới:
// HTTP
define('HTTP', $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/');
define('HTTP_SERVER', 'http://'.HTTP);
// HTTPS
define('HTTPS_SERVER', 'http://'.HTTP);

// DIR
define(‘BASE_DIR’, realpath(dirname(__FILE__)));
define(‘DIR_APPLICATION’, BASE_DIR.’/catalog/’);
define(‘DIR_SYSTEM’, BASE_DIR.’/system/’);
define(‘DIR_DATABASE’, BASE_DIR.’/system/database/’);
define(‘DIR_LANGUAGE’, BASE_DIR.’/catalog/language/’);
define(‘DIR_TEMPLATE’, BASE_DIR.’/catalog/view/theme/’);
define(‘DIR_CONFIG’, BASE_DIR.’/system/config/’);
define(‘DIR_IMAGE’, BASE_DIR.’/image/’);
define(‘DIR_CACHE’, BASE_DIR.’/system/cache/’);
define(‘DIR_DOWNLOAD’, BASE_DIR.’/download/’);
define(‘DIR_LOGS’, BASE_DIR.’/system/logs/’);

// DB
define(‘DB_DRIVER’, ‘mysqli’);
define(‘DB_HOSTNAME’, ‘localhost’);
define(‘DB_USERNAME’, ‘root’);
define(‘DB_PASSWORD’, ”);
define(‘DB_DATABASE’, ‘opencart’);
define(‘DB_PREFIX’, ‘oc_’);