I have an issue where my PHP version is affecting a project I'm trying to run inside of a docker container.
When I run php -v
in the container I get this.
PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct 3 2016 13:00:37)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
My goal is to make the "php -v" command results look like below. Which it does right now on a working machine.
PHP 5.5.30 (cli) (built: Dec 12 2015 21:28:27)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Suhosin v0.9.36, Copyright (c) 2007-2014, by SektionEins GmbH
The reason I need to downgrade is something changed in regards to how the date() function works between these two versions that causes a crashing error in the PDO Extention, something to this tune (exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2017-01-13 23:47:31 UTC')
Changing the PHP version seems to fix it. To save time since its a huge project and I need to just deploy it to active users I need to switch the PHP version down.
My docker file looks like below.
FROM ubuntu:14.04
MAINTAINER Joe Astrahan <****>
VOLUME ["/var/www"]
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y \
apache2 \
curl \
libcurl3 \
libcurl3-dev \
php5 \
php5-cli \
libapache2-mod-php5 \
php5-gd \
php5-json \
php5-ldap \
php5-mysql \
php5-pgsql \
php5-curl
COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/run /usr/local/bin/run
RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite
EXPOSE 80
CMD ["/usr/local/bin/run"]
The run file is below:
#!/bin/bash
set -e
PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/apache2/php.ini
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/cli/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/apache2/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/cli/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/apache2/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/cli/php.ini
source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND
I am not sure how to install a particular version of php 5.5.30 since it always installs 5.9. I looked around on Google and couldn't find anything. Any help is appreciated!
If needed below is my docker-compose.yml file.
version: '2'
services:
dblive:
image: mysql:5.7.17
volumes:
- ./db_data_live:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ****
MYSQL_DATABASE: ****
MYSQL_USER: ****
MYSQL_PASSWORD: ****
dbdev:
image: mysql:5.7.17
volumes:
- ./db_data_dev:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ****
MYSQL_DATABASE: ****
MYSQL_USER: ****
MYSQL_PASSWORD: ****
phpmyadmin:
depends_on:
- dblive
- dbdev
image: phpmyadmin/phpmyadmin
environment:
PMA_ARBITRARY : 1
restart: always
ports:
- "8081:80"
web:
build: ./
depends_on:
- dblive
- dbdev
volumes:
- ./web:/var/www
- ./config/php.ini:/usr/local/etc/php/php.ini
- ./config/apache_default.conf:/etc/apache2/sites-enabled/000-default.conf
restart: always
ports:
- "80:80"
- "443:443"
environment:
TEST: testenviromentvar
I blurred out the passwords but just put your own to make the database work. Note, use docker exec 8d8a115f6d6b php -v
to test php version in the container. Where the jumble of #'s is the container id after you run docker-compose up etc...
For those curious the line in PHP it currently errors, its below.
$class->created = date('Y-m-d H:i:s', time());
$validated = $class->save();
I get this exact error message, exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2017-01-13 23:47:31 UTC' for column 'created' at row 1' in /var/www/public_html/devsite/vendor/php-activerecord/php-activerecord/lib/Connection.php:322
The error is because of the UTC, but for some reason this doesn't cause an issue in 5.5.30?