Xibo 1.7.x with PHP7 (patch)


#1

A lot of people have been asking for a PHP7-compatible version of Xibo. We are also in that boat, as we want to upgrade our Ubuntu 14.04 server to Ubuntu 16.04 and continue to use officially supported PHP packages. Version 1.7.x is not compatible in its current state, and the devs haven’t released a stable version of 1.8.x that has PHP7 support yet.

I’ve come up with a patch that makes the following minimal changes:

  • Change mysql API calls to mysqli, which is included in PHP7
  • Fix session handling stuff to work with the memcached session handler with PHP7’s more strict string checking

It’s an (unsupported) option for people who are otherwise stuck. The patch is very small and makes the minimal required changes to install and run Xibo 1.7.x on PHP7. I’ve tested this on our prod Xibo 1.7.8/PHP 5.5.9 as well as our dev Xibo 1.7.9/PHP 7.0.8 with a couple-of-slide campaign. Hopefully it will help other people and eventually lead to some sort of official patch showing up.

diff -urN ../xibo-cms-1.7.9/config/config.class.php ./config/config.class.php
--- ../xibo-cms-1.7.9/config/config.class.php   2016-09-27 03:56:49.000000000 -0700
+++ ./config/config.class.php   2016-11-30 16:47:34.409919758 -0800
@@ -589,7 +589,7 @@
      */
     function CheckMySQL()
     {
-        return extension_loaded("mysql");
+        return extension_loaded("mysqli");
     }

     /**
diff -urN ../xibo-cms-1.7.9/lib/app/session.class.php ./lib/app/session.class.php
--- ../xibo-cms-1.7.9/lib/app/session.class.php 2016-09-27 03:56:49.000000000 -0700
+++ ./lib/app/session.class.php 2016-11-30 15:57:03.906584412 -0800
@@ -150,7 +150,7 @@
                        if (!$row = $sth->fetch()) {
                                // Key doesn't exist yet
                                $this->isExpired = 0;
-                               return settype($empty, "string");
+                               return (string)$empty;
                        }

                        // What happens if the UserAgent has changed?
@@ -189,12 +189,16 @@
                        // Either way - update this SESSION so that the security token is NULL
                        $this->securityToken = null;

-                       return($row['session_data']);
+                       if ($row["session_data"]) {
+                               return($row['session_data']);
+                       } else {
+                               return (string)$empty;
+                       }
                }
                catch (Exception $e) {
                        Debug::LogEntry('error', 'Error reading session: ' . $e->getMessage());

-                       return settype($empty, "string");
+                       return (string)$empty;
                }
        }

diff -urN ../xibo-cms-1.7.9/modules/module_db_mysql.php ./modules/module_db_mysql.php
--- ../xibo-cms-1.7.9/modules/module_db_mysql.php       2016-09-27 03:56:49.000000000 -0700
+++ ./modules/module_db_mysql.php       2016-11-30 16:46:28.736980737 -0800
@@ -28,7 +28,7 @@
     function connect_db($dbhost, $dbuser, $dbpass)
     {
         //open the db link
-        if (!$this->connection = @mysql_connect($dbhost, $dbuser, $dbpass))
+        if (!$this->connection = @mysqli_connect($dbhost, $dbuser, $dbpass))
             return false;

         return true;
@@ -37,10 +37,10 @@
     function select_db($dbname)
     {
        //select out the correct db name
-        if (!mysql_select_db($dbname, $this->connection))
+        if (!mysqli_select_db($this->connection, $dbname))
             return false;

-        return $this->query("SET NAMES 'utf8'", $this->connection);
+        return $this->query("SET NAMES 'utf8'");
     }

     /**
@@ -64,7 +64,7 @@
             $SQL = $this->SqlPrintF($args);

         // Run the query
-        if(!$result = mysql_query($SQL, $this->connection))
+        if(!$result = mysqli_query($this->connection, $SQL))
        {
             $this->error_text = 'The query [' . $SQL . '] failed to execute';
             return false;
@@ -76,23 +76,23 @@
     // gets the current row from the result object
     function get_row($result)
     {
-        return mysql_fetch_row($result);
+        return mysqli_fetch_row($result);
     }

     function get_assoc_row($result)
     {
-        return mysql_fetch_assoc($result);
+        return mysqli_fetch_assoc($result);
     }

     //gets the number of rows
     function num_rows($result)
     {
-        return mysql_num_rows($result);
+        return mysqli_num_rows($result);
     }

     function escape_string($string)
     {
-       return mysql_real_escape_string($string);
+       return mysqli_real_escape_string($this->connection, $string);
     }

     /**
@@ -189,7 +189,7 @@
     {
         try
        {
-            $this->error_text .= mysql_error($this->connection);
+            $this->error_text .= mysqli_error($this->connection);

             return $this->error_text;
         }
@@ -223,7 +223,7 @@
     {
         if (is_string($s))
         {
-            return mysql_real_escape_string($s, $this->connection);
+            return mysqli_real_escape_string($this->connection, $s);
         }
         else if (is_null($s))
         {
@@ -239,7 +239,7 @@
         }
         else
         {
-            return mysql_real_escape_string(strval($s), $this->connection);
+            return mysqli_real_escape_string($this->connection, strval($s));
         }
     }
 }

You can apply it by running (from the Xibo web directory):

patch -p0 < /path/to/saved/xibo-php7.patch


Xibo CMS 1.8 with PHP7?
PHP7 on alpine containers - request for advance testing
#2

Hi, kloostec!
Can you explain exacrly, what i have Tod doch with your patch?

What rxactly you mean: xibo web Directory

Please contact me, behause 1.8.9 don‘t work on my web server.


#3

1.8.9 works with PHP7 directly. You don’t need to make patches to have that work!