Heroku上的Docker PHP + Apache部署崩溃

时间:2018-12-21 12:14:30

标签: php apache docker heroku deployment

我是Heroku的新手。我正在尝试部署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日志--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.

3 个答案:

答案 0 :(得分:3)

@ caleb-gray接受的答案已于2019年9月停止为我工作,但我想出了另一种解决方案:

不是代替Dockerfile中的端口值,而是使用env变量将它们替换为原始apache2 .conf文件中的端口值,然后将其复制到Docker映像中。这也意味着.conf文件现在已成为我的存储库的一部分(我从正在运行的Docker容器中复制了它们)。

我的文件夹层次结构:

Dockerfile
apache-config/
  ports.conf
  000-default.conf

例如,在我的ports.conf行中

Listen 80

已更改为

Listen ${PORT}

在我的Dockerfile中:

COPY ./apache-config/ports.conf /etc/apache2/ports.conf                                
COPY ./apache-config/000-default.conf /etc/apache2/sites-available/000-default.conf    
CMD docker-php-entrypoint apache2-foreground

到目前为止效果很好

答案 1 :(得分:2)

我最近here亲自解决了这个问题,以防您想再次尝试使用Heroku:)

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

答案 2 :(得分:0)

答案很简单,您不能绑定到应该使用$ PORT env变量的特定端口。有关此线程here的更多信息。