diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..c86ae59 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,18 @@ +FROM php:7.3-fpm +#设置时区 +ENV TZ=Asia/Shanghai +#工作目录 +WORKDIR /root +#复制安装脚本 +COPY ./install.sh /root +#复制启动脚本 +COPY ./run.sh /usr/sbin +#执行安装脚本 +RUN bash install.sh +#暴露配置文件 +VOLUME /usr/local/nginx/conf/vhost +VOLUME /var/www/html +EXPOSE 80 +EXPOSE 443 +#运行crontab和nginx +CMD ["/usr/sbin/run.sh"] \ No newline at end of file diff --git a/php/install.sh b/php/install.sh new file mode 100644 index 0000000..3899ff5 --- /dev/null +++ b/php/install.sh @@ -0,0 +1,44 @@ +#!/bin/bash +#update system +apt-get update +#install nginx +function install_nginx() { + cd /usr/local + #add user and group + groupadd www + useradd -M -g www www -s /sbin/nologin + #download nginx + wget http://soft.xiaoz.org/nginx/xcdn-binary-1.18-debian.tar.gz + tar -zxvf xcdn-binary-1.18-debian.tar.gz + rm -rf xcdn-binary-1.18-debian.tar.gz + #add env + echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile + export PATH=$PATH:'/usr/local/nginx/sbin' + #备份配置文件 + cd /usr/local/nginx/conf + cp nginx.conf nginx.conf.bak + apt-get install -y wget + wget -P /usr/local/nginx/conf https://github.com/helloxz/dnmp/raw/main/php/nginx.conf +} + +#setting php +function set_php() { + cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini + #install gd ext + apt-get update && apt-get install -y \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libpng-dev \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd + #install xdebug and redis + pecl install redis-5.1.1 \ + && pecl install xdebug-2.8.1 \ + && docker-php-ext-enable redis xdebug +} + +install_nginx && setting + +echo '-----------------------------' +echo 'nginx + php install success.' +echo '-----------------------------' \ No newline at end of file diff --git a/php/run.sh b/php/run.sh new file mode 100644 index 0000000..57073c4 --- /dev/null +++ b/php/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash +#start nginx +/usr/local/nginx/sbin/nginx +echo 'start nginx success.' +#start php-fpm +/usr/local/sbin/php-fpm \ No newline at end of file