无法在linux成功搭建起hu60 php5.4.45版本

在linux下,因为我找不到静态编译的php5.4.45版本,所以我用了docker

我不太想用mysql,因为在docker-compose里面,让其他服务访问它,不容易,再说mysql的版本也固定不下来,老是升级

____

我在看 db.php 的时候,发现该网站可以使用 sqlite 来作为数据库

但是当我启动时,我发现它还是报错:

“”“
错误代码:14
错误信息:SQLSTATE[HY000] [14] unable to open database file
错误发生在 /var/www/html/class/db.php 的第 235 行
错误追踪信息:
#0 /var/www/html/class/db.php(235): PDO->__construct('sqlite:/var/www...')
#1 /var/www/html/class/db.php(287): db::conn(true)
#2 /var/www/html/class/db.php(333): db->pdo(true)
#3 /var/www/html/class/db.php(363): db->sqlexec(true, 'SELECT id as to...', Array)
#4 /var/www/html/class/bbs.php(427): db->select('id as topic_id', 'bbs_topic_meta', 'WHERE ctime>171...', 0, 21)
#5 /var/www/html/page/index/index.php(11): bbs->newTopicList(21, 0, 'WHERE ctime>171...')
#6 /var/www/html/q.php(74): include('/var/www/html/p...')
#7 {main}
”“”

___

我的docker-compose设置以及tiger_bbs版本可以看以下 repository 的 readme file:

https://gitlab.com/yingshaoxo/tiger_bbs_php5.4.45#docker-compose

"""
version: "3.9"

services:
  old_php:
    image: php:5.4.45-apache
    #network_mode: "host"        
    ports:
      - '7071:80'
    volumes:
      - .:/var/www/html:rw
    restart: always
"""
回复列表(8|隐藏机器人聊天)
  • @Ta / 1天前 / /

    @yingshaoxo,你要给/var/www/html/db文件夹写入权限(chmod 0777 /var/www/html/db)。不过其实程序早就不支持sqlite了,因为我后来写了很多MySQL专属语法,用sqlite肯定会报SQL语法错误,你得自己改。

  • @Ta / 1天前 / /

    此外,这里有支持php 8.1的版本。注意:不支持php 8.2。
    https://github.com/hu60t/hu60wap6
    数据库必须使用mysql或者与之兼容的mariadb等分支。

  • @Ta / 1天前 / /

    @yingshaoxo,docker 拉取镜像时指定版本号,就能固定版本了吧

    网络设置也不麻烦吧,实在不行用 host 模式?性能损耗也更少些?

  • @Ta / 1天前 / /
    @老虎会游泳


    谢谢,改了db folder permission后,原错误确实消失了。


    后来我自己建了一个新的sqlite的db文件,现在主页可以访问了:
    https://gitlab.com/yingshaoxo/tiger_bbs_php5.4.45/-/blob/main/db/sqlite.sql_command?ref_type=heads
    https://gitlab.com/yingshaoxo/tiger_bbs_php5.4.45/-/blob/main/db/test.db3?ref_type=heads

    但无法注册用户,会报错。


    新的错误:

    错误代码:22
    错误信息:数据库写入错误,SQL预处理失败。
    错误发生在 /var/www/html/class/user.php 的第 416 行
    错误追踪信息:
    #0 /var/www/html/page/user/reg.php(30): user->reg('yingshaoxo', 'password', 'yingshaoxo@gmai...')
    #1 /var/www/html/q.php(74): include('/var/www/html/p...')
    #2 {main}


                $rs = $db->prepare('SELECT `active`,`uid`,`name`,`mail`,`sid`,`sidtime`,`regtime`,`acctime`' . ($getinfo ? ',`info`' : '') . ' FROM `' . DB_A . 'user` WHERE `sid`=?');

                $x_getinfo = $getinfo;
            }
            if (!$rs || !$rs->execute(array($sid))) throw new PDOException('数据库查询失败,SQL' . ($rs ? '执行' : '预处理') . '失败。', $rs ? 21 : 22);
            $data = $rs->fetch(db::ass);

    ______


    > 以下不是重点:

    我不太懂php的程序,感觉编译器太难固定了,我之前找到一个5.7MB的x86_linux静态编译的Python3.2程序,感觉就挺好用:
    https://gitlab.com/yingshaoxo/yingshaoxo_alpine_x86_system/-/blob/main/python?ref_type=heads

    我感觉如果我有时间的话,都想用python重写一遍简单的wap论坛了,完全脱离docker,sql,javascript,php,就简单的自实现的http server + file read/write + html + css
  • @Ta / 1天前 / /

    @yingshaoxo,你要用文件系统,代替数据库? 这些事情咋办:

    • 全文搜索?
    • 增量备份?
    • 帖子阅读量,帖子文件要频繁保存?
    • 保存时程序炸了/系统崩了/断电关机/……,帖子丢失?
    • 一个帖子,只能同时一人访问?(前一个阅读量 + 1 并保存后,下一个才能继续 + 1 再保存)
  • @Ta / 1天前 / /
    @无名啊

    1. 全文搜索不是事儿
    2. 增量备份没必要,一般纯文本的数据不会超过3GB
    3. 一天备份一次
    4. 服务器程序一般不会断电
    5. SSD的速度很快了,人类几乎没有延时感。同时纯文本要做memory dict cache,保存最近访问的1000个文章,快如闪电。

    我之前用Python写过类似的数据库,只不过没写中心化的pipe line,多进程会出问题:
    https://github.com/yingshaoxo/auto_everything/blob/dev/auto_everything/database.py#L357

    其中一点代码:
    “”“
            if self.use_sqlite == False:
                self.database_txt_file_path = self._disk.join_paths(self.database_base_folder, f"{self.database_name}.txt")
                if (not self._disk.exists(self.database_txt_file_path)):
                    self._io.write(self.database_txt_file_path, "")
    ”“”

    “”“
        def raw_search(self, one_row_json_string_handler: Callable[[str], dict[str, Any] | None]) -> Iterator[dict[str, Any]]:
            """
            one_row_json_string_handler: a_function to handle search process. If it returns None, we'll ignore it, otherwise, we'll add the return value into the result list.
            ```
                def one_row_json_string_handler(item: str) -> dict[str, Any] | None:
                    return json.loads(item)
                    #return None
            ```
            """
            if self.global_multiprocessing_shared_dict != None:
                self._wait_until_unlock()
                self.global_multiprocessing_shared_dict[self._the_key_for_the_lock_of_memory_data] = True

                for row in self.global_multiprocessing_shared_dict[self._the_key_for_memory_data]:
                    json_string = self._json.dumps(row, sort_keys=True).strip()
                    result = one_row_json_string_handler(json_string)
                    if (result != None):
                        yield result

                self.global_multiprocessing_shared_dict[self._the_key_for_the_lock_of_memory_data] = False
                return

            if self.use_sqlite:
                for row in self.sql_cursor.execute(
                    f"SELECT * FROM {self._sql_table_name}"
                ):
                    result = one_row_json_string_handler(row[0])
                    if (result != None):
                        yield result
            else:
                with open(self.database_txt_file_path, "r") as file_stream:
                    previous_position = None
                    while True:
                        current_position = file_stream.tell()
                        line = file_stream.readline()
                        if previous_position == current_position:
                            # reach the end
                            break
                        previous_position = current_position
                        if (line.strip() == ""):
                            # ignore empty line
                            continue

                        if (line.startswith('#')):
                            # ignore deleted line
                            continue

                        result = one_row_json_string_handler(line)
                        if (result != None):
                            yield result
    ”“”
  • @Ta / 1天前 / /

    @yingshaoxo

    之前用mysql的时候,安装需要导入一个sql的命令文本文件,来实现table的建立。但现在换成sqlite,难道只能手工建表了吗

    或者你把mysql的建表语句修改为兼容sqlite然后写一个程序去执行这些sql就能自动建出来了。

    从我切换到mysql以来,后续所有涉及数据库的代码修改都没有考虑sqlite兼容性,所以这个sqlite连接功能其实基本不能用,只是还没从代码里删掉而已。

  • @Ta / 1天前 / /

    @yingshaoxo,你是说,帖子放内存里,就不会慢了,是吧。。

    • 单线程提供服务,并发量会不会很低。。
    • 多线程数据同步,会不会很麻烦?
    • 啥时候落盘一次数据呢?此时整个服务都要卡住吗。。
    • 后续扩展功能,会不会还不如写 SQL 方便。。
添加新回复
回复需要登录