Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

Recommended Posts

近段时间手头有个PHP的源码,对它挺感兴趣所以就用Docker运行了PHP8的容器,代码运行起来之后发现数据库无法访问,根据报错信息看出是MySQL的扩展没启用,百度溜达了好久也没找到一个帖子讲明白如何启用扩展,自己摸索了半天终于搞明白,在这里分享给一下

安装扩展的教程在文档中有记录,根据文档描述镜像中已经内置了许多常用的扩展,只是没有安装,且文档中写出了操作扩展的命令

image

我下载的镜像是PHP8版本:docker pull php:8.0-fpm,容器起名为php8

进入到容器中,执行php -m命令,可以看到打印出mysqlnd,查看该扩展所在位置

[root@localhost webs]# docker exec -it php8 /bin/bash
root@8e288e13b95c:/var/www/html# php -m
root@8e288e13b95c:/var/www/html# find / -name mysqlnd

执行install命令安装mysqlnd,然后再次查看该扩展所在位置,会发现多了一个目录

root@8e288e13b95c:/var/www/html# docker-php-ext-install mysqlnd
root@8e288e13b95c:/var/www/html# find / -name mysqlnd

移动到多出来的目录中,查看与MySQL相关的文件,会看到mysqli,这个才是真正要安装的扩展,执行安装

root@8e288e13b95c:/var/www/html# cd /usr/src/php/ext
root@8e288e13b95c:/usr/src/php/ext# ls -l | grep mysql
root@8e288e13b95c:/usr/src/php/ext# docker-php-ext-install ./mysqli

至此安装完成,退出容器重启后重启MySQL扩展就可以使用了

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...