diff --git a/include/mysqli.php b/include/mysqli.php
index 4049050e6615b7d7afc8e2e60f8baf40bf2e48a0..2ec03daeea2d9afa840e4038a7536156b01a0cdb 100644
--- a/include/mysqli.php
+++ b/include/mysqli.php
@@ -39,18 +39,24 @@ function db_connect($host, $user, $passwd, $options = array()) {
         return NULL;
 
     $port = ini_get("mysqli.default_port");
+    $socket = ini_get("mysqli.default_socket");
     if (strpos($host, ':') !== false) {
-        list($host, $port) = explode(':', $host);
+        list($host, $portspec) = explode(':', $host);
         // PHP may not honor the port number if connecting to 'localhost'
-        if (!strcasecmp($host, 'localhost'))
-            // XXX: Looks like PHP gethostbyname() is IPv4 only
-            $host = gethostbyname($host);
-        $port = (int) $port;
+        if ($portspec && is_numeric($portspec)) {
+            if (!strcasecmp($host, 'localhost'))
+                // XXX: Looks like PHP gethostbyname() is IPv4 only
+                $host = gethostbyname($host);
+            $port = (int) $portspec;
+        }
+        elseif ($portspec) {
+            $socket = $portspec;
+        }
     }
 
     // Connect
     $start = microtime(true);
-    if (!@$__db->real_connect($host, $user, $passwd, null, $port)) # nolint
+    if (!@$__db->real_connect($host, $user, $passwd, null, $port, $socket)) # nolint
         return NULL;
 
     //Select the database, if any.
diff --git a/setup/inc/class.installer.php b/setup/inc/class.installer.php
index 22f06ee0352862045d94e5010c108088270b2c7f..61741a5b7fa1e83d38a94baeb5d8f06e4401df32 100644
--- a/setup/inc/class.installer.php
+++ b/setup/inc/class.installer.php
@@ -81,9 +81,7 @@ class Installer extends SetupWizard {
 
         // Support port number specified in the hostname with a colon (:)
         list($host, $port) = explode(':', $vars['dbhost']);
-        if ($port && (!is_numeric($port) || !((int)$port)))
-            $this->errors['db'] = 'Database port number must be a number';
-        elseif ($port && ($port < 1 || $port > 65535))
+        if ($port && is_numeric($port) && ($port < 1 || $port > 65535))
             $this->errors['db'] = 'Invalid database port number';
 
         //MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!)