Phalcon Installation In Docker - windows

I am trying to install phalcon in docker and I cannot figure out how to do it.
I am searching through the web for solutions and couldn't manage to make it work.
I successfully installed docker for windows and it seems to work fine but i cannot find a way to install docker.
Can anyone help me to install phalcon in docker ?
Thanks in advance

You can create a Dockerfile which is compiling Phalcon for you:
FROM php:7.2-fpm
ENV PHALCON_VERSION=3.4.2
RUN curl -sSL "https://codeload.github.com/phalcon/cphalcon/tar.gz/v${PHALCON_VERSION}" | tar -xz \
&& cd cphalcon-${PHALCON_VERSION}/build \
&& ./install \
&& cp ../tests/_ci/phalcon.ini $(php-config --configure-options | grep -o "with-config-file-scan-dir=\([^ ]*\)" | awk -F'=' '{print $2}') \
&& cd ../../ \
&& rm -r cphalcon-${PHALCON_VERSION}

if you are looking for php7+apache+mysql with phalcon 3.4.2 then here is my solution. for phalcon 4 there needs to be done addition steps like installing psr otherwise it will give error for required dependencies.
CONSIDER FOLLOWING STUCTURE AND PUT FILES ACCORDINGLY
docker-compose.yml
www(directory where you will put your code)
index.php
.docker(directory)
Dockerfile
dump(directory just to persist your mysql data)
here is Dockerfile which you will put in .docker directory
FROM php:7.1.2-apache
RUN docker-php-ext-install pdo_mysql
RUN sed -i '/jessie-updates/d' /etc/apt/sources.list # Now archived
RUN apt update
RUN apt install -y \
apt-transport-https \
lsb-release \
ca-certificates \
wget \
curl \
nano \
dialog \
net-tools \
git \
sudo \
openssl \
libpcre3-dev
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
RUN apt update && apt install -y \
php7.1-curl \
php7.1-mbstring \
php7.1-gettext \
php7.1-gd \
php7.1-fileinfo \
php7.1-json \
php7.1-mcrypt \
php7.1-redis \
php7.1-intl \
php7.1-xml \
php7.1-zip
ARG PHALCON_VERSION=3.4.2
ARG PHALCON_EXT_PATH=php7/64bits
RUN set -xe && \
# Compile Phalcon
curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz && \
tar xzf ${PWD}/v${PHALCON_VERSION}.tar.gz && \
docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) ${PWD}/cphalcon-${PHALCON_VERSION}/build/${PHALCON_EXT_PATH} && \
# Remove all temp files
rm -r \
${PWD}/v${PHALCON_VERSION}.tar.gz \
${PWD}/cphalcon-${PHALCON_VERSION}
RUN a2enmod rewrite
this will be for you php and phalcon settings along with apache
and you can use docker compose to run all your required container to make up your application
here is your docker-compose file
version: "2"
services:
www:
build: ./.docker
ports:
- "8001:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
db:
image: mysql:5.7.13
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
after this just add index.php in www
<?php echo phpinfo();?>
after this localhost:8001 should b accessible.. happy coding. and if there is any improvements need to be done in this. please let me know. as of now this one is working super cool for me and my first phalcon configuration. wasted lot of time on it.....

You can install it through Dockerfile
Kindly, fetch this link according to your operating system
https://github.com/phalcon/dockerfiles
Plus you can make it through repo
https://hub.docker.com/u/phalconphp

For phalcon its important to compile on same hardware/cpu. Or you pass the flags to
phpize \
&& ./configure CFLAGS="-O2 -g" \
&& make -B \
&& make install

not sure if still relevant but here
https://keepforyourself.com/coding/php/how-to-setup-phalcon-framework-in-a-docker-container-v2/
there is this solution
FROM alpine:latest
RUN apk add --no-cache \
apache2-proxy \
apache2-ssl \
apache2-utils \
curl \
git \
logrotate \
openssl \
git bash php php7-dev apache2 gcc \
libc-dev make php7-pdo php7-json \
php7-session php7-pecl-psr \
php7-apache2
WORKDIR /
RUN git clone --depth=1 "git://github.com/phalcon/cphalcon.git"
WORKDIR /cphalcon/build
RUN ./install
RUN echo "extension=phalcon.so" > /etc/php7/conf.d/phalcon.ini
RUN apk del libc-dev zlib-dev php7-dev libedit-dev musl-dev pcre2-dev ncurses-dev \
expat xz-libs curl musl-utils make libedit zlib ncurses-libs libstdc++ pcre git bash musl argon2-libs
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
RUN rm -rf /cphalcon
WORKDIR /var/www/localhost/htdocs
RUN echo "<?php phpinfo(); ?>" > /var/www/localhost/htdocs/index.php
EXPOSE 80
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

Related

Laradock - Service 'php-fpm' failed to build

Info:
OS: Ubuntu 16.04
Docker version: 20.10.6
Commit: 63fc1fd
Project versions:
Laravel 5.8.33
Vue 2.6.10
My Laravel docker environment stopped working today.
After several tries I finally deleted all images and tried to rebuild environemt.
I get the same error:
+ apt-get install -yqq apt-utils libzip-dev zip unzip
E: Unable to correct problems, you have held broken packages.
ERROR: Service 'php-fpm' failed to build: The command '/bin/sh -c set -xe; apt-get update -yqq && pecl channel-update pecl.php.net && apt-get install -yqq apt-utils libzip-dev zip unzip && docker-php-ext-configure zip --with-libzip && docker-php-ext-install zip && php -m | grep -q 'zip'' returned a non-zero code: 100
Here is the code of my php-fpm Docker file.
Any idea what is wrong?
in Dockerfile
you can add:
FROM composer AS composer
COPY . /app
RUN rm composer.lock && composer install
--optimize-autoloader
--no-interaction
--no-progress
--ignore-platform-reqs
RUN apk add --no-cache php
php7-common
php7-fpm
php7-pdo
php7-opcache
php7-zip \
did you add
RUN apk add --no-cache php
php7-common
php7-fpm \
try this
FROM composer AS composer
COPY . /app
RUN rm composer.lock && composer install \
--optimize-autoloader \
--no-interaction \
--no-progress \
--ignore-platform-reqs
RUN chmod 777 -R storage
FROM alpine:3.13
LABEL Maintainer="Diki Rahman <diki#sawala.tech>"
RUN apk add --no-cache php \
php7-common \
php7-fpm \
php7-pdo \
php7-opcache \
php7-zip \
php7-phar \
php7-iconv \
php7-cli \
php7-curl \
php7-openssl \
php7-mbstring \
php7-tokenizer \
php7-fileinfo \
php7-json \
php7-xml \
php7-xmlwriter \
php7-simplexml \
php7-dom \
php7-pdo_mysql \
php7-pdo_pgsql \
php7-pdo_sqlite \
php7-tokenizer \
php7-pecl-redis \
nginx supervisor curl
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY docker/php-fpm/fpm-pool.conf /etc/php7/php-fpm.d/www.conf
COPY docker/php/php.ini /etc/php7/conf.d/timezone.ini
COPY docker/supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x docker-entrypoint.sh
RUN mkdir -p /var/www/html
RUN mkdir -p /var/www/backend
RUN chown -R nginx.nginx /var/www/html && \
chown -R nginx.nginx /run && \
chown -R nginx.nginx /var/lib/nginx && \
chown -R nginx.nginx /var/log/nginx
WORKDIR /var/www/html
COPY --chown=nginx --from=composer /app /var/www/html
COPY --chown=nginx --from=composer /app /var/www/backend
EXPOSE 8080
ENTRYPOINT ["/docker-entrypoint.sh"]
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping

Trigger executing a custom shell script inside a container to run migrations and db:seed after docker build is complete from docker-compose.yml

I have created my docker-compose.yml file to make containers for a Laravel project and I created a separate project_setup.sh script to do composer install,npm install and DB migration. is there a way to automate this like once both containers up run the sh script from inside apache server container where files are located without manually log in to the container and run the file.
my current docker-compose.yml
version: '3.5'
services:
laravel-app:
build:
context: '.'
container_name: my-app
volumes:
- ./:/var/www/html
- ./docker_configs/custom.ini:/usr/local/etc/php/conf.d/custom.ini
- ./docker_configs/laravel-worker.conf:/etc/supervisor/conf.d/laravel-worker.conf
- ./docker_configs/docker_cron:/etc/cron.d/docker_cron
working_dir: /var/www/html
ports:
- 8080:80
networks:
backend:
aliases:
- app
mariadb:
image: mariadb:10.2
container_name: my-db
volumes:
- ./run/var:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_USER=${DB_USERNAME}
- MYSQL_PASSWORD=${DB_PASSWORD}
ports:
- 3309:3306
networks:
backend:
aliases:
- db
networks:
backend:
name: backend-network
I'm just using latest MariaDB image with database settings my docker file in case
FROM php:7.3.12-apache-stretch
RUN apt-get autoclean
RUN apt-get update
# 1. development packages
RUN apt-get install -y \
apt-utils \
build-essential \
debconf-utils \
debconf \
default-mysql-client \
locales \
git \
memcached \
zip \
sudo \
wget \
gnupg \
unzip \
nano \
libxml2-dev \
libldb-dev \
libldap2-dev \
libpq-dev \
libzip-dev \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
openssh-client \
libmcrypt-dev \
libreadline-dev \
libmagickwand-dev \
libmemcached-dev \
libmagickcore-dev \
zlib1g-dev \
libfreetype6-dev \
cron \
supervisor
RUN \
echo "deb http://ftp.au.debian.org/debian/ stretch main non-free contrib" > /etc/apt/sources.list && \
echo "deb-src http://ftp.au.debian.org/debian/ stretch main non-free contrib" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ stretch/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ stretch/updates main contrib non-free" >> /etc/apt/sources.list && \
apt-get -qq update && apt-get -qqy upgrade && apt-get -q autoclean && rm -rf /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get upgrade
RUN apt-get update && apt-get install -y libc-client-dev libkrb5-dev && rm -r /var/lib/apt/lists/*
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bcmath \
bz2 \
dom \
gd \
json \
ldap \
mbstring \
pgsql \
mysqli \
intl \
iconv \
opcache \
calendar \
pdo_mysql \
pdo_pgsql \
xml
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-install imap
RUN docker-php-ext-configure zip --with-libzip && \
docker-php-ext-install zip
#add unsupported php files via pecl
RUN pecl install xdebug && docker-php-ext-enable xdebug && \
pecl install mcrypt && docker-php-ext-enable mcrypt && \
pecl config-set php_ini /etc/php/7.3/apache2/php.ini && \
pecl install imagick && docker-php-ext-enable imagick
RUN mkdir -p /usr/src/php/ext/memcached
WORKDIR /usr/src/php/ext/memcached
RUN wget https://github.com/php-memcached-dev/php-memcached/archive/v3.1.3.zip; unzip /usr/src/php/ext/memcached/v3.1.3.zip
RUN mv /usr/src/php/ext/memcached/php-memcached-3.1.3/* /usr/src/php/ext/memcached/
RUN docker-php-ext-configure memcached && docker-php-ext-install memcached
RUN mkdir -p /usr/src/php/ext/memcache
WORKDIR /usr/src/php/ext/memcache
RUN wget https://github.com/websupport-sk/pecl-memcache/archive/4.0.4.zip; unzip /usr/src/php/ext/memcache/4.0.4.zip
RUN mv /usr/src/php/ext/memcache/pecl-memcache-4.0.4/* /usr/src/php/ext/memcache/
RUN docker-php-ext-install memcache && docker-php-ext-configure memcache
# 6. Configure needed apache modules and disable default site
RUN a2dismod mpm_event cgi # mpm_worker enabled.
RUN a2enmod \
access_compat \
actions \
alias \
auth_basic \
authn_core \
authn_file \
authz_core \
authz_groupfile \
authz_host \
authz_user \
autoindex \
dir \
env \
expires \
filter \
headers \
mime \
negotiation \
mpm_prefork \
reqtimeout \
rewrite \
setenvif \
status \
ssl
# 7. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
maybe my approach wrong.. I appreciate any support.
Update
i created the files required for building the docker container.Hope it'll be usefull to anyone else.
https://github.com/Madu-rosh/laravel-docker-setup

Logs directory permission denied error when running Artisan commands

I have a setup of docker with laravel and apache alongside mysql, when trying to run artisan command in the terminal of vscode i get :
There is no existing directory at "/var/www/html/storage/logs" and its not buildable: Permission denied
Apache setup in docker compose:
laravel-app:
build:
context: ./docker/app
args:
uid: ${UID}
container_name: laravel-app
environment:
- APACHE_RUN_USER=#${UID}
- APACHE_RUN_GROUP=#${UID}
volumes:
- .:/var/www/html
ports:
- ${HOST_PORT}:80
networks:
backend:
aliases:
- laravel-app
Dockerfile of apache
FROM php:7.2-apache
RUN apt-get update
# 1. development packages
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
mbstring \
pdo_mysql \
zip
# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 6. we need a user with the same UID/GID with host user
# so when we execute CLI commands, all the host file's ownership remains intact
# otherwise command from inside container will create root-owned files and directories
ARG uid
RUN useradd -G www-data,root -u $uid -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
even though the directory exists, also the commands run successfully from within the container. Should i always run the commands related to laravel artisan from the container, or there is something wrong?
Go to your project folder and open terminal
then,
run this command
sudo chmod -R 775 storage

Init Laravel passport from within docker

I'm in the process of dockerizing our dev environement. The application consists among other things of a laravel app exposing a REST API. Authentication is done through laravel passport.
As this is intented for dev only, I'm installing composer dependencies, setting application encryption key, migrating datatabases and setting passport keys at run time. Everything is initialised correctly except for the passport keys. No matter how I tried to approach the problem I end up with the following error:
fpm_1 | In CryptKey.php line 45:
fpm_1 |
fpm_1 | Key path "file:///var/www/html/storage/oauth-public.key" does not exist or
fpm_1 | is not readable
This is the relevant part of my docker-compose file.
version: '3'
services:
fpm:
build: ./api/docker/fpm
restart: unless-stopped
volumes:
- ./api:/var/www/html
- /etc/passwd:/etc/passwd
user: "${UID}:${GID}"
My fpm dockerfile (./api/docker/fpm/Dockerfile)
FROM php:7.2.6-fpm
COPY ./init-app.sh /usr/local/bin/
COPY ./install-composer.sh /usr/local/bin/
RUN apt-get update && apt-get install -y --no-install-recommends libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev libpng-dev \
libzip-dev \
libzip4 \
git \
zip \
wget \
&& apt-get autoremove \
&& apt-get clean \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure zip --with-libzip=/usr/include/ \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_mysql \
&& chmod +x /usr/local/bin/init-app.sh \
&& chmod +x /usr/local/bin/install-composer.sh \
&& /usr/local/bin/install-composer.sh \
&& rm /usr/local/bin/install-composer.sh \
&& wget https://raw.githubusercontent.com/vishnubob/wait-for-it/8ed92e8cab83cfed76ff012ed4a36cef74b28096/wait-for-it.sh \
&& chmod +x wait-for-it.sh \
&& mv wait-for-it.sh /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/init-app.sh" ]
CMD ["php-fpm"]
install-composer.sh installs composer into the container at build time.
init-app.sh:
#!/bin/sh
set -e
# Install composer dependencies
composer install
# Copy env file
cp .env.example .env
# Wait for DB to be up
/usr/local/bin/wait-for-it.sh db:3306 -t 0 --strict -- php artisan key:generate && php artisan migrate:refresh --seed
php artisan passport:install
# Run upstream entrypoint
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$#"
fi
exec "$#"
My user is correctly mapped inside the fpm container as I export $UID and $GID in .zshrc. Commenting out the passport:install line in my init-app.sh in order to let container boot correctly, I'm able to generate the keys by running docker exec -it php artisan passport:install just fine. But letting the container handle it fails.
Turns out, one of my database seeder, somehow required the key to be present. while I investigate, I fixed the problem by swapping instructions (the seeding and passport keys installation)

Wrong permissions in volume in Docker container

I run Docker 1.8.1 in OSX 10.11 via an local docker-machine VM.
I have the following docker-compose.yml:
web:
build: docker/web
ports:
- 80:80
- 8080:8080
volumes:
- $PWD/cms:/srv/cms
My Dockerfile looks like this:
FROM alpine
# install nginx and php
RUN apk add --update \
nginx \
php \
php-fpm \
php-pdo \
php-json \
php-openssl \
php-mysql \
php-pdo_mysql \
php-mcrypt \
php-ctype \
php-zlib \
supervisor \
wget \
curl \
&& rm -rf /var/cache/apk/*
RUN mkdir -p /etc/nginx && \
mkdir -p /etc/nginx/sites-enabled && \
mkdir -p /var/run/php-fpm && \
mkdir -p /var/log/supervisor && \
mkdir -p /srv/cms
RUN rm /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/nginx.conf
ADD thunder.conf /etc/nginx/sites-enabled/thunder.conf
ADD nginx-supervisor.ini /etc/supervisor.d/nginx-supervisor.ini
WORKDIR "/srv/cms"
VOLUME "/srv/cms"
EXPOSE 80
EXPOSE 8080
EXPOSE 22
CMD ["/usr/bin/supervisord"]
When I run everything with docker-compose up everything works fine, my volumes are mounted at the correct place.
But the permissions in the mounted folder /srv/cms look wrong. The user is "1000" and the group is "50" in the container. The webserver could not create any files in this folder, because it runs with the user "root".
1) General idea: Docker it is not Vagrant. It is wrong to put two different services into one container! Split it into two different images and link them together. Don't do this shitty image.
Check and follow https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
Avoid installing unnecessary packages
Run only one process per container
Minimize the number of layers
If you do it:
you will remove your supervisor
your can decrease numbers of layers
It should be something like (example):
FROM alpine
RUN apk add --update \
wget \
curl
RUN apk add --update \
php \
php-fpm \
php-pdo \
php-json \
php-openssl \
php-mysql \
php-pdo_mysql \
php-mcrypt \
php-ctype \
php-zlib
RUN usermod -u 1000 www-data
RUN rm -rf /var/cache/apk/*
EXPOSE 9000
For nginx it is enough to use default image and mount configs.
docker-compose file like:
nginx:
image: nginx
container_name: site.dev
volumes:
- ./myconf1.conf:/etc/nginx/conf.d/myconf1.conf
- ./myconf2.conf:/etc/nginx/conf.d/myconf2.conf
- $PWD/cms:/srv/cms
ports:
- "80:80"
links:
- phpfpm
phpfpm:
build: ./phpfpm/
container_name: phpfpm.dev
command: php5-fpm -F --allow-to-run-as-root
volumes:
- $PWD/cms:/srv/cms
2)
Add RUN usermod -u 1000 www-data into Dockerfile for php container, it will fix problem with permission.
For alpine version you need to use:
RUN apk add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data

Resources