I'm working on a project were files stored on a remote server and this project is running on Docker.
I'm trying to enable Xdebug in PhpStorm but I can't made this working. The first problem is I can't reach the PHP executable inside my remote PHP Docker container.
For clarify : my PhpStorm IDE is on my locale machine, and my docker project is on a remote server.
Inside my remote container docker php path:
And when I'm trying to validate, it doesn't work properly:
; XDEBUG Extension
[xdebug]
xdebug.remote_enable = 1
xdebug.profiler_enable = 0
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable_trigger = 0
xdebug.show_local_vars = 0
xdebug.remote_port = 9003
xdebug.remote_host = host.docker.internal
xdebug.idekey = PHPSTORM
;xdebug.remote_log = "/var/www/web/var/log/xdebug.log"
xdebug.cli_color = 1
xdebug.extended_info = 1
Is there anyway to have Xdebug working in this configuration ?
Dockercompose
version: '3.0'
services:
apache:
container_name: colis_apache
build:
context: apache
args:
USER_UID: 1000
volumes:
- "../..:/var/www/colis:rw,cached"
- "./logs:/var/log/apache2/:rw"
depends_on:
- db
ports:
- "80:80"
- "443:443"
hostname: "colis.qangles.lan"
networks:
- colis-net
extra_hosts:
- "host.docker.internal:host-gateway"
db:
image: mariadb:10.1.45
container_name: colis_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: *****
MYSQL_USER: colis
MYSQL_PASSWORD: ****
volumes:
- "db_colis_data:/var/lib/mysql"
- "../..:/code:rw"
networks:
- colis-net
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: colis_phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: toor
ports:
- "8080:80"
networks:
- colis-net
volumes:
db_colis_data:
networks:
colis-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.12.2.0/24
Dockerfile
FROM php:7.3.20-fpm
RUN apt-get update && apt-get install -y \
libicu-dev \
zip \
curl \
libcurl4-openssl-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
zlib1g-dev \
libxml2-dev \
libxslt-dev \
libicu-dev \
wget \
curl \
zip \
git \
jpegoptim optipng \
cron
# opcache
RUN docker-php-ext-enable opcache
# Xdebug
RUN pecl install xdebug-3 apcu
RUN docker-php-ext-enable xdebug apcu
# PHP extensions
RUN docker-php-ext-install intl pdo_mysql mysqli calendar soap \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
exif \
gettext \
bcmath \
shmop \
sockets \
sysvmsg \
sysvsem \
sysvshm \
xsl
# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN mkdir -p /var/www/.composer
COPY php.ini /usr/local/etc/php/
COPY xdebug.ini /usr/local/etc/php/conf.d/
COPY openssl.cnf /usr/lib/ssl/
RUN mkdir -p /var/www/colis/var/log
RUN chown -R www-data:www-data /var/www
# Set timezone to UTC (as always)
RUN rm /etc/localtime \
&& ln -s /usr/share/zoneinfo/UTC /etc/localtime \
&& date \
&& printf "date.timezone=Europe/Paris\n" > $PHP_INI_DIR/conf.d/timezone.ini
#COPY files/crontab /etc/cron.d/distriartisan
# Change CMD to have cron running
RUN echo "#!/bin/sh\ncron\nphp-fpm" > /usr/bin/run
RUN chmod u+x /usr/bin/run
CMD ["run"]
# Use www-data with correct UID
ARG USER_UID=1000
RUN usermod -u $USER_UID www-data
# Mailcatcher
#RUN echo "sendmail_path = /usr/sbin/ssmtp -t" > /usr/local/etc/php/conf.d/sendmail.ini \
# && echo "mailhub=mail:25\nUseTLS=NO\nFromLineOverride=YES" > /etc/ssmtp/ssmtp.conf
WORKDIR /var/www/colis
you can use sail example to see better
docker-compose.yml
your Dockerfile should have this section
RUN apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd \
php8.1-curl \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
php8.1-ldap \
php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
php8.1-memcached php8.1-pcov php8.1-xdebug \
version: '3'
services:
laravel.test:
build:
context: .
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
XDEBUG: ${SAIL_DEBUG}
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
PHP_IDE_CONFIG: '${PHP_IDE_CONFIG}'
volumes:
- '.:/var/www/html'
networks:
- sail
then set these variable in .env file :
SAIL_XDEBUG_MODE=develop,debug
php.ini file :
[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
[XDebug]
zend_extension = xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
xdebug.idekey = VSC
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
and then create a server in phpStorm setting. with 0.0.0.0 ip and 9003 port.
Related
After success build container on docker, try running with docker-compose up -d, until here is okay. But try to run artisan CLI, I have an error with message Service "php" is not running container #1. This project using lumen framework. Before I'm using Windows for OS
this is my docker-compose.yml
version: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
image: appbilling-service
container_name: appbilling-api
volumes:
- app-data:/var/www/html
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
links:
- db
server:
image: nginx:1.23-alpine
container_name: appbilling-server
ports:
- 8100:80
volumes:
- app-data:/var/www/html
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- app
db:
image: mysql:8
container_name: mydb
command: --default-authentication-plugin=mysql_native_password
ports:
- 33061:3306
environment:
MYSQL_DATABASE: appbilling_test
MYSQL_USER: user
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root
volumes:
- db-data:/var/lib/mysql
- ./docker/mysql/my.cnf:/etc/mysql/my.cnf
- ./docker/mysql/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
volumes:
db-data:
app-data:
and this is my dockerfile
FROM composer:2 as vendor
COPY ./database ./database
COPY ./tests ./tests
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install \
--ignore-platform-reqs \
--no-interaction \
--no-plugins \
--no-scripts \
--prefer-dist
FROM php:7.4-fpm-alpine
COPY . /var/www/html
WORKDIR /var/www/html
COPY . .
COPY --from=vendor /app/vendor ./vendor/
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
RUN apk add --no-cache \
oniguruma-dev \
mysql-client \
libxml2-dev \
# If you have enabled gd plugin
# libpng-dev \
# libjpeg-turbo-dev \
# freetype-dev \
git \
zip \
unzip \
curl
RUN docker-php-ext-install \
bcmath \
mbstring \
pdo \
pdo_mysql \
tokenizer \
xml
# If you need to work with image manipulation.
# RUN docker-php-ext-configure gd --with-freetype --with-jpeg
# RUN docker-php-ext-install gd
RUN adduser www-data www-data
RUN chown -R www-data:www-data .
USER www-data
EXPOSE 9000
CMD ["php-fpm"]
I'm try to run lumen sevrice with port 8100 is run normally
Does anyone have any idea why the request time of my Laravel project is running very slow? I'm running the project on Docker and I use a Dockerfile and docker-compose.yml. I'm also using nginx
I have tried multiple things like Eager loading and artisan optimize but none of those seems to work.
I'm running this on a laptop with an i7-9750H and 16gb RAM.
This what my debugbar says:
Dockerfile in a folder named 'php':
FROM php:8.0-fpm-alpine
RUN apk add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
RUN chmod 777 /dev/stdout /dev/stderr
RUN apk --update add wget \
curl \
git \
grep \
build-base \
libmcrypt-dev \
libxml2-dev \
zlib-dev \
autoconf \
cyrus-sasl-dev \
libgsasl-dev \
composer \
supervisor \
libpng-dev \
freetype-dev \
libjpeg-turbo-dev \
libjpeg-turbo-utils \
openssh \
htop \
nano \
ghostscript \
imagemagick-dev \
libzip-dev \
wkhtmltopdf \
jpegoptim \
optipng \
pngquant \
pngcrush \
gifsicle \
bash
RUN apk add --update --no-cache graphviz font-bitstream-type1
RUN echo '* * * * * php /var/www/html/artisan schedule:run' | crontab -u www-data -
RUN rm -rf /var/spool/cron/crontabs/root
RUN docker-php-ext-install mysqli pdo pdo_mysql tokenizer xml zip exif
RUN pecl channel-update pecl.php.net \
&& pecl install redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
&& docker-php-ext-install gd \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install bcmath
# install imagick
# use github version for now until release from https://pecl.php.net/get/imagick is ready for PHP 8
RUN mkdir -p /usr/src/php/ext/imagick \
&& curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1 \
&& docker-php-ext-install imagick
RUN rm /var/cache/apk/* && \
mkdir -p /var/www && \
chown www-data:www-data /var/www -R
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
USER www-data
RUN composer global require laravel/envoy
ENV PATH "$PATH:/home/www-data/.composer/vendor/bin"
Dockerfile inside folder named 'nginx':
FROM nginx:alpine
docker-compose.yml
version: "3"
services:
php:
volumes:
- './src/:/var/www/html'
- './.docker/php/supervisor.conf:/etc/supervisord.conf'
tty: true
build:
context: .
dockerfile: .docker/php/Dockerfile
links:
- "db:database"
- "redis:redis"
networks:
internal:
traefik:
nginx:
image: nginx:alpine
volumes:
- './src:/var/www/html'
- './.docker/nginx/nginx/conf.d/:/etc/nginx/conf.d/'
- './.docker/nginx/nginx/nginx.conf:/etc/nginx/nginx.conf'
labels:
traefik.backend: domain.test
traefik.frontend.rule: "Host:library.test"
traefik.docker.network: traefik
traefik.port: 80
networks:
internal:
traefik:
depends_on:
- php
db:
image: mysql/mysql-server:latest
environment:
MYSQL_DATABASE: 'library'
MYSQL_USER: 'amin'
MYSQL_PASSWORD: 'secret'
MYSQL_ROOT_PASSWORD: 'secret'
DEFAULT_AUTHENTICATION_PLUGIN: 'mysql_native_password'
volumes:
- mysql:/var/lib/mysql:rw
- './database:/var/data'
networks:
- internal
ports:
- "3306:3306"
# Cache server
redis:
image: redis:4-alpine
volumes:
- redis:/data:rw
networks:
internal:
volumes:
mysql:
driver: "local"
redis:
driver: "local"
networks:
traefik:
external: true
internal:
external: false
That's not slow.
20MB in 1.7s is about 12MB/s, with overheads that's pretty quick.
The route you're hitting is returning heaps of data, probably more than you expect, and that's why it looks like it's running slow.
I have started to play with my first Laravel project on a MacOS. I am using Laravel Sail for running the project inside a container and everything seems to work except the debugging part.
Versions used:
Laravel 8.66,
PHP 8.0.12,
Xdebug 3.1.1
According to Laravel docs we can set SAIL_XDEBUG_MODE to enable the debug mode. However, the debugging is not working in PhpStorm even if it is set to listen for incoming connections. I have seen that running php -i in container returns different configs for Xdebug comparing to what we see in phpinfo() from browser even if the Configuration file is the same one.
Here are some screenshots from browser:
Here are screenshots from what I see in the command line:
As it can be seen in the attached screenshots, in console is used the XDEBUG_MODE env var, while in browser is used xdebug.mode. Is is possible to have the same configs in console and browser via SAIL_XDEBUG_MODE ?
This is the Dockerfile that is used:
FROM ubuntu:21.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline php8.0-pcov \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis php8.0-swoole php8.0-xdebug \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
And this is my docker-compose.yml:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
PHP_IDE_CONFIG: "serverName=my.local"
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
As it can be seen in the attached screenshots, in console is used the XDEBUG_MODE env var, while in browser is used xdebug.mode.
Xdebug uses XDEBUG_MODE if it is set, otherwise it falls back to the value of the xdebug.mode setting.
I don't know which web server Sail uses, but some will strip out the environment variables — including XDEBUG_MODE.
So you can either fix that, or update the Dockerfile to add a line below:
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
Which says:
COPY xdebug.ini /etc/php/8.0/cli/conf.d/999-xdebug.ini
And add to the contents of xdebug.ini (in the same directory as php.ini):
xdebug.mode=develop,debug
I had the same problem and I'm also on macOS.
You must use the export command, like this:
export SAIL_XDEBUG_MODE=develop,debug
I want to access vsphere config info from powercli script to laravel. But I do not know how to make them work together in docker. Whatever I do, the error is similar to this - The command "'pwsh' '-v'" failed. Exit Code: 127(Command not found) Working directory: /var/www/public Output: ================ Error Output: ================ sh: 1: exec: pwsh: not found
As a last resort, I am here.
docker-compose.yml:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: vapp
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: vapp
MYSQL_ROOT_PASSWORD: vapp
SERVICE_TAGS: dev
SERVICE_NAME: mysql
TZ: Asia/Kolkata
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
- ./mysql:/var/lib/mysql-files/
networks:
- app-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpMyAdmin
restart: always
ports:
- "8080:80"
environment:
MYSQL_ROOT_PASSWORD: vapp
PMA_HOST: db
external_links:
- mariadb:mariadb
volumes:
- "./phpmyadmin/sessions:/sessions"
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile
FROM mcr.microsoft.com/powershell:latest
WORKDIR ./
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libonig-dev \
locales \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN snap install powershell --classic
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl mysqli
RUN docker-php-ext-configure gd --enable-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-enable mysqli
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Controller:
//$process = new Process(['ls', '-lsa']); #This works but next one do not
$process = new Process(['pwsh', '-v']);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
I know how the Process() method works. Above code fails.
I need help on making powershell and laravel work together in docker.
Is there anything wrong with docker configuration or the controller code in accessing powershell.
You are using multistage build in Dockerfile. It can copy artifacts, but you don't copy anything. So pwsh app doesn't copy to PHP image (to the second stage).
You could remove first stage (FROM mcr.microsoft.com/powershell:latest) and install properly Powershell inside PHP image.
For example:
RUN apt-get update && apt-get install -y \
wget
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb
RUN apt-get update && apt-get install -y \
powershell
PHP image use Debian 10, so here is the instruction: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1#debian-10
Check pwsh inside container first:
docker exec -it app bash
pwsh
Thanks to #konstantin-bogomolov
The reason was the incorrect docker file. Powershell was not properly installed in container.
For those who stop by, Working dockerfile is below.
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libonig-dev \
locales \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
wget \
apt-utils
# Download the Microsoft repository GPG keys
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
RUN dpkg -i packages-microsoft-prod.deb
# Update the list of products
RUN apt-get update
# Install PowerShell
RUN apt-get install -y powershell
# Start PowerShell
RUN pwsh
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl mysqli
RUN docker-php-ext-configure gd --enable-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-enable mysqli
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
I'm just trying to get a simple docker dev environment setup, but docker is not installing php's mysql extension. I get a fatal error - Call to undefined function mysql_connect(). I've tried different php versions (5.4, 5.5, 5.6, 7.0) all with the same result. Any help would be appreciated.
docker-compose.yml
version: '2'
volumes:
database_data:
driver: local
services:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
volumes_from:
- php
php:
build: ./docker/php/
expose:
- 9000
volumes:
- .:/var/www/html
testing:
build: ./docker/php/
volumes_from:
- php
mysql:
image: mysql:latest
expose:
- 3306
volumes:
- database_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
Dockerfile
FROM php:7.0-fpm
# Install pdo_mysql
RUN apt-get update \
&& echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& apt-get install -y wget \
&& wget https://www.dotdeb.org/dotdeb.gpg \
&& apt-key add dotdeb.gpg \
&& apt-get update \
&& apt-get install -y php7.0-mysql \
&& docker-php-ext-install pdo_mysql mysqli mysql
If you install this php extension works (inside dockerfile)
docker-php-ext-install mysqli
inside container:
docker-php-ext-install mysqli
apache2ctl restart
I looked at the WP Docker repo and used their php Dockerfile and it worked.
# install the PHP extensions we need
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-install gd
RUN docker-php-ext-install mysqli