更新时间:2023-10-16 23:42:58
经过两天的尝试,我终于到达了可以在支持php的apache容器上部署Laravel应用程序的地步.由于发现的问题数不胜数,因此以下是最后的Dockerfile
以及各节的说明:
After two days of attempts, I finally arrived to a point in which I am able to deploy my Laravel Application on a php-enabled apache container. Since the number of issues found was countless, here is the final Dockerfile
, and an explanation of the sections:
# PHP Images can be found at https://hub.docker.com/_/php/
FROM php:7.3-alpine3.9
# The application will be copied in /home/application and the original document root will be replaced in the apache configuration
COPY . /home/application/
# Custom Document Root
ENV APACHE_DOCUMENT_ROOT /home/application/public
# Concatenated RUN commands
RUN apk add --update apache2 php7-apache2 php7-mbstring php7-session php7-json php7-pdo php7-openssl php7-tokenizer php7-pdo php7-pdo_mysql php7-xml php7-simplexml\
&& chmod -R 777 /home/application/storage \
&& chown -R www-data:www-data /home/application \
&& mkdir -p /run/apache2 \
&& sed -i '/LoadModule rewrite_module/s/^#//g' /etc/apache2/httpd.conf \
&& sed -i '/LoadModule session_module/s/^#//g' /etc/apache2/httpd.conf \
&& sed -ri -e 's!/var/www/localhost/htdocs!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/httpd.conf \
&& sed -i 's/AllowOverride\ None/AllowOverride\ All/g' /etc/apache2/httpd.conf \
&& docker-php-ext-install pdo_mysql \
&& rm -rf /tmp/* /var/cache/apk/*
# Launch the httpd in foreground
CMD rm -rf /run/apache2/* || true && /usr/sbin/httpd -DFOREGROUND
这是我在Dockerfile
/home/application
public
Laravel文件夹apk
请求安装操作系统软件包(所有这些都是我的Laravel应用程序所必需的).可用软件包的完整列表可在 http://dl- cdn.alpinelinux.org/alpine/edge/community/x86_64/ storage
文件夹上的权限/home/application/
文件夹的所有者httpd.conf
文件中的文档根目录AllowOverride All
指令pdo_mysql
扩展名(否则命令将无法访问mysql)httpd
/home/application
public
Laravel folderapk
(all of them were required for my Laravel application). A full list of the available packages can be found on http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/storage
folder/home/application/
folder httpd.conf
fileAllowOverride All
instruction pdo_mysql
extension (otherwise commands will not be able to access mysql)httpd
使用此Dockerfile
,现在可以运行所有Laravel Web应用程序,只需在/home/application/
Using this Dockerfile
, it's now possible to run all of the Laravel Web Applications, it will just be a matter of copying the application source code in /home/application/