親愛的開發者們, 我已經解決了最初的問題,但如果有人有一個可以運行這個的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
是正常的。
問題最終是一個打字錯誤。我必須更新我的
.env
文件,將DB_HOST="localhost:3306"
改為DB_HOST="127.0.0.1:3306"
,然後它就可以工作了。希望這對任何人有幫助。