Waaaaat
Waaaaat

Reputation: 644

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

Upvotes: 2

Views: 5104

Answers (6)

Quentin CG
Quentin CG

Reputation: 973

Here is a working Dockerfile for PHP8.x under apache & latest phalcon:

FROM php:8-apache-bookworm
# https://docs.phalcon.io/5.8/installation/

# --- Install system dependencies ---
RUN apt-get update && \
    apt-get upgrade && \
    apt-get install -y \
        libpcre3-dev \
        re2c && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    pecl channel-update pecl.php.net && \
    a2enmod rewrite && \
    a2enmod headers

# Enable real IP if behind a proxy
RUN a2enmod remoteip ; \
    { \
    echo 'RemoteIPHeader X-Real-IP'; \
    echo 'RemoteIPInternalProxy 10.0.0.0/8'; \
    echo 'RemoteIPInternalProxy 172.16.0.0/12'; \
    echo 'RemoteIPInternalProxy 192.168.0.0/16'; \
    } > /etc/apache2/conf-available/remoteip.conf; \
    a2enconf remoteip

# --- Install PHP extensions ---

# MySQLi is a PHP extension which acts as a connector to MySQL database
# PDO is a PHP extension which provides a data-access abstraction layer
# PDO_MySQL is a PHP extension which provides a data-access abstraction layer for MySQL
RUN docker-php-ext-install mysqli && \
    docker-php-ext-install pdo && \
    docker-php-ext-install pdo_mysql

# PSR is a set of common interfaces defined by PHP Framework Interop Group
RUN CFLAGS="-w" pecl install psr && \
docker-php-ext-enable psr > /dev/null

# Build & install php phalcon (will take some time)
RUN CFLAGS="-w" pecl install phalcon && \
    docker-php-ext-enable phalcon > /dev/null
# Note: 'docker-php-ext-enable phalcon psr' is equivalent to:
# echo extension=psr.so | tee -a /usr/local/etc/php/conf.d/XXXX.ini
# echo extension=phalcon.so | tee -a /usr/local/etc/php/conf.d/XXXX.ini

# Base image will do the "CMD" part to start apache server

Built image & usage explanation: https://hub.docker.com/r/funnylabz/apache-with-phalcon

Upvotes: 0

d3javu999
d3javu999

Reputation: 323

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

Upvotes: 0

Akash Sharma
Akash Sharma

Reputation: 757

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

Upvotes: 0

zoomi
zoomi

Reputation: 602

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.....

Upvotes: 2

pgeimer
pgeimer

Reputation: 103

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}

Upvotes: 4

Mahmoud Gabr
Mahmoud Gabr

Reputation: 21

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

Upvotes: 0

Related Questions