Fellow Developers, I have solved the initial issue, but if anyone has a docker image that would run this, i would much appreciate it. I need help with a very old app.
I am setting up a VM environment for an old application. Please read through carefully if you intend to help.
I have an old application that is soon to be thrown away as we are working on the rewrite, however the old application still needs to be supported and it runs very old version of PHP and MYSQL. The code below is supposed to test that the db connection works.
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 breaks giving me
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 in the same code block i use mysqli_connect istead everything works, but the project runs on mysql_functions. The app works on the staging and production servers and i tried to copy the setup on my VM, also here is the dockerfile that used to work, but recently some security updates stopped it from working.
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"]
All i need is to get this up and running. If it can be done with docker that would be perfect but i think that image is long deprecated. Any help is very much appreciated. I can provide you with the env and .ini setup. I didnt want to pase too much in the question.
I tried everything, i looked throught .ini and .env and all the linux setup. looks like mysql socket is not setting up properly, however the cmd connection works fine mysql -uroot -p works fine
The issue ended up being a typo thing. i had to update my
.envand instead ofDB_HOST="localhost:3306"i had to putDB_HOST="127.0.0.1:3306"and it worked. Hope this helps anyone