I have codeigniter (php framework) running on an nginx webserver on my local machine (Mac OSX 10.8).
I am trying to connect to an external mySQL database hosted with mediaTemple.
When loading in the database helper in codeigniter, with all the correct details, l keep getting:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
The contents of my database.php file is:
$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;
The contents of my nginx.conf file is:
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/*;
}
And the contents of my sites/olliejennings.conf file is:
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;
}
}
NB: the php website works fine if i don't try and connect to the external database.
EDIT - Found differences is the mySQL settings between nginx and apache
This is what phpinfo() throws out when l connect to the database on apache:

This is what the phpinfo() throws out when using nginx as l can't connect to the database:

Also the socket for mySQL when using nginx is wrong as it is not located at
/var/mysql/mysql.sock
But instead located at:
/temp/mysql.sock
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.
$db['default']['port'] = 3306;to the db conf file. Maybe it needs to be explicitly set for some reason. Also, maybe try writing a little script with native php mysqli and running it on nginx to make certain it's an issue with nginx.