2017-02-09 1 views
1

Codeigniter (버전 : 3.05), PHP (버전 : 5.6.24), mysql : 10.1.16 mariaDB). 로컬 서버 : 운영 체제 = OSX, PHP 버전 = 5.6.24, mysql 버전 = 10.1.16 mariaDB. 호스팅 서버 : 운영 체제 = FreeBSD (유닉스), phpversion = 5.6.30, mysql 버전 = : 5.5.38-log. 이 사이트는 로컬 서버에서 정상적으로 작동합니다. 하지만 아래와 같이 라이브 서버에서는 오류가 발생합니다. Codeigniter 오류 Live server : mysqli :: real_connect() : (HY000/2002) : 연결이 거부되었습니다.

A PHP Error was encountered 

    Severity: Warning 

    Message: mysqli::real_connect(): (HY000/2002): Connection refused 

    Filename: mysqli/mysqli_driver.php 

    Line Number: 202 

    Backtrace: 

    File: /home/sv-001/www/user/myweb/application/third_party/MX/Loader.php 
    Line: 109 
    Function: DB 

    File: /home/sv-001/www/user/myweb/application/third_party/MX/Loader.php 
    Line: 65 
    Function: initialize 

    File: /home/sv-001/www/user/myweb/application/modules/home/controllers/Home.php 
    Line: 8 
    Function: __construct 

    File: /home/sv-001/www/user/myweb/index.php 
    Line: 294 
    Function: require_once 

나는 내 데이터베이스 파일 (database.php) 몇 시간을 확인되었습니다하지만 호스트 이름, 사용자 이름, 암호, 데이터베이스 이름과 관련이 오류를 찾을 수 없습니다. 당신의 database.php 대신 퍼팅에서

if($_SERVER['HTTP_HOST'] == "localhost" OR $_SERVER['HTTP_HOST'] == "testurl.com") 
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/myfolder/myfolder2/'; 
else if($_SERVER['HTTP_HOST'] == "testurl.com" OR $_SERVER['HTTP_HOST'] == "testurl.com") 
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/myfolder2/'; 
else 
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; 

$config['index_page'] = 'index.php'; 
//$config['index_page'] = ''; 

$config['uri_protocol'] = 'REQUEST_URI'; 

$config['url_suffix'] = ''; 

$config['language'] = 'english'; 

$config['charset'] = 'UTF-8'; 

$config['enable_hooks'] = FALSE; 

$config['subclass_prefix'] = 'MY_'; 
$config['composer_autoload'] = FALSE; 


$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; 

$config['allow_get_array'] = TRUE; 
$config['enable_query_strings'] = FALSE; 
$config['controller_trigger'] = 'c'; 
$config['function_trigger'] = 'm'; 
$config['directory_trigger'] = 'd'; 

$config['log_threshold'] = 0; 

$config['log_path'] = ''; 

$config['log_file_extension'] = ''; 

$config['log_file_permissions'] = 0644; 
$config['log_date_format'] = 'Y-m-d H:i:s'; 

$config['error_views_path'] = ''; 

$config['cache_path'] = ''; 

$config['cache_query_string'] = FALSE; 

$config['sess_driver'] = 'files'; 
$config['sess_cookie_name'] = 'ci_session'; 
$config['sess_expiration'] = 7200; 
//$config['sess_save_path'] = NULL; 
$config['sess_save_path'] = APPPATH . 'cache'; 
$config['sess_match_ip'] = FALSE; 
$config['sess_time_to_update'] = 300; 
$config['sess_regenerate_destroy'] = FALSE; 

$config['cookie_prefix'] = ''; 
$config['cookie_domain'] = ''; 
$config['cookie_path']  = '/'; 
$config['cookie_secure'] = FALSE; 
$config['cookie_httponly'] = FALSE; 

$config['standardize_newlines'] = FALSE; 

$config['global_xss_filtering'] = FALSE; 

$config['csrf_protection'] = FALSE; 
$config['csrf_token_name'] = 'csrf_test_name'; 
$config['csrf_cookie_name'] = 'csrf_cookie_name'; 
$config['csrf_expire'] = 7200; 
//$config['csrf_regenerate'] = TRUE; 
$config['csrf_regenerate'] = FALSE; 
$config['csrf_exclude_uris'] = array(); 
$config['compress_output'] = FALSE; 

$config['time_reference'] = 'local'; 

$config['rewrite_short_tags'] = FALSE; 

$config['proxy_ips'] = ''; 
+1

config/database.php 파일을 표시하십시오 –

+0

mariadb 서비스가 실행 중이십니까? 기본 포트에서 작동합니까? –

+0

"mysqli :: real_connect() : (HY000/2002)"를 사용하여 Google에서 처음 2 번 조회 : [first] (http://stackoverflow.com/questions/29928109/getting-error-mysqlireal-connect-hy000-2002- no-such-file-or-directory-wh), [second] (http://stackoverflow.com/questions/13769504/mysqlimysqli-hy000-2002-cant-connect-to-local-mysql-server-through-sock). 그 이상의 결과가 보인다면 설정이 틀릴 수도 있습니다. "hostname"에'localhost' 또는'127.0.0.1'을 사용하십시오. DB 서비스가 실행 중인지 확인하십시오. 어쩌면 둘 다. – Nukeface

답변

1

는 "localhost" "127.0.0.1"를 넣어보십시오 : 아래 그림과 같이

database.php 파일

$db['default'] = array(
     'dsn' => '', 
     'hostname' => 'testurl.com', 
     'username' => 'username', 
     'password' => 'password', 
     'database' => 'dbname', 
     'dbdriver' => 'mysqli', 
     'dbprefix' => '', 
     'pconnect' => FALSE, 
     'db_debug' => (ENVIRONMENT !== 'production'), 
     'cache_on' => FALSE, 
     'cachedir' => '', 
     'char_set' => 'utf8', 
     'dbcollat' => 'utf8_general_ci', 
     'swap_pre' => '', 
     'encrypt' => FALSE, 
     'compress' => FALSE, 
     'stricton' => FALSE, 
     'failover' => array(), 
     'save_queries' => TRUE 
); 

config.php 파일입니다. 이것은 대부분의 경우에 적용됩니다.

여전히 오류가 발생하면 database.php 파일을 게시하십시오.

0

다음과 같이 시도하십시오. 로컬 서버의 경우.

$active_group = 'default'; 
$query_builder = TRUE; 

$db['default'] = array(
    'dsn'  => '', 
    'hostname' => 'localhost', 
    'username' => '<user>', 
    'password' => '<password>', 
    'database' => '<database>', 
    'dbdriver' => 'mysqli', 
    'dbprefix' => '', 
    'pconnect' => FALSE, 
    'db_debug' => (ENVIRONMENT !== 'production'), 
    'cache_on' => FALSE, 
    'cachedir' => '', 
    'char_set' => 'utf8', 
    'dbcollat' => 'utf8_general_ci', 
    'swap_pre' => '', 
    'encrypt' => FALSE, 
    'compress' => FALSE, 
    'stricton' => FALSE, 
    'failover' => array(), 
    'save_queries' => TRUE 
); 
+0

로컬 서버에는 문제가 없습니다. 그러나 서버에 파일을 업로드하면 "SQLSTATE [HY000] [2002] Connection refused"라는 오류 메시지가 표시됩니다. – ero

+0

편집 된 답변을 시도하십시오. 여기에서 잘 작동합니다. –

0

'hostname' => 'testurl.com' 대신 'hostname' => 'localhost'을 사용하십시오. 라이브 서버에 코드를 업로드하더라도 호스트 이름은 "localhost"로 남아 있습니다.

+0

'hostname'=> 'localhost'를 만들었습니다. 나는 여전히 같은 오류가있다. – ero

+0

호스트 이름에 'localhost'대신 '127.0.0.1'을 사용하십시오. –

관련 문제