简体   繁体   中英

Phalcon Installation In Docker

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"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM