title: Connecting to external mysql database with codeigniter running on a local nginx server
body: <p>I have codeigniter (php framework) running on an nginx webserver on my local machine (Mac OSX 10.8).</p>
  
  <p>I am trying to connect to an external mySQL database hosted with mediaTemple.</p>
  
  <p>When loading in the database helper in codeigniter, with all the correct details, l keep getting:</p>
  
  <pre><code>  A Database Error Occurred
    Unable to connect to your database server using the provided settings.
  </code></pre>
  
  <p>The contents of my database.php file is:</p>
  
  <pre><code>  $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;
  </code></pre>
  
  <p>The contents of my nginx.conf file is:</p>
  
  <pre><code>  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/*;
    }
  </code></pre>
  
  <p>And the contents of my sites/olliejennings.conf file is:</p>
  
  <pre><code>  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;
         }
     }
  </code></pre>
  
  <p>NB: the php website works fine if i don't try and connect to the external database.</p>
  
  <hr>
  
  <p><strong>EDIT - Found differences is the mySQL settings between nginx and apache</strong></p>
  
  <p>This is what phpinfo() throws out when l connect to the database on apache:</p>
  
  <p><img src="https://i.stack.imgur.com/uZ44r.png" alt="mySQL config when using apache"></p>
  
  <p>This is what the phpinfo() throws out when using nginx as l can't connect to the database:</p>
  
  <p><img src="https://i.stack.imgur.com/zLjVr.png" alt="mySQL config when using nginx"></p>
  
  <p>Also the socket for mySQL when using nginx is wrong as it is not located at</p>
  
  <pre><code>/var/mysql/mysql.sock
  </code></pre>
  
  <p>But instead located at:</p>
  
  <pre><code>/temp/mysql.sock
  </code></pre>
  
  <p>I have chnaged these settings in the php.ini file, yet they don't appear to be read by php when using nginx, it appears to ignore anything l change within that file.</p>