Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用运行在本地nginx服务器上的codeigniter连接到外部mysql数据库_Php_Mysql_Codeigniter_Nginx_External - Fatal编程技术网

Php 使用运行在本地nginx服务器上的codeigniter连接到外部mysql数据库

Php 使用运行在本地nginx服务器上的codeigniter连接到外部mysql数据库,php,mysql,codeigniter,nginx,external,Php,Mysql,Codeigniter,Nginx,External,我在本地机器(MacOSX 10.8)上的nginx Web服务器上运行codeigniter(php框架) 我正在尝试连接到由mediaTemple托管的外部mySQL数据库 在codeigniter中加载数据库帮助程序时,如果有所有正确的详细信息,我会不断得到: A Database Error Occurred Unable to connect to your database server using the provided settings. mydatabase.php

我在本地机器(MacOSX 10.8)上的nginx Web服务器上运行codeigniter(php框架)

我正在尝试连接到由mediaTemple托管的外部mySQL数据库

在codeigniter中加载数据库帮助程序时,如果有所有正确的详细信息,我会不断得到:

  A Database Error Occurred
  Unable to connect to your database server using the provided settings.
mydatabase.php文件的内容是:

  $db['default']['hostname'] = 'external-db.#######.gridserver.com';
  $db['default']['username'] = '#######';
  $db['default']['password'] = '#######';
  $db['default']['database'] = '#######_olliejennings';
  $db['default']['dbdriver'] = 'mysql';
  $db['default']['dbprefix'] = '';
  $db['default']['pconnect'] = TRUE;
  $db['default']['db_debug'] = TRUE;
  $db['default']['cache_on'] = FALSE;
  $db['default']['cachedir'] = '';
  $db['default']['char_set'] = 'utf8';
  $db['default']['dbcollat'] = 'utf8_general_ci';
  $db['default']['swap_pre'] = '';
  $db['default']['autoinit'] = TRUE;
  $db['default']['stricton'] = FALSE;
我的nginx.conf文件的内容是:

  daemon off;

  user olliejennings staff;

  worker_processes 2;
  pid /opt/boxen/data/nginx/nginx.pid;

  events {
     worker_connections 1024;
  }

  http {
     include mime.types;
     default_type application/octet-stream;

     log_format main '$remote_addr - $remote_user [$time_local] $status '
                     '"$request" $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "http_x_forwarded_for"';

     access_log /opt/boxen/log/nginx/access.log main;
     error_log  /opt/boxen/log/nginx/error.log debug;

     sendfile on;

     tcp_nopush  on;
     tcp_nodelay off;

     gzip              on;
     gzip_http_version 1.0;
     gzip_comp_level   2;
     gzip_proxied      any;

     upstream www-upstream-pool {
          server unix:/tmp/php-fpm.sock;
     }

     server {
          listen      80;
          server_name localhost;

          location / {
               root   /opt/boxen/config/nginx/public;
          }
     }

     include /opt/boxen/config/nginx/sites/*;
  }
  server {
       server_name      olliejennings.dev;
       root         /Users/olliejennings/Code/olliejennings;
       index        index.php index.html index.htm;

       location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
         expires max;
         log_not_found off;
         add_header Pragma public;
         add_header Cache-Control "public, must-revalidate, proxy-revalidate";
       }

       location / {
         # Check if a file exists, or route it to index.php
         try_files $uri $uri/ /index.php;
       }

       location ~ \.php$ {
         include fastcgi_php_default.conf;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root/index.php;
       }
   }
我的站点/olliejennings.conf文件的内容是:

  daemon off;

  user olliejennings staff;

  worker_processes 2;
  pid /opt/boxen/data/nginx/nginx.pid;

  events {
     worker_connections 1024;
  }

  http {
     include mime.types;
     default_type application/octet-stream;

     log_format main '$remote_addr - $remote_user [$time_local] $status '
                     '"$request" $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "http_x_forwarded_for"';

     access_log /opt/boxen/log/nginx/access.log main;
     error_log  /opt/boxen/log/nginx/error.log debug;

     sendfile on;

     tcp_nopush  on;
     tcp_nodelay off;

     gzip              on;
     gzip_http_version 1.0;
     gzip_comp_level   2;
     gzip_proxied      any;

     upstream www-upstream-pool {
          server unix:/tmp/php-fpm.sock;
     }

     server {
          listen      80;
          server_name localhost;

          location / {
               root   /opt/boxen/config/nginx/public;
          }
     }

     include /opt/boxen/config/nginx/sites/*;
  }
  server {
       server_name      olliejennings.dev;
       root         /Users/olliejennings/Code/olliejennings;
       index        index.php index.html index.htm;

       location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
         expires max;
         log_not_found off;
         add_header Pragma public;
         add_header Cache-Control "public, must-revalidate, proxy-revalidate";
       }

       location / {
         # Check if a file exists, or route it to index.php
         try_files $uri $uri/ /index.php;
       }

       location ~ \.php$ {
         include fastcgi_php_default.conf;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root/index.php;
       }
   }
注意:如果我不尝试连接到外部数据库,php网站工作正常


编辑-发现的差异是nginx和apache之间的mySQL设置

这是当我连接到apache上的数据库时phpinfo()抛出的内容:

这是phpinfo()在使用nginx时抛出的问题,因为我无法连接到数据库:

另外,当使用nginx时,mySQL的套接字是错误的,因为它不位于

/var/mysql/mysql.sock
而是位于:

/temp/mysql.sock

我已经在php.ini文件中更改了这些设置,但是在使用nginx时,php似乎没有读取它们,它似乎忽略了我在该文件中更改的任何内容。

好的,所以我终于解决了这个问题

当我尝试使用本机php mysqli时,表明我收到了以下信息:

Connect failed: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
因此,为了解决这个问题,我做了以下工作:

  • 使用phpmyadmin连接到mysql数据库
  • 运行以下查询
    显示变量,如“旧密码”
  • 如果返回的是ON,那么我知道问题出在数据库上
  • 运行此查询以关闭此变量-
    SET SESSION old\u passwords=FALSE

  • 然后,我可以连接到我的mySQL数据库,而没有任何问题或代码更改。

    r您确定主机名不是本地主机吗?是否允许远程数据库接受远程连接?是的,允许数据库接受远程连接,我可以通过phpmyadmin连接到这个数据库,或者通过你是否三次检查用户名并通过?不应该有任何东西明确拒绝您的请求…尝试添加
    $db['default']['port']=3306
    到db conf文件。也许出于某种原因需要显式设置。另外,也许可以尝试用编写一个小脚本并在nginx上运行它,以确定这是nginx的问题。