Unable to enable php-ast in docker php 7.3.5 - php

I'm trying to install php-ast extension to my project. This is my Dockerfile:
FROM php:7.3.5-apache
RUN apt-get -yqq update \
&& apt-get -yqq install --no-install-recommends libzip-dev git
COPY ./php/php.ini /usr/local/etc/php/
COPY ./php/php_errors.log /var/log/php_errors.log
COPY ./apache/error.log /var/log/apache2/error.log
COPY ./apache/access.log /var/log/apache2/access.log
COPY . /var/www/html
COPY ./apache/vhost.conf /etc/apache2/sites-available/000-default.conf
COPY ./mysql/my.cnf /etc/mysql/conf.d/my.cnf
COPY --from=composer:1.6.5 /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y libmcrypt-dev libtool zip unzip \
&& docker-php-ext-install mysqli pdo_mysql \
&& pecl install mcrypt-1.0.2 ast-1.0.1 \
&& docker-php-ext-enable mcrypt ast \
&& a2enmod rewrite
RUN chown -R www-data:www-data /var/www/html
After I run this build and try to use ast, I get message that ast is not enabled. Would someone explain in plain English how should I install this extension on Docker php 7.3.5 or higher?
Update
This is my docker-compose.yml:
version: "3"
services:
appnew:
build: .
depends_on:
- mysqlnew
ports:
- 8080:80
networks:
- app-net
volumes:
- ..:/var/www/html
container_name: appnew
mysqlnew:
image: mysql:5.6
ports:
- 13317:3306
environment:
- MYSQL_DATABASE=XXXX_db
- MYSQL_ROOT_PASSWORD=XXXXXX
volumes:
- mysql57data:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf
# - ./mysql/logs:/var/log/mysql/
networks:
- app-net
container_name: mysqlnew
networks:
app-net:
driver: "bridge"
volumes:
mysql57data:
driver: "local"
And this is my php.ini:
date.timezone = Europe/London
memory_limit = 128M
post_max_size = 500M
upload_max_filesize = 200M
error_log = /var/log/php_errors.log
error_reporting = -1
log_errors = 1

I used this Dockerfile
FROM php:7.3.5-apache
RUN apt-get -yqq update \
&& apt-get -yqq install --no-install-recommends libzip-dev git
RUN apt-get update && apt-get install -y libmcrypt-dev libtool zip unzip \
&& docker-php-ext-install mysqli pdo_mysql \
&& pecl install mcrypt-1.0.2 ast-1.0.1 \
&& docker-php-ext-enable mcrypt ast \
&& a2enmod rewrite
ran the build and wrote php -m and this is the output
[PHP Modules]
ast
Core
ctype
curl
date
dom
fileinfo
and you so many lines after that.

Related

"deploy-php-ext-configure" in /bin/sh missing when building docker laravel image

i am trying to build image and container from a project but i am having an issue when trying to build the image. the project is a template and I already have a project using this template in my computer. I would like to know how to solve it and understand a little more. I hope somebody would help me.
here is the error log when I run the command "docker build -t my-payments ." :
#7 200.3 /bin/sh: 1: deploy-php-ext-configure: not found
here is the "docker-compose.yml" :
version: '3.8'
services:
web:
container_name: laravel-template-...
build:
context: ./
dockerfile: ./Dockerfile.dev
volumes:
- .:/var/www-data
environment:
- PORT=80
ports:
- 81:80
links:
- db
db:
image: postgres:13
container_name: db-lrv-postgres-...
restart: always
environment:
POSTGRES_DB: db-lrv-postgres
POSTGRES_USER: ...
POSTGRES_PASSWORD: ...
TZ: ...
PORT: ${PORT:-5432}
ports:
- "5434:5432"
here is "Dockerfile" :
FROM php:7.4-fpm
USER root
WORKDIR /var/www-data
RUN apt-get update \
# gd
&& apt-get install -y --no-install-recommends build-essential openssl nginx libfreetype6-dev libjpeg-dev libpng-dev libwebp-dev zlib1g-dev libzip-dev gcc g++ make nano vim unzip curl git jpegoptim optipng pngquant gifsicle locales libonig-dev nodejs npm libpq-dev \
#custom-dependencies installed: libpq-dev
&& deploy-php-ext-configure gd \
&& deploy-php-ext-install gd \
# gmp
&& apt-get install -y --no-install-recommends libgmp-dev \
&& deploy-php-ext-install gmp \
# pdo
&& deploy-php-ext-install pdo \
# pdo_pgsql
&& deploy-php-ext-install pgsql pdo_pgsql mbstring \
# opcache
&& deploy-php-ext-enable opcache \
# zip
&& deploy-php-ext-install zip \
&& apt-get autoclean -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/pear/
COPY . /var/www-data
COPY ./deploy/php.ini /usr/local/etc/php/conf.d/local.ini
COPY ./deploy/nginx.conf /etc/nginx/nginx.conf
RUN mv .env.production .env
RUN chmod +rwx /var/www-data
RUN chmod -R 777 /var/www-data
#RUN npm install -g npm#latest
RUN npm install
RUN npm run prod
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --working-dir="/var/www-data"
RUN composer dump-autoload --working-dir="/var/www-data"
RUN php artisan optimize
EXPOSE 8080
RUN ["chmod", "+x", "./deploy/post_deploy.sh"]
CMD [ "sh", "./deploy/post_deploy.sh" ]

How to enable php extensions when using the image php:7.2-apache with docker-compose?

I want to run a apache webserver with php extension inside container using docker compose as deployment.
My compose file looks like this:
version: '3.1'
services:
php:
image: php:7.2-apache
ports:
- 8089:80
volumes:
- ./php/www:/var/www/html/
how can I enable the following extensions.
apache2
php7.2
php-xdebug
php7.2-mcrypt
php-apcu
php-apcu-bc
php7.2-json
php-imagick
php-gettext
php7.2-mbstring
First of all you can run php -m in php container to see installed and enabled modules.
You can edit your docker-compose.yml like this:
version: '3.1'
services:
php:
# image: php:7.2-apache # remember to comment this line
build: .
ports:
- 8089:80
volumes:
- ./php/www:/var/www/html/
Create a file called Dockerfile beside docker-compose.yml with the following contents:
FROM php:7.2-apache
# then add the following `RUN ...` lines in each separate line, like this:
RUN pecl install xdebug && docker-php-ext-enable xdebug
...
Finally, let's go one by one:
apache2
Is installed.
php7.2
Is enabled.
php-xdebug
Add Dockerfile:
RUN pecl install xdebug && docker-php-ext-enable xdebug
php7.2-mcrypt
Add to Dockerfile:
RUN apt-get install libmcrypt-dev
RUN pecl install mcrypt && docker-php-ext-enable mcrypt
php-apcu
Add to Dockerfile:
RUN pecl install apcu && docker-php-ext-enable apcu
php-apcu-bc
Add to Dockerfile:
RUN pecl install apcu_bc
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN echo 'extension=apc.so' >> /usr/local/etc/php/php.ini
php7.2-json
Is installed.
php-imagick
Add to Dockerfile:
RUN apt install -y libmagickwand-dev --no-install-recommends && \
pecl install imagick && docker-php-ext-enable imagick
php-gettext
RUN docker-php-ext-install gettext && \
docker-php-ext-enable gettext
php7.2-mbstring
Is enabled.

Docker with sqlsrv php73 extension failing to load

I made a docker LAMP Stack Container including PHP7.3 and some extensions that I need to run my web application on. Recently I needed to include the sqlsrv extension to establish a connection to a MS SQL Server, it worked well for 1 day and when I restarted my Docker Desktop it rebuilt itself and now it's not working anymore even if I try to delete the images and volumes of the container and rebuild it.
When I run docker-compose up I get these two errors :
PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory))
PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Here are my config files :
docker-compose.yml
version: '3.8'
volumes:
datafiles:
services:
mysql:
image: mysql:8.0.0
container_name: mysql8
environment:
- MYSQL_ROOT_PASSWORD=x
- MYSQL_TCP_PORT=x
volumes:
- datafiles:/var/lib/mysql
- "./scripts:/docker-entrypoint-initdb.d"
restart: always
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: x
PMA_USER: x
PMA_PASSWORD: x
ports:
- "8081:80"
website:
container_name: php73
build:
context: .
dockerfile: Dockerfile
image: rootkitty/lamp-quietal-webapp:latest
env_file:
- .env
ports:
- 80:80
- 443:443
depends_on:
- mysql
Dockerfile the COPY php.ini permit to add
extension=sqlsrv.so
extension=pdo_sqlsrv.so
FROM php:7.3-apache
#Install git and MySQL extensions for PHP
ENV ACCEPT_EULA=Y
ENV MYSQL_DBHOST=x
ENV MYSQL_DBPORT=x
ENV MYSQL_DBUSER=x
ENV MYSQL_DBPASS=x
ENV MYSQL_DBNAME=x
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install MS ODBC Driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev \
&& pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& echo "extension=pdo_sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini \
&& echo "extension=sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-sqlsrv.ini \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN apt-get update && \
apt-get install -y \
git libzip-dev \
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
I followed the official Microsoft documentations to make up my Dockerfile :
https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#debian17
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-on-debian
And gathered some codes on different GitHub pages. How can I achieve a proper sqlsrv installation on my docker container?
So, multiple things were not configured in the right way in my Dockerfile, here's the patch :
FROM php:7.3-apache
# Env variables
ENV ACCEPT_EULA=y
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
#Install ODBC Driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update
# Install sqlsrv
RUN apt-get update
RUN apt-get install -y wget
RUN wget http://ftp.br.debian.org/debian/pool/main/g/glibc/multiarch-support_2.24-11+deb9u4_amd64.deb && \
dpkg -i multiarch-support_2.24-11+deb9u4_amd64.deb
RUN apt-get -y install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
# Install webapp extension
RUN apt-get update && \
apt-get install -y \
git libzip-dev libicu-dev\
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
In fact I had to install multiarch-support for a reason that I still ignore despite it being a required package (if it's one ?). Then, I had to install the ODBC Drivers which I completely forgot in the first place.
From now everything seems to be working fine

How to install yarn and npm on a PHP docker image (symfony 4 project)

Im working on a symfony 4/posgresql project. Im using docker toolbox.
I need to install webpack encore bundle on symfony, but in order to do this, i need to add yarn and npm to my project. Somebody told me i should add theses 2 installations on my php docker container, but i don't know which command to add (im a linux/docker beginner).
This is my docker-compose.yaml :
services:
database:
image: postgres:11-alpine
ports:
- "5432:5432"
volumes:
- 'boeki_database:/var/lib/postgresql/data'
environment:
POSTGRES_PASSWORD: root
database_pg_admin:
image: dpage/pgadmin4
ports:
- "8001:80"
environment:
PGADMIN_DEFAULT_EMAIL: root#root.com
PGADMIN_DEFAULT_PASSWORD: root
application:
build:
context: .
dockerfile: ./docker/Dockerfile
working_dir: /var/www/project
ports:
- "8000:80"
volumes:
- ./:/var/www/project:rw,cached
- ./docker/http/000-default.conf:/etc/apache2/sites-enabled/000-default.conf:rw,cached
volumes:
boeki_database: {}
And this is my Dockerfile :
RUN apt-get update && \
apt-get install -y libpq-dev g++ zlib1g-dev libicu-dev vim git zip
#GD
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
poppler-utils
RUN rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install -j "$(nproc)" gd pdo_pgsql
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql intl zip opcache
RUN pecl install redis && echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini
RUN a2enmod rewrite
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Thanks for the help !
according to https://classic.yarnpkg.com/en/docs/install#debian-stable which provides some commands to follow, adding the following to your dockerfile should work (disclaimer: I'm not extremely familiar with docker)
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && sudo apt-get install -y yarn
(the -y removes the questions)

Warning Message: session_start(): Failed to read session data: user (path: )

I am trying to setup an existing project with Docker. The project is in codeigniter and uses memcached as the driver to set the session.
I created a Docker environment with php:7.1.8-apache and installed all the neccesary packages.
I am now getting this error on the page
Warning Message: session_start(): Failed to read session data: user (path: localhost:11211:128)
I searched this on the internet a lot and tried out many things but nothing works.
I have a file in application/libraries/Session/drivers/Session_memcached_driver.php
This is the the piece of code from where the error is generating but i am not sure what exactly it is.
public function read($session_id)
{
if (isset($this->_memcached) && $this->_get_lock($session_id))
{
// Needed by write() to detect session_regenerate_id() calls
$this->_session_id = $session_id;
$session_data = (string) $this->_memcached->get($this->_key_prefix.$session_id);
$this->_fingerprint = md5($session_data);
return $session_data;
}
return $this->_fail();
}
Here are my Docker Configurations:
FROM php:7.1.8-apache
# AUTHOR
MAINTAINER Development
# INSTALLING PACKAGES
RUN apt-get update && apt-get install -y \
git \
pkg-config \
build-essential \
libmemcached-dev \
libmemcached-tools \
libicu-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libfreetype6 \
libfontconfig \
libxml2-dev \
vim \
nano \
mysql-client \
libldap2-dev \
wget
RUN apt-get clean
# Extension PHP
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install intl
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install mcrypt
RUN docker-php-ext-install zip
RUN docker-php-ext-install exif
RUN docker-php-ext-install soap
RUN docker-php-ext-install opcache
RUN docker-php-ext-install iconv
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# APCu
RUN pecl channel-update pecl.php.net
RUN pecl install apcu
RUN echo "extension=apcu.so" > /usr/local/etc/php/conf.d/apcu.ini
# Enable PHP 7
RUN a2enmod rewrite && a2enmod headers && a2enmod expires
RUN a2enmod php7
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# SETUP VIRTUAL HOST
COPY .docker/sites-available/default-vhost.conf /etc/apache2/sites-available/default-vhost.conf
COPY .docker/sites-available/my-vhost.conf /etc/apache2/sites-available/my-vhost.conf
RUN a2dissite 000-default.conf
RUN a2ensite default-vhost.conf
RUN a2ensite my-vhost.conf
# Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Memcached
RUN apt-get update
RUN apt-get install -y pkg-config build-essential libmemcached-dev
RUN git clone https://github.com/php-memcached-dev/php-memcached.git
RUN cd php-memcached && git checkout php7 && phpize && ./configure --disable-memcached-sasl && make && make install
RUN echo 'extension = memcached.so' > /usr/local/etc/php/conf.d/memcached.ini
# ALIASES
RUN echo "alias ll='ls -l'" >> /root/.bashrc
RUN echo "alias la='ls -l'" >> /root/.bashrc
# COPY THE WORKING DIRECTORY
COPY . /var/www/myproject
# MANAGE DIRECTORY PERMISSIONS
RUN chown -R www-data:www-data /var/www/myproject
# SERVER RESTART
RUN service apache2 restart
And this is docker-compose.yml settings
version: '3'
services:
app:
build:
context: .
dockerfile: .docker/Dockerfile
container_name: gaz-container
image: gaz-docker
ports:
- "80:80"
volumes:
- .:/var/www/gaz
links:
- memcached:memcached
- mysql:mysql
memcached:
image: memcached
ports:
- "11211:11211"
mysql:
container_name: mysql
image: mysql:5.6
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
Can anyone please direct me what could be the issue here?
OMG.
After doing lot of searching i finally managed to get this working.
Thanks to dukebody. This post helped me to get hints about what i was doing wrong.
https://stackoverflow.com/a/27657937/4342075
The thing is i am actually creating multiple docker containers as you can see in the question in docker-compose.yml file. One of which is memcached. And i was trying to use memcached in the main container which is app.
What i was doing wrong is, i was using localhost:11211 to access memcached.
I just changed
$config['sess_save_path'] = 'localhost:11211:128'
To
$config['sess_save_path'] = 'memcached:11211';
And guess what it worked!!!

Categories