如何在Docker中创建PHP环境?
我正在尝试将phpweb应用程序与apache2服务器对接。为php和apache2创建环境的任何更好的方法。我在互联网云上搜索,无法找到任何解决方案 我使用了ubuntu:latest作为基本图像,我试着在第一步中创建图像,如果第一步成功的话。我已经尝试过在没有php的情况下创建图像,并且我成功地运行了docker容器,但是没有php,运行没有任何意义,因为我已经采取了下一步将php添加到图像中,现在我被卡住了 下面是错误的图像 这是我的文件如何在Docker中创建PHP环境?,php,linux,docker,Php,Linux,Docker,我正在尝试将phpweb应用程序与apache2服务器对接。为php和apache2创建环境的任何更好的方法。我在互联网云上搜索,无法找到任何解决方案 我使用了ubuntu:latest作为基本图像,我试着在第一步中创建图像,如果第一步成功的话。我已经尝试过在没有php的情况下创建图像,并且我成功地运行了docker容器,但是没有php,运行没有任何意义,因为我已经采取了下一步将php添加到图像中,现在我被卡住了 下面是错误的图像 这是我的文件 #Download base image FRO
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
RUN ln -f -s /usr/bin/g++ /usr/bin/g++
RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
谢谢 g++&gcc的符号链接不好 以下几点对我很有用:
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y && apt-get install -y gcc g++
#RUN apt-get install -y gcc
#RUN apt-get install -y g++
#RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
#RUN ln -f -s /usr/bin/g++ /usr/bin/g++
#RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
谢谢这很有帮助。你怎么想到的?我觉得这不符合逻辑。我假设它对流量有一些影响。