Dear developers, I've solved the original problem, but if anyone has a docker image that can run this I'd be very grateful. I need help with a very old application.
I'm setting up a virtual machine environment for an old application. If you plan to help, please read carefully.
I have an old application that is about to be discarded because we are doing a rewrite, but the old application still needs support, and it is running very old versions of PHP and MYSQL. The code below should test whether the database connection is working properly.
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; }
The code went wrong and gave me the following error message:
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
If I use mysqli_connect
in the same code block, everything works fine, but the project is using mysql_functions. The application runs fine on staging and production servers, I tried copying the settings onto my virtual machine and this was the dockerfile that used to work, but some recent security updates caused it to not work.
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"]
I just need to get it running. It would be perfect if it could be done using docker, but I think that image is outdated. Any help is greatly appreciated. I can provide you with the env and .ini settings. I don't want to paste too much into the question.
I tried everything, looked at .ini and .env and all the Linux settings. It seems that the mysql socket is not set up correctly, however the command line connection mysql -uroot -p
is normal.
The problem ended up being a typo. I had to update my
.env
file to changeDB_HOST="localhost:3306"
toDB_HOST="127.0.0.1:3306"
and then it It's ready to work. Hope this helps anyone.