亲爱的开发者们, 我已经解决了最初的问题,但如果有人有一个可以运行这个的docker镜像,我会非常感激。 我需要帮助一个非常旧的应用程序。
我正在为一个旧应用程序设置一个虚拟机环境。如果你打算帮助,请仔细阅读。
我有一个即将被丢弃的旧应用程序,因为我们正在进行重写,但是旧应用程序仍然需要支持,并且它运行着非常旧版本的PHP和MYSQL。下面的代码应该测试数据库连接是否正常。
require_once("/var/www/html/class/autoload.php"); $database = $_ENV['DB_HOST']; $DBuser = $_ENV["MYSQL_USER"]; $DBpass = $_ENV["MYSQL_USER"]; $link = mysql_connect($database, $DBuser, $DBpass, null); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysql_error() . PHP_EOL; exit; }
代码出错,给我以下错误信息:
Warning: mysql_connect(): No such file or directory in /var/www/html/docker_build/test_db.php on line 10 Error: Unable to connect to MySQL. Debugging errno: No such file or directory
如果在同一个代码块中使用mysqli_connect
,一切都正常,但是该项目使用的是mysql_functions。该应用程序在暂存和生产服务器上运行正常,我尝试将设置复制到我的虚拟机上,这是以前工作的dockerfile,但最近一些安全更新导致它无法工作。
version: "3" services: webserver: build: context: ${DOCKER_BUILD_ROOT}/bin/${DOCKER_PHPVERSION} container_name: ${DOCKER_PHPVERSION} restart: 'always' ports: - "${HOST_MACHINE_UNSECURE_HOST_PORT}:80" - "${HOST_MACHINE_SECURE_HOST_PORT}:443" links: - database volumes: - ${DOCUMENT_ROOT-.}:/var/www/html - ${PHP_INI-./docker_build/config/php/php.ini}:/usr/local/etc/php/php.ini - ${VHOSTS_DIR-./docker_build/config/vhosts}:/etc/apache2/sites-enabled - ${APACHE_LOG_DIR-./docker_build/logs/apache2}:/var/log/apache2 # user: "1000:1000" user: root database: build: context: "${DOCKER_BUILD_ROOT}/bin/${DOCKER_DATABASE}" container_name: 'database' restart: 'always' ports: - "${DOCKER_LOCALHOST}:${HOST_MACHINE_MYSQL_PORT}:3306" volumes: - ${MYSQL_CONF_FILE-./docker_build/config/mysql/mysql.conf.d/mysqld.cnf}:/etc/mysql/mysql.conf.d/mysqld.cnf - ${MYSQL_DATA_DIR-./docker_build/data/mysql}:/var/lib/mysql - ${MYSQL_LOG_DIR-./docker_build/logs/mysql}:/var/log/mysql - ${MYSQL_INIT_DIR-./docker_build/config/mysql/ini}:/docker-entrypoint-initdb.d environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} phpmyadmin: image: phpmyadmin/phpmyadmin container_name: 'phpmyadmin' links: - database environment: PMA_HOST: database PMA_PORT: 3306 PMA_USER: ${MYSQL_USER} PMA_PASSWORD: ${MYSQL_PASSWORD} MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} ports: - '8080:80' volumes: - /sessions - ${PHP_INI-./docker_build/config/php/php.ini}:/usr/local/etc/php/conf.d/php-phpmyadmin.ini redis: container_name: 'redis' image: redis:latest ports: - "${DOCKER_LOCALHOST}:${HOST_MACHINE_REDIS_PORT}:6380"
FROM php:5.6-apache RUN apt-get -y update && apt-get upgrade -y # Install tools && libraries RUN apt-get -y install --fix-missing apt-utils nano wget dialog \ build-essential git curl libcurl3 libcurl3-dev zip \ libmcrypt-dev libsqlite3-dev libsqlite3-0 mysql-client \ zlib1g-dev libicu-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \ && rm -rf /var/lib/apt/lists/* # Composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # PHP5 Extensions RUN docker-php-ext-install curl \ && docker-php-ext-install tokenizer \ && docker-php-ext-install json \ && docker-php-ext-install mcrypt \ && docker-php-ext-install pdo_mysql \ && docker-php-ext-install pdo_sqlite \ && docker-php-ext-install mysql \ && docker-php-ext-install mysqli \ && docker-php-ext-install zip \ && docker-php-ext-install -j$(nproc) intl \ && docker-php-ext-install mbstring \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd \ && pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug # Enable apache modules RUN a2enmod rewrite headers RUN apt-get update && apt-get install -y \ mediainfo \ jhead \ imagemagick \ ffmpeg RUN usermod -u 1000 www-data EXPOSE 80 # initialize server script. designed to be run after volumes are mounted. # runs composer install and runs apache2 foreground. # ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] ENTRYPOINT ["./docker_build/config/server_ini.sh"]
我只需要让它运行起来。如果可以使用docker完成,那就太完美了,但我认为该镜像已经过时了。非常感谢任何帮助。我可以为你提供env和.ini的设置。我不想在问题中粘贴太多内容。
我尝试了一切,查看了.ini和.env以及所有的Linux设置。看起来mysql套接字没有正确设置,然而命令行连接mysql -uroot -p
是正常的。
P粉6931261152024-01-17 10:21:43
问题最终是一个打字错误。我不得不更新我的.env
文件,将DB_HOST="localhost:3306"
改为DB_HOST="127.0.0.1:3306"
,然后它就可以工作了。希望这对任何人有所帮助。