php - Heroku 上的 Docker PHP + Apache 部署崩溃

标签 php apache docker heroku deployment

我正在尝试部署一个 docker 容器,尽管我尝试了多种选择,但它总是崩溃。在本地运行正常,在端口 8080 上。

现在,我正在使用 PHP + Apache。

我的文件夹层次结构如下所示:

docker-compose.yml
Dockerfile 
www
   .htaccess
   index.php

我的 Dockerfile 是这个:

FROM php:7.1-apache
COPY www /var/www/html
RUN a2enmod rewrite
RUN a2enmod lbmethod_byrequests
RUN service apache2 restart
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

我的 docker-composer.yml:

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: ./Dockerfile
    image: myproject
    ports:
      - 8080:80

还有 .htaccess:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

当我检查 Heroku 日志 (heroku logs --tail) 时,这是我看到的:

Starting process with command `/usr/sbin/apache2ctl -D FOREGROUND`
State changed from starting to crashed
Process exited with status 1
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action '-D FOREGROUND' failed.

最佳答案

我最近自己解决了这个问题here如果你想再次尝试 Heroku :)

基本上,我使用 Docker CMD 语句在运行时更改 apache 端口配置。

CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground

关于php - Heroku 上的 Docker PHP + Apache 部署崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884647/

相关文章:

apache 无缓存,过期

amazon-web-services - 禁止从私有(private)注册表访问的 AWS EB docker-compose 部署

Docker-Compose v3-静态IP

linux - 首次启动时的 Docker 卷

php - jQuery 到 PHP : Add a selector class to children elements if more than one

php - foreach $_POST 更新取决于 $key

java - 使用 POI 创建 Word 文件

regex - htaccess重写规则3变量

php - laravel 编辑 phpunit.xml 以在测试时更改环境

php - 在 php 中维护页面之间的 session ?