+## SQL Server version
121.0.2100.60
+## Client operating system
Ubuntu 16.04
+## PHP version
7.0
+## Microsoft ODBC Driver version
3.21
+## Problem description
Had A docker container working just fine. I rebuilt the container today and it no longer works. Sending pdo requests is no longer functioning correctly.
error when trying to pdo into my server:
Error!: could not find driver
Error in php -m:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_sqlsrv.so' - /usr/lib/php/20151012/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
+## Expected behavior and actual behavior
Should return data from my database. Instead returns error.
+## Repro code - my dockerfile
FROM ubuntu:16.04
RUN apt-get update -y
# install curl and git
RUN apt-get install -y curl git
# install apache
RUN apt-get install -y apache2
RUN apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml zip unzip php-zip
RUN apt-get install -y libapache2-mod-php7.0
RUN apt-get install -y php7.0-sybase
RUN apt-get update
RUN apt-get install -y apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y install msodbcsql mssql-tools
RUN apt-get install -y unixodbc-utf16
RUN apt-get install -y unixodbc-dev-utf16
# install driver sqlsrv
RUN pecl install sqlsrv
RUN echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN pecl install pdo_sqlsrv
RUN echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
#load driver sqlsrv
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini
# install composer
RUN curl -sS https://getcomposer.org/installer | php
COPY ./composer.json /var/www/html/composer.json
RUN mv /composer.phar /var/www/html/composer.phar
RUN cd /var/www/html && php /var/www/html/composer.phar install
RUN cd /
#RUN php composer-setup.php
#RUN php -r "unlink('composer-setup.php');"
#RUN mv composer.phar /usr/local/bin/composer
# I know I install some of this stuff twice. Needs cleanup. Regardless, it was working.
# install ODBC Driver
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
RUN ACCEPT_EULA=Y apt-get install -y unixodbc-dev mssql-tools
#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN exec bash
# install locales
RUN apt-get install -y locales && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
COPY ./propel.yml /var/www/html/propel.yml
COPY ./.htaccess /var/www/html
COPY ./schema.xml /var/www/html
RUN cd /var/www/html \
&& ./vendor/bin/propel build \
&& ./vendor/bin/propel config:convert \
&& mkdir ./model \
&& mv ./generated-classes/model/* ./model/ \
&& rm -rf ./generated-classes
RUN a2enmod rewrite
COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf
COPY ./apache2.conf /etc/apache2/apache2.conf
EXPOSE 80
WORKDIR /var/www/html/
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Here is the code I'm running to call pdo:
try {
$dbh = new PDO('192.168.23.765:1433', 'sa', 'SorryYouCantHaveMyPassword');
foreach($dbh->query('SELECT * from Maintenance') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Maybe #736 can help you in finding a solution
@Crobitaille I was going through the issues but realized you just closed this. Hopefully you have resolved this issue already.
Yes I solved the issue. Here is a working dockerfile (Minus propel and such) for anyone chasing a similar solution.
FROM ubuntu:16.04
# install curl and git
RUN apt-get update -y
RUN apt-get install -y curl git
# install PHP
RUN apt-get install -y php7.0 php7.0-dev php7.0-xml
# install apt-transport-https (required for curling the msodbcsql packages. doesn't come w/ container)
RUN apt-get update
RUN apt-get install -y apt-transport-https
# add msodbcsql packages
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install msodbcsql and associated tools
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
# add msssql-tools to path
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN apt-get install -y unixodbc-dev
# add extension info to ini files
RUN echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
RUN echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
# install sqlsrv
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
# install apache
RUN apt-get install -y libapache2-mod-php7.0 apache2
RUN a2dismod mpm_event
RUN a2enmod mpm_prefork
RUN a2enmod php7.0
# add sqlsrv extension info to apache2/php.ini
RUN echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
RUN echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
# copy 30-pdo_sqlsrv.ini to some locations for loading
RUN cp /etc/php/7.0/cli/conf.d/30-pdo_sqlsrv.ini /etc/php/7.0/fpm/conf.d
RUN cp /etc/php/7.0/cli/conf.d/30-pdo_sqlsrv.ini /etc/php/7.0/apache2/conf.d
# install locales (sqlcmd will have a fit if you don't have this)
RUN apt-get install -y locales && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
EXPOSE 80
WORKDIR /var/www/html/
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Most helpful comment
Yes I solved the issue. Here is a working dockerfile (Minus propel and such) for anyone chasing a similar solution.