Skip to content

Instantly share code, notes, and snippets.

@divinity76
Created March 12, 2023 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/c09ba2a168261e32a81d4d98dcbc335c to your computer and use it in GitHub Desktop.
Save divinity76/c09ba2a168261e32a81d4d98dcbc335c to your computer and use it in GitHub Desktop.
dockerfile old php mysql thingy..
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get -y full-upgrade;
RUN apt-get -y install apt-utils
RUN apt-get -y install default-mysql-server libmysqlclient-dev git make autoconf gcc re2c wget xz-utils tar file bison
RUN git clone -b 'PHP-7.3' --depth 1 https://github.com/php/php-src.git php56
# https://askubuntu.com/questions/1329414/why-is-my-global-h-from-libmysqlclient-dev-is-missing-in-ubuntu-20-04
#RUN touch /usr/include/mysql/my_global.h
#RUN apt-get install -y bison
# PHP5.5 (and older 5.6 but not 5.6.40) require bison 2.x...
#RUN \
#wget https://ftp.gnu.org/gnu/bison/bison-2.7.tar.xz && \
#tar -xvf bison-2.7.tar.xz && \
#cd bison-2.7/ && \
#chmod +x configure && \
#mkdir build && \
#./configure --prefix=/bison2 && \
#make -j $(nproc) && \
#make install && \
#chmod +x /bison2/bin/bison
#ENV PATH="/bison2/bin:$PATH"
RUN echo hi && \
cd 'php56' && \
./buildconf --force && \
./configure --disable-all --disable-cgi --enable-cli --enable-pdo --with-pdo-mysql=/usr/bin/mysql_config --with-mysqli=/usr/bin/mysql_config && \
make clean && \
make -j $(nproc);
RUN cp php56/sapi/cli/php /php
RUN /php --version
# probably not required in the Microsoft/Freexian php56 but we're on the vanilla php56
# Connect Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
# https://stackoverflow.com/a/50790434/1067003
RUN printf '[mysql]\ndefault-character-set=utf8\n\n[mysqld]\ncollation-server = utf8_unicode_ci\ncharacter-set-server = utf8' >> /etc/mysql/conf.d/charset.cnf
# again probably not needed in the Microsoft/Freexian php56, but we're on vanilla php56
# PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Command line code on line 1
RUN \
printf "[mysqld]\ndefault-authentication-plugin=mysql_native_password" >> /etc/mysql/mysql.conf.d/default-auth-plugin.cnf && \
service mysql start && \
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';" && \
mysql -e "UPDATE mysql.user SET plugin='auth_socket' WHERE User='root';" && \
mysql -e "SELECT user,authentication_string,plugin,host FROM mysql.user;" && \
service mysql stop;
RUN \
service mysql start && \
service mysql status && \
/php -r '$db = new PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8mb4", "root", "", \
array( \
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, \
PDO::ATTR_EMULATE_PREPARES => false, \
)); \
var_dump($db->query("CREATE DATABASE db;")); \
var_dump($db->query("CREATE TABLE db.t (c int);")); \
var_dump($db->query("alter table db.t add column c1 int")->fetchAll()); \
var_dump($db->query("SELECT 1")->fetchAll()); \
'
@divinity76
Copy link
Author

trying to build this crash with

 > [12/12] RUN service mysql start && service mysql status && /php -r '$db = new PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8mb4", "root", "", array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, )); var_dump($db->query("CREATE DATABASE db;")); var_dump($db->query("CREATE TABLE db.t (c int);")); var_dump($db->query("alter table db.t add column c1 int")->fetchAll()); var_dump($db->query("SELECT 1")->fetchAll()); ':
#15 7.753 object(PDOStatement)#2 (1) {
#15 7.753   ["queryString"]=>
#15 7.753   string(26) "CREATE TABLE db.t (c int);"
#15 7.753 }
#15 7.839 
#15 7.839 Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2053  in Command line code:1
#15 7.839 Stack trace:
#15 7.839 #0 Command line code(1): PDOStatement->fetchAll()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment