1
votes

I am trying continuous deployment of codeigniter 4 application from github repo using cloud build in GCP, but it shows failed to listen port but I used port environment variable, Help me with this error

My Docker File

FROM php:fpm

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "libzip-dev"]
RUN ["apt-get", "install", "-y", "zip"]
RUN ["apt-get", "install", "-y", "unzip"]
RUN ["apt-get", "install", "-y", "libxml2-dev"]
RUN ["docker-php-ext-install", "soap"]
RUN ["docker-php-ext-configure", "zip"]
RUN ["docker-php-ext-install", "mysqli", "pdo", "pdo_mysql", "zip"]

RUN touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize=64M;\r\n post_max_size=128M;\r\nmemory_limit = 512M" >> /usr/local/etc/php/conf.d/uploads.ini

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./writable /var/www/html/writable

## Install codeIgniter Dependecies
COPY ./composer.json /var/www/html/composer.json
RUN cd /var/www/html/ && composer update /var/www/html/ --no-dev --ignore-platform-reqs "vendor/*"

RUN cd /var/www/html/
#RUN ["chmod", "-R", "777", "writable/"]
RUN ["chown", "-R", "www-data:www-data", "/var/www/html/"]
########################################

EXPOSE ${PORT}

My composer.json file

{
  "name": "codeigniter4/appstarter",
  "type": "project",
  "description": "CodeIgniter4 starter app",
  "homepage": "https://codeigniter.com",
  "license": "MIT",
  "require": {
    "php": ">=7.2",
    "codeigniter4/framework": "^4"
  },
  "require-dev": {
    "mikey179/vfsstream": "1.6.*",
    "phpunit/phpunit": "8.5.*"
  },
  "autoload-dev": {
    "psr-4": {
      "Tests\\Support\\": "tests/_support"
    }
  },
  "scripts": {
    "test": "phpunit",
    "post-update-cmd": [
      "@composer dump-autoload"
    ]
  },
  "support": {
    "forum": "http://forum.codeigniter.com/",
    "source": "https://github.com/codeigniter4/CodeIgniter4",
    "slack": "https://codeigniterchat.slack.com"
  }
}
1
Go to the logs, you have, most of time, far more detail on the error. Check it out and share the logs if you aren't able to fix the issueguillaume blaquiere
Hmm, with a closer look to your dockerfile, you don't have a CMD line that execute the webserver at the end. Nothing is running, nothing is started on the $PORT, so, there is an error. Do you serve only static content?guillaume blaquiere
Thanks for the reply man I used apache in dockerfile instead of fpm and edited my dockerfile,now it works great, should have used it beforeNaveen Raj
@guillaumeblaquiere you should post it as a formal answerLouis C

1 Answers

0
votes
FROM php:7.3-apache

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install --fix-missing -y libpq-dev
RUN apt-get install --no-install-recommends -y libpq-dev
RUN apt-get install -y libxml2-dev libbz2-dev zlib1g-dev
RUN apt-get -y install libsqlite3-dev libsqlite3-0 mariadb-client curl exif ftp
RUN docker-php-ext-install intl
RUN apt-get -y install --fix-missing zip unzip

RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer self-update

RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

ADD conf/apache.conf /etc/apache2/sites-available/000-default.conf

RUN a2enmod rewrite

RUN printf "#!/bin/bash\n/usr/sbin/apache2ctl -D FOREGROUND" > /startScript.sh
RUN chmod +x /startScript.sh

RUN cd /var/www/html
COPY . /var/www/html/
COPY ./.env.example /var/www/html/.env
COPY ./composer.json /var/www/html/composer.json

RUN composer update /var/www/html/ --no-dev --ignore-platform-reqs "vendor/*"
RUN chmod -R 0777 /var/www/html/writable

RUN apt-get clean \
    && rm -r /var/lib/apt/lists/*

EXPOSE ${PORT}
VOLUME ["/var/www/html", "/var/log/apache2", "/etc/apache2"]

CMD ["bash", "/startScript.sh"]

I used apache instead of fpm and it works but I still don't know why fpm is not working